Reputation: 3521
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.
Upvotes: 3
Views: 1185
Reputation: 16120
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 \
Upvotes: 1