docker从一个容器复制文件到另一个容器?

前端之家收集整理的这篇文章主要介绍了docker从一个容器复制文件到另一个容器?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这是我想要做的:

> docker-compose build
> docker-compose $COMPOSE_ARGS运行–rm task1
> docker-compose $COMPOSE_ARGS运行–rm task2
> docker-compose $COMPOSE_ARGS运行–rm combine-both-task2
> docker-compose $COMPOSE_ARGS运行–rm selenium-test

还有一个看起来像这样的docker-compose.yml:

task1:
  build: ./task1
  volumes_from:
    - task1_output
  command: ./task1.sh

task1_output:
  image: alpine:3.3
  volumes:
    - /root/app/dist
  command: /bin/sh

# essentially I want to copy task1 output into task2 because they each use different images and use different tech stacks... 
task2:
  build: ../task2
  volumes_from:
    - task2_output
    - task1_output:ro
  command: /bin/bash -cx "mkdir -p task1 && cp -R /root/app/dist/* ."

所以现在所有必需的文件都在task2容器中…如何启动Web服务器并在task2中公开包含内容的端口?

我被困在这里……如何从我的combine-tasks / Dockerfile中的task2_output访问这些东西:

combine-both-task2:
  build: ../combine-tasks
  volumes_from:
     - task2_output
在最新版本的docker中,named volumes replace data containers作为在容器之间共享数据的简便方法.

docker volume create --name myshare
docker run -v myshare:/shared task1
docker run -v myshare:/shared -p 8080:8080 task2
...

这些命令将设置一个本地卷,-v myshare:/ shared参数将使该共享可用作每个容器内的文件夹/共享.

要在撰写文件中表达:

version: '2'
services:
  task1:
    build: ./task1
  volumes:
    - 'myshare:/shared'

  task2:
    build: ./task2
  ports:
    - '8080:8080'
  volumes:
    - 'myshare:/shared'

volumes:
  myshare:
    driver: local 

为了测试这个,我做了一个小项目:

- docker-compose.yml (above)
- task1/Dockerfile
- task1/app.py
- task2/Dockerfile

我使用node的http-server作为task2 / Dockerfile:

FROM node
RUN npm install -g http-server
WORKDIR /shared
CMD http-server

和task1 / Dockerfile使用python:alpine,显示两个不同的堆栈写入和读取.

FROM python:alpine
WORKDIR /app
COPY . .
CMD python app.py

这是task1 / app.py

import time

count = 0
while True:
  fname = '/shared/{}.txt'.format(count)
  with open(fname,'w') as f:
    f.write('content {}'.format(count))
    count = count + 1
  time.sleep(10)

拿这四个文件,然后通过docker-compose.yml在目录中运行它们 – 然后访问$DOCKER_HOST:8080以查看稳定更新的文件列表.

此外,我正在使用docker版本1.12.0并编写版本1.8.0但这应该适用于几个版本.

请务必查看docker文档,了解我可能错过的详细信息:
https://docs.docker.com/engine/tutorials/dockervolumes/

原文链接:https://www.f2er.com/docker/436951.html

猜你在找的Docker相关文章