Docker, and small production server infrastructure advices
I’m figuring out how to setup my production server the best way, but i’m a little bit stuck about how to do it correctly:
Currently, all my web applications are dockerified, i have:
- One nginx front container, that route request to several backend containers:
- One Symfony App
- Two WordPress blog
- One NodeJS App
- One MySql container for DB storage
- One MongoDB container too
ALL this infrastructure is started using docker-compose.
This works fine but it sounds too much “monolitihic” for me:
- I cannot stop one container without restarting all the others.
- I cannot add other web applications without restarting everything
- I have no way to restart container automatically after a crash…
This is the first time i’m doing this, do you know some best practices or softwares that can help me to improve my production server ?
Thanks a lot !
2 Solutions collect form web for “Docker, and small production server infrastructure advices”
I cannot stop one container without restarting all the others.
What prevents you from using the
docker stop command instead of the
docker-compose stop command when you want to stop only one container?
I cannot add other web applications without restarting everything
I would suggest the use of the excellent jwilder/nginx-proxy nginx docker image to act as a reverse proxy in front of your other containers. This reverse proxy will adapt to the running/stopped containers. You can add a container later on and this reverse proxy will automatically route traffic to it depending on the domain name.
I have no way to restart container automatically after a crash…
Take a look at the
restart: directive for the docker-compose.yml file.
The “monolithic” view of docker-compose is indeed made to allow you to manage your application stack in one way. But one needs to know that docker-compose is a “layer” on top of docker which (docker) you can still use.
As @thomasleveil says, you still can manipulate docker-compose created containers individually with docker.
$ docker exec project_web_1 ls -l / $ docker stop project_db_1 $ docker up -d project_nginx_1 $ ...
In another hand I suggest to rely more on docker-compose which also allows to act on individual containers, separate your different applications or environments, and is aware of the dependencies between containers (not being exhaustive).
$ docker-compose exec web ls -l / $ docker-compose stop db $ docker-compose up -d nginx $ ...
Booting up a new service is also very easy with docker-compose, since it can detect things based on your yml config without stopping anything if not needed.
$ docker-compose up -d project_web_1 is up-to-date project_db_1 is up-to-date Creating project_newservice_1
I also find the help of a reverse proxy very useful for production installations. However I would more suggest the brand new Traefik which brings nice features like hot-reloading, service discovery, automated SSL certification with Letsencrypt and renewal (not being exhaustive).