Simple docker containers: create a dedicated image or mount configuration as a volume?

I am compiling a docker-compose.yml to run several services for the project I'm working on. This project has a Magento and Wordpress website located in the same domain, with that aspect of the "same domain" that requires a very simple nginx container to route requests to any service.

So, I have it archived as 4 containers ( visualization ):

  • The container is purple using its own image for the project.
  • Content "wordpress" using a proprietary image specific to the project.
  • The "db" container with mysql:5.6 , with init db /docker-entrypoint-initdb.d set in /docker-entrypoint-initdb.d .
  • The router container is running nginx:alpine with a custom configuration installed in /etc/nginx/nginx.conf . This works as a reverse proxy with two location settings. location / routes to purple and location /blog routes to wordpress.

I want everything to be simple and not create unnecessary custom images, but in the context of the “router” I’m not sure what I’m doing is the best approach or if it will be better than the project-specific image.

I am inclined to my current approach to creating a custom configuration in the nginx:alpine container, because the configuration is specific to the executable stack - it does not make sense as a separate standalone container.

Thus, two methods without a custom image have the following meanings in docker-compose.yml

  router: image: nginx:alpine networks: - projectnet ports: - "80:80" volumes: - "./router/nginx.conf:/etc/nginx/nginx.conf" 

Otherwise, we have a Dockerfile containing the following, as I have seen, offered over the Internet and in other StackOverflow answers.

  FROM nginx:alpine ADD nginx.conf /etc/nginx/ 

Does anyone have any arguments for / against any approach?

+5
source share
1 answer

If you bake 'nginx configuration (your second approach)

 ADD nginx.conf /etc/nginx/ 

it makes your docker containers more portable - that is, they can be downloaded and run on any server that can work with docker, and it will work.

If you use option 1, mounting the configuration file at run time, you transfer one of your dependencies outside of your container. This makes him addicted, which should be managed outside of dockers.

In my opinion, it is best to install as many dependencies as possible inside your docker files, because this makes them more portable and more automatic (great for CI Pipelines, for example)

There are reasons for mounting files at run time, and they usually focus on environment-specific settings (although they can be largely overcome in docker) or “sensitive” files that application developers should not or could not receive, for example, certificates ssl, database passwords, etc.

+1
source

Source: https://habr.com/ru/post/1268670/


All Articles