使用docker-machine进行部署时,docker COPY不工作

我使用docker-compose,用dockerfile构build一个图像,其他图像是标准图像。 由dockerfile('网站')控制的图像具有COPY。 / gp_flask(该目录是较早创build的)。 它工作正常时

docker-compose up --build 

发生在我的Ubuntu机器上。 它复制一个目录结构。

但是,当我使用EC2泊坞窗机器时,我添加的目录(在泊坞窗)中没有内容

 RUN ls -la /gp_flask 

COPY后立即显示所有内容。 EXPOSE的唯一命令是EXPOSE端口和CMD ["/usr/bin/supervisord"]

COPY命令复制supervisord和nginxconfiguration文件确实工作正常。

但在构build过程完成后,其他容器之一失败,因为它无法find/ gp_flask中的东西,果然,如果我docker-compose exec website / bin / bash目录/ gp_flask现在是空的。

这只发生在我在docker-machine环境中运行时。 docker,撰写我的本地机器工作正常。

另外,如果我使用docker-machine并用eval "$(docker-machine env gpflask)"启动两个shell,然后在其中一个:

  docker build -t gp_flask . 

另一个是:

 docker exec -it mad_fermat /bin/bash 

那么我可以看到COPY的工作(在EC2docker引擎实例上)。

所以这意味着docker-compose在远程docker引擎上有所不同。 RUN ls之后的RUN ls的成功似乎表明复制正在工作,但是在构build过程中稍后的映像将其删除,但基本上没有以下命令。

 FROM python:3.5 MAINTAINER Tim Richardson <tim@growthpath.com.au> RUN apt-get update && apt-get install -qq -y \ build-essential libpq-dev --no-install-recommends RUN apt-get install -qq -y vim --no-install-recommends RUN apt-get install -qq -y nginx --no-install-recommends RUN apt-get install -qq -y supervisor --no-install-recommends RUN apt-get install -qq -y python3-dev python3-pip python3-setuptools --no-insta ll-recommends # RUN apt-get install -qq -y openssh-server --no-install-recommends #RUN mkdir -p /var/run/sshd COPY requirements.txt requirements.txt COPY requirements requirements RUN pip3 install -r requirements.txt COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf ENV INSTALL_PATH /gp_flask RUN mkdir -p $INSTALL_PATH COPY nginx.conf /etc/nginx/nginx.conf RUN rm /etc/nginx/sites-enabled/default WORKDIR $INSTALL_PATH COPY . /gp_flask RUN ls -la /gp_flask EXPOSE 8000 EXPOSE 5000 EXPOSE 5001 #note that if you change the name of the app, you have to change the command lin e to gunicorn #gunicorn is started in supervisord setup #CMD gunicorn -b 0.0.0.0:8001 --access-logfile - "dear_flask.app:create_app()" CMD ["/usr/bin/supervisord"] 

这里是docker-compose.yml

 version: '2' services: postgres: image: 'postgres:9.5' env_file: - '.env' volumes: - 'postgres:/var/lib/postgresql/data' ports: - '5432:5432' redis: image: 'redis:3.0-alpine' command: redis-server --requirepass devpassword volumes: - 'redis:/var/lib/redis/data' ports: - '6379:6379' website: build: . command: > /usr/bin/supervisord env_file: - '.env' volumes: - '.:/gp_flask' ports: - '8000:8000' - '5000:5000' - '5001:5001' celery: build: . command: celery worker -l debug -A dear_flask.dear.tasks env_file: - '.env' volumes: - '.:/gp_flask' volumes: postgres: redis: 

这里是supervisord.conf

 [supervisord] logfile_maxbytes=50MB logfile_backups=10 logfile=/tmp/supervisord.log loglevel=info pidfile=/tmp/supervisord.pid nodaemon=true minfds=1024 minprocs=200 directory=/gp_flask/ [supervisorctl] #[program:sshd] #command=/usr/sbin/sshd -D [program:nginx] command=/usr/sbin/nginx -g "daemon off;" #command=ls # a dummy command convenient for disabling nginx [program:gunicorn] command=/usr/local/bin/gunicorn -b 127.0.0.1:8001 "dear_flask.app:create_app()" directory=/gp_flask/ 

在您的撰写文件中,用主卷(bind mound)replace/ gp_flash的内容:

  website: build: . command: > /usr/bin/supervisord env_file: - '.env' volumes: - '.:/gp_flask' ports: - '8000:8000' - '5000:5000' - '5001:5001' 

这会导致容器中的/ gp_flask文件夹中有任何内容. 目录。 本地,这将工作。 但是在远程服务器上,docker compose命令可能会引用一个空的或不存在的文件夹,就像您在AWS环境中看到的那样。 如果您删除了卷引用,则会按预期方式查看图像的内容。 如果您需要一个卷来存储持久性存储空间,请考虑使用一个命名卷,它将在您第一次使用时初始化为映像的内容。 例如:

 version: '2' services: postgres: image: 'postgres:9.5' env_file: - '.env' volumes: - 'postgres:/var/lib/postgresql/data' ports: - '5432:5432' redis: image: 'redis:3.0-alpine' command: redis-server --requirepass devpassword volumes: - 'redis:/var/lib/redis/data' ports: - '6379:6379' website: build: . command: > /usr/bin/supervisord env_file: - '.env' volumes: - 'gp_flask:/gp_flask' ports: - '8000:8000' - '5000:5000' - '5001:5001' celery: build: . command: celery worker -l debug -A dear_flask.dear.tasks env_file: - '.env' depends_on: - website volumes: - 'gp_flask:/gp_flask' volumes: postgres: redis: gp_flask: 

您应确保包含此文件夹的图像填充文件是第一个启动,或者在源容器启动之前没有其他容器写入文件夹。 要做到这一点,使用类似于我已经显示芹菜取决于网站的depends_on。