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.ymlversion: '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" servicedocker-compose up stage# Commit changes to an image named "stage"docker commit $(docker-compose ps -q stage) stage# Start setup service off of stage imagedocker-compose up setup