How to prepare docker for a production?
In order to use Docker on Production, you have to ensure that you can deploy easily, maintain multiple similar services and be ‘reboot proot’
1. Ditch Docker – Pick Compose
Docker compose is a great tool to keep docker as a configuration. You can add multiple dockers that too interlinked in docker-compose.yml file and run it.
2. Reboot proof Containers
There will be unavoidable circumstances when your host provider will reboot your system for scheduled or emergency maintenance. To ensure that containers/services come back online – use a ‘restart’ option. Version 2 and above support restart option.
[code] version: '3.2' services: web: image: nginx restart: always [/code]
3. Avoiding network_mode: hosts
Network mode (network_mode) host ignores the port binding. Whatever port is exposed by the container is exposed from host machine. With multiple containers in a single machine, it is very commanded to have few services with same type – example Nginx serving static files when using docker on production. For this reason, only the first service will be able to start and rest will give port already used error. Thus, avoiding network_mode has hosts should be avoided unless it is absolutely required.
4. Log Management
Logs can become overwhelmingly problematic if not managed. Ensure the format of the log, its location and also check for logrotate service. An unchecked log file will choke your server. It can disable ssh logins which can be devastating.
[code] logging: options: max-size: '12m' max-file: '5' driver: json-file [/code]
5. Not everything deserves a Container
It is tempting to have a stateless or portable container. However, some services need a lot of IO read-write and such services are often relying on databases. There can be a huge performance difference when these databases are not in containers.