Copy docker file from one container to another?

Here is what I want to do:

  • docker-compose build
  • docker-compose $ COMPOSE_ARGS run --rm task1
  • docker-compose $ COMPOSE_ARGS run --rm task2
  • docker-compose $ COMPOSE_ARGS run --rm comb-both-task2
  • docker-compose $ COMPOSE_ARGS run --rm selenium-test

And the docker-compose.yml file looks like this:

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/* ."

So, now all the necessary files are in the container task2 ... how can I start the web server and open the port with the contents in task2?

I'm stuck here ... how can I access materials from task2_output in my compiler tasks / Docker file:

combine-both-task2:
  build: ../combine-tasks
  volumes_from:
     - task2_output
+4
source share
1 answer

docker .

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

, -v myshare:/shared /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 up docker-compose.yml - $DOCKER_HOST: 8080, .

, docker 1.12.0 1.8.0, .

docker , , , :
https://docs.docker.com/engine/tutorials/dockervolumes/

+6

Source: https://habr.com/ru/post/1651870/


All Articles