How to map the host OS file to the container at th

2019-08-16 02:06发布

问题:

docker-compose.yml:

    version: '3'
    services:
      ezmove:
        volumes:
          - /host-dir:/home/container-dir    
        build:
          context: .
          args:
            BRANCH: develop

Dockerfile:

FROM appcontainers/ubuntu:xenial

MAINTAINER user <user>

RUN apt-get update -y --no-install-recommends \
    && apt-get install -y --no-install-recommends python3.5-minimal python3.5-venv \    
    && apt-get install -y --no-install-recommends git \
    && apt-get install -y --no-install-recommends python-pip \
    && pip install --upgrade pip \  
    && rm -rf /var/lib/apt/lists/* \
    && mkdir -p /home/container-dir 

WORKDIR /home/container-dir 

RUN /bin/bash - c "sh ./script.sh"

At the time of build the docker container How to map local directory to container

When $ docker-compose up, it will starts to build container but after installation of the packag dependancies it will try to execute the script.sh file but got error "FILE NOT FOUND! "

Tried:

  1. Not want todo git clone inside docker continer
  2. Not want to store source code inside the continer

So, how to map the host OS file to the container at build time

回答1:

you lack some COPY or ADD in your Dockerfile in order to copy your script.sh in your image.

Check the docs

https://docs.docker.com/engine/reference/builder/#add

https://docs.docker.com/engine/reference/builder/#copy

By the way, Docker is about isolation, so a running container should be isolated from the host, and certainly not access the host OS.