在容器构建过程中如何将主机OS文件映射到容器 [英] How to map the host OS file to the container at the time of container build process
问题描述
docker-compose.yml:
docker-compose.yml:
version: '3'
services:
ezmove:
volumes:
- /host-dir:/home/container-dir
build:
context: .
args:
BRANCH: develop
Dockerfile:
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"
在构建时间,docker容器如何将本地目录映射到容器
At the time of build the docker container How to map local directory to container
当$ docker-compose up时,它将开始构建容器,但是在安装packag依赖项后,它将尝试执行script.sh文件,但出现错误文件未找到!
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! "
尝试过:
- 不想要待办事项docker clone内的git clone
- 不想将源代码存储在Continer内
因此,如何在构建时将主机OS文件映射到容器
推荐答案
您缺少一些 COPY
或 ADD
在Dockerfile中,以便在图像中复制script.sh。
you lack some COPY
or ADD
in your Dockerfile in order to copy your script.sh in your image.
检查文档
https://docs.docker.com/engine/reference/builder/#add
https://docs.docker.com/engine/reference/builder/#copy
顺便说一句,Docker是关于隔离的,因此应该将运行中的容器与主机隔离,并且一定不能访问主机操作系统。
By the way, Docker is about isolation, so a running container should be isolated from the host, and certainly not access the host OS.
这篇关于在容器构建过程中如何将主机OS文件映射到容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!