How to include files outside of Docker's build context?

前端 未结 14 1083
情话喂你
情话喂你 2020-11-22 07:21

How can I include files from outside of Docker\'s build context using the \"ADD\" command in the Docker file?

From the Docker documentation:

T

14条回答
  •  不要未来只要你来
    2020-11-22 07:46

    Using docker-compose, I accomplished this by creating a service that mounts the volumes that I need and committing the image of the container. Then, in the subsequent service, I rely on the previously committed image, which has all of the data stored at mounted locations. You will then have have to copy these files to their ultimate destination, as host mounted directories do not get committed when running a docker commit command

    You don't have to use docker-compose to accomplish this, but it makes life a bit easier

    # docker-compose.yml
    
    version: '3'
      services:
        stage:
          image: alpine
          volumes:
            - /host/machine/path:/tmp/container/path
          command: bash -c "cp -r /tmp/container/path /final/container/path"
        setup:
          image: stage
    
    # setup.sh
    
    # Start "stage" service
    docker-compose up stage
    
    # Commit changes to an image named "stage"
    docker commit $(docker-compose ps -q stage) stage
    
    # Start setup service off of stage image
    docker-compose up setup
    

提交回复
热议问题