Copying files to docker-compose container


I’m using docker-compose to run tests for my project, and I use volumes to get my application code into docker-compose.

In circle 2.0 docker volumes don’t work, and it looks like the recommended solution to get files into a docker image is to use docker cp as specified here:

However, docker-compose has no cp option, and I can’t figure out an equivalent workaround with docker-compose to get my project files into docker-compose so that I can run tests. I think I can use docker cp with docker-compose after docker-compose up is already running, but docker-compose up instantly fails for me since all my files are missing, which is a bit of a catch 22. Is there some equivalent technique to what’s described in the above article that can work for docker-compose?


You can achieve that directly by using the machine executor instead of the base docker executor.


Could you elaborate on this a little more? What specifically needs to change to make docker work with the machine executor? I assume I need to do something extra to manually set up docker if I’m not using the docker executor?


Just change the docker section of your config to machine: true and remove the setup_remote_docker step. It’s actually less steps to get running on the machine.


I was able to get this to work without needing to use the machine executor with the following hacky technique, in case it’s useful to anyone else:

# give docker-compose run a nonsense command to keep it from quitting
docker-compose run -d <container> sleep 1000
# use docker cp to move files to the container
docker cp /local/path "$(docker-compose ps -q <container>)":/destination/path
# now run the actual command
docker-compose run <container> whatever-command

I’m sure there’s a better way to do this, but this is the best I could figure out


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.