3

I run different instances of a PHP software using Docker. Each instance has its own database container, app container, docker-compose file, etc (no swarm, kubernetes, or orchestration of any kind).

There there are customizations that I have to include on /usr/local/etc/php/conf.d/. I need to alter the contents of a file, and add another file.

This is how I'm currently achieving this on docker-compose:

volumes:
  - "./conf/disable-opcache.ini:/usr/local/etc/php/conf.d/opcache-recommended.ini:z"
  - "./conf/custom.ini:/usr/local/etc/php/conf.d/custom.ini:z"

It works, but forces me to have a copy of both files for every instance of the app. When I want to make changes, I need to replicate them to every instance.

I want to have an easy, portable, replicable way of placing these customizations on multiple instances of these containers.

I have read this answer and what I'm currently doing is basically their option (a), but it has all the drawbacks I mentioned. I can't use option (b) because there's no support on the images I use - at least not for all the custom configs I need; whereas for option (c) I'd need to create a custom derived image for every version/tag of every image we use.

What I tried was creating an image containing only the configuration files, and add that as a volume. It works if the volume is a folder, but then it "overwrites" the original folder and only these 2 custom files are present, whereas I need the other original files on the folder to be present as well.

If I try to use a single file as a volume, it doesn't work.

I'm thinking I could maybe place all the files in a volume in a new image, and then create symlink on the containers to each file. But I'm not sure how I would create those symlinks on the containers.

There's probably a better way to proceed, but I'm unfortunately stuck.

That Brazilian Guy
  • 3,328
  • 5
  • 31
  • 49
  • 1
    I'm not adding this as an answer, because you said you weren't considering swarm. But, you can use swarm locally, without a cluster (use: `docker swarm init`), which can still read your compose files, and then you could use the 'configs' feature which was created to solve your exact problem: https://docs.docker.com/engine/swarm/configs/ – Software Engineer Apr 04 '19 at 14:25
  • @EngineerDollery I wasn't aware of this functionality. Or that you can run a single "node" in swarm. It seems indeed the most elegant and logical approach. Please, *do* write an anwser, I'll accept it. – That Brazilian Guy Apr 04 '19 at 15:42
  • If you mount every instances on a single file, it works no ? – Kilian Apr 04 '19 at 16:14

1 Answers1

1

Maybe ou should try to make use of the swarm configuration service: based on your description I think it will help you move forward.

You can use swarm on a single 'node' (your local machine), and continue to make use of your compose files. Use: docker swarm init to begin.

You add your disable-opcache.ini file to the service like so:

docker config create dopcache disable-opcache.ini

Then use something like this to pass the config to your containers:

docker service create \
   --name myphpapp \
   --config source=dopcache,target=/usr/local/etc/php/conf.d/opcache-recommended.ini,mode=0440 \
   -c my-docker-compose.yml \
   myphpimage:latest \
Software Engineer
  • 15,457
  • 7
  • 74
  • 102