How to correctly mount my file/system or application files using docker compose?


#1

I have the following ci build set up https://github.com/Bixal/drupal-project/blob/settings-automation/.circleci/config.yml

In this build I have a docker-compose setup that I’m trying to test. In short I want to be able to run a docker compse up, run composer, and do a quick database install.

I am not quite understanding the documentation on mounting folders here at https://circleci.com/docs/2.0/building-docker-images/#mounting-folders .

I get to the composer install step docker-compose run php composer install and get an error message saying no composer.json is there. Running docker-compose run php ls /var/www/html reveals an empty dir. I’m a bit at a loss how this is working because in my latest build I’m running the actual --build flags and can see the output where I have my COPY commands.

Any help or advice would be appreciated.


#2

The problem is that, by virtue of the CircleCI architecture, you cannot use on-host volumes. They only work locally, but CircleCI hooks into Docker to spin up containers on remote boxes, and volumes don’t work over LAN connections.

There’s a solution involving docker create in the link you have given. Or, the way I do it, is to bake a new Docker image with everything it needs, and run that. That makes sense for me anyway, since I need the image artefact for deployment.


Docker-compose setup: messed up volumes
#3

But that’s the thing, I AM building an image, in my docker compose I use the build: ./ key, and I can see my COPY ./ /var/www/html command running in the output. What additional steps would I need to take to build these files into my image? If I run the new image locally and just use docker run I can create a container from my new image, with the applications web dir on there?

I appreciate the hlep, I’m just still not understanding why my files are not there, after I have built using the dockerfile included.


#4

Ah right. I haven’t seen your Dockerfile - I was looking at your compose file. In particular this:

volumes:
  - ./:/var/www/html:cached # User-guided caching

There’s a few of these, and if you don’t need the volumes, I wonder if you need to take them out. I wonder if this would effectively overwrite the files in the container with an (apparently empty) folder that has failed to mount.


#5

That was 100% it. I’ll need to have an additional override docker-compose.


#6

Great! You can use the acceptance device here, by the way - no need to hack the title.


#7

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