As said in previous post about Docker, my blog's Docker Image is only a middleware container. It needs to be launch with a frontend, a database and optionnaly a cache. A solution for get ready to play with a full containerized architecture is docker-compose, with it I followed micro-services architecturing and only define one service by container.
Docker-compose (previously fig) act as services manager, you create a
docker-compose.yml and it use it to create sets of containers, volume sharing and network links. See my
docker-compose.yml file, explaination are after:
database: image: mariadb volumes: - /opt/mysql:/var/lib/mysql:rw - extras/docker-compose/my.cnf:/etc/mysql/my.cnf:ro env_file: extras/docker-compose/compose.env cache: image: redis static: build: . command: myblog collectstatic --noinput volumes: - extras/docker-compose/myblog.cfg:/myblog.cfg:ro - static environment: - BLOG_CONFIG_FILE=/myblog.cfg middleware: build: . command: uwsgi --ini /uwsgi.ini links: - database - cache volumes: - extras/docker-compose/myblog.cfg:/myblog.cfg:ro - media frontend: image: nginx ports: - "80:80" - "443:443" volumes: - extras/docker-compose/nginx_site.conf:/etc/nginx/conf.d/default.conf:ro - extras/docker-compose/nginx_media.conf:/etc/nginx/conf.d/media.conf:ro - extras/docker-compose/ssl-certs:/ssl/:ro volumes_from: - static - middleware links: - middleware
Based on MariaDB, I mount inside MySQL configuration and a persistent database. MySQL/MariaDB images use environment variables for set database credentials, mine is extras/docker-compose/compose.env.
A simple base Redis image
This is a data container based on my blog's image. It gathers all static files taken from manage.py collectstatic. I mount a custom configuration file and defined
/static as a shared volume.
Based on my blog's image, it is the real middleware service which use uWSGI for serve my project. Middleware must have network links with cache and database. I mount the same configuration file and define
/media as shared volume.
It is an Nginx container exposing ports 80 and 443. It has a network link only with middleware and has shared volumes from middleware (media) and static. I mount SSL keys and nginx sites configuration.