How to map the host OS file to the container at the time of container build process

给你一囗甜甜゛ 提交于 2019-12-14 04:05:00

问题


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.



来源:https://stackoverflow.com/questions/47030342/how-to-map-the-host-os-file-to-the-container-at-the-time-of-container-build-proc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!