- What Is Docker Compose
- Inception Docker Compose File
- Inception Makefile
- Compile Inception
- Setting Up Other Containers
Docker Compose is a powerful tool in the Docker ecosystem that enables you to manage multi-container applications with ease. Instead of handling each container individually, Docker Compose lets you define a complete application stack in a single YAML file, known as the docker-compose.yml file. This file specifies all the services, networks, and volumes your application needs, allowing you to start, stop, and manage your entire application stack with simple commands
-
Declarative Configuration
One of WordPress’s most praised features is its user-friendly interface. With a simple and intuitive dashboard, users can easily create and manage content without needing extensive technical knowledge. The platform supports a visual editor and a block-based editor (Gutenberg), making content creation and editing straightforward. -
Simplified Commands
WordPress offers a vast repository of themes that allow users to change the appearance of their site without altering the underlying code. These themes are designed to be customizable, enabling users to modify layouts, colors, fonts, and more to match their branding and style. -
Multi-Container Orchestration
Plugins are an integral part of WordPress, extending its functionality and allowing users to add features such as SEO optimization, social media integration, and e-commerce capabilities. With thousands of free and premium plugins available, users can tailor their WordPress sites to meet specific needs. -
Environment Management
WordPress is highly flexible, accommodating a range of website types from blogs and portfolios to business sites and online stores. It supports a range of custom post types and taxonomies, and its scalability ensures that it can grow with your website, handling everything from small personal sites to large enterprise-level applications. -
Isolation and Portability
As an open-source platform, WordPress benefits from a vibrant community of developers, designers, and enthusiasts. This community contributes to a vast repository of documentation, forums, and tutorials, making it easier for users to find solutions to common issues and to receive support.
Docker Compose is an essential tool for managing multi-container Docker applications. It simplifies the configuration, deployment, and management of complex applications by using a single YAML file to define all components. With Docker Compose, you can streamline development workflows, improve consistency across environments, and manage applications more efficiently. Whether you're building a small application or a large-scale system, Docker Compose provides the tools you need to handle containerized services with ease.
If you have not created yet the file type
vim ~/Inception/srcs/docker-compose.yml
And write inside
services:
mariadb:
container_name: mariadb
init: true
restart: always
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
env_file:
- .env
build: requirements/mariadb
volumes:
- mariadb:/var/lib/mysql
networks:
- docker-network
image: mariadb
nginx:
container_name: nginx
init: true
restart: always
environment:
- DOMAIN_NAME=${DOMAIN_NAME}
env_file:
- .env
build: requirements/nginx
ports:
- "443:443" #https
volumes:
- wordpress:/var/www/html
networks:
- docker-network
depends_on:
- wordpress
- mariadb
image: nginx
wordpress:
container_name: wordpress
init: true
restart: always
environment:
- DOMAIN_NAME=${DOMAIN_NAME}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- WORDPRESS_TITLE=${WORDPRESS_TITLE}
- WORDPRESS_ADMIN_USER=${WORDPRESS_ADMIN_USER}
- WORDPRESS_ADMIN_PASSWORD=${WORDPRESS_ADMIN_PASSWORD}
- WORDPRESS_ADMIN_EMAIL=${WORDPRESS_ADMIN_EMAIL}
- WORDPRESS_USER=${WORDPRESS_USER}
- WORDPRESS_PASSWORD=${WORDPRESS_PASSWORD}
- WORDPRESS_EMAIL=${WORDPRESS_EMAIL}
- REDIS_HOST=redis
- REDIS_PORT=6379
build: requirements/wordpress
volumes:
- wordpress:/var/www/html
networks:
- docker-network
depends_on:
- mariadb
- redis
image: wordpress
redis:
build: ./requirements/bonus/redis
container_name: redis
restart: always
networks:
- docker-network
image: redis
ftp:
build: ./requirements/bonus/ftp
container_name: ftp
restart: always
env_file:
- .env
environment:
- FTP_USER=${FTP_USER}
- FTP_PASSWORD=${FTP_PASSWORD}
- WORDPRESS_DIR=${WORDPRESS_DIR}
volumes:
- wordpress:/var/www/html
ports:
- "21:21"
- "21000-21010:21000-21010"
networks:
- docker-network
depends_on:
- wordpress
image: ftp
adminer:
build: ./requirements/bonus/adminer
container_name: adminer
restart: always
depends_on:
- mariadb
ports:
- "8080:8080"
networks:
- docker-network
image: adminer
static-site:
container_name: static-site
build: ./requirements/bonus/static-site
restart: always
ports:
- "80:80"
image: static-site
portainer:
build: ./requirements/bonus/portainer
container_name: portainer
ports:
- "8000:8000"
- "9443:9443"
- "9000:9000"
networks:
- docker-network
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer:/data
image: portainer
restart: always
volumes:
mariadb:
driver: local
driver_opts:
type: none
o: bind
device: ${HOME}/data/mariadb
wordpress:
driver: local
driver_opts:
type: none
o: bind
device: ${HOME}/data/wordpress
portainer:
driver_opts:
o: bind
type: none
device: ${HOME}/data/portainer
networks:
docker-network:
name: docker-network
driver: bridge
-
mariadb Service
- container_name
Names the container mariadb for easier reference. - init
Ensures the container is initialized properly, handling zombie processes. - restart
Configures the container to restart automatically if it crashes or the Docker daemon restarts. - environment
Sets environment variables for the MySQL database credentials and configuration. - env_file
Loads environment variables from a .env file for sensitive data like passwords. - build
Specifies the path to the Dockerfile for building the mariadb image. - volumes
Mounts a named volume mariadb to persist database data. - networks
Connects the container to the docker-network network. - image
Uses the mariadb image from Docker Hub.
- container_name
-
nginx Service:
- container_name
Names the container nginx. - init
Ensures proper initialization. - restart
Always restarts the container on failure. - environment
Sets the DOMAIN_NAME environment variable. - env_file
Loads additional environment variables from .env. - build
Path to the Dockerfile for building the nginx image. - ports
Maps port 443 on the host to port 443 on the container for HTTPS. - volumes
Mounts the wordpress volume to serve the website files. - networks
Connects to docker-network. - depends_on
Ensures nginx starts only after wordpress and mariadb. - image
Uses the nginx image.
- container_name
-
wordpress Service:
- container_name
Names the container wordpress. - init
Ensures proper initialization. - restart
Configures auto-restart on failure. - environment
Sets various WordPress and database environment variables. - build
Path to the Dockerfile for building the wordpress image. - volumes
Mounts the wordpress volume to serve the WordPress files. - networks
Connects to docker-network. - depends_on
Ensures wordpress starts only after mariadb and redis. - image
Uses the wordpress image.
- container_name
-
redis Service:
- container_name
Names the container redis. - restart
Configures auto-restart. - build
Path to the Dockerfile for building the redis image. - networks
Connects to docker-network. - image
Uses the redis image.
- container_name
-
ftp Service:
- container_name
Names the container ftp. - restart
Configures auto-restart. - env_file
Loads FTP-related environment variables from .env. - environment
Sets FTP user credentials and WordPress directory. - volumes
Mounts the wordpress volume. - ports
Maps ports 21 for FTP and 21000-21010 for passive FTP connections. - networks
Connects to docker-network. - depends_on
Ensures ftp starts only after wordpress. - image
Uses the ftp image.
- container_name
-
adminer Service:
- container_name
Names the container adminer. - restart
Configures auto-restart. - depends_on
Ensures adminer starts only after mariadb. - ports
Maps port 8080 for Adminer web interface. - networks
Connects to docker-network. - image
Uses the adminer image.
- container_name
-
static-site Service:
- container_name
Names the container static-site. - build
Path to the Dockerfile for building the static-site image. - restart
Configures auto-restart. - ports
Maps port 80 for serving static content. - image
Uses the static-site image.
- container_name
-
portainer Service:
- container_name
Names the container portainer. - build
Path to the Dockerfile for building the portainer image. - ports
Maps ports 8000, 9443, and 9000 for Portainer's web interface. - networks
Connects to docker-network. - volumes
Mounts Docker socket and Portainer data volumes. - image
Uses the portainer image. - restart
Configures auto-restart.
- container_name
-
Volumes
Volumes are defined to persist data and ensure that it is not lost when containers are stopped or removed:- mariadb: Stores MySQL data.
- wordpress: Stores WordPress files.
- portainer: Stores Portainer data.
Vim inside the root directory for Makefile
vim ~/Inception/Makefile
And how I have orchestrated all the compilation is like below:
DOCKER_COMPOSE_FILE := ./srcs/docker-compose.yml
ENV_FILE := srcs/.env
DATA_DIR := $(HOME)/data
WORDPRESS_DATA_DIR := $(DATA_DIR)/wordpress
MARIADB_DATA_DIR := $(DATA_DIR)/mariadb
PORTAINER_DATA_DIR := $(DATA_DIR)/portainer
name = inception
all: create_dirs make_dir_up
build: create_dirs make_dir_up_build
down:
@printf "Stopping configuration ${name}...\n"
@docker-compose -f $(DOCKER_COMPOSE_FILE) --env-file $(ENV_FILE) down
re: down create_dirs make_dir_up_build
clean: down
@printf "Cleaning configuration ${name}...\n"
@docker system prune -a
@sudo rm -rf $(WORDPRESS_DATA_DIR)/*
@sudo rm -rf $(MARIADB_DATA_DIR)/*
@sudo rm -rf $(PORTAINER_DATA_DIR)/*
fclean: down
@printf "Total clean of all configurations docker\n"
# @docker stop $$(docker ps -qa)
@docker system prune --all --force --volumes
@docker network prune --force
@docker volume prune --force
@sudo rm -rf $(WORDPRESS_DATA_DIR)/*
@sudo rm -rf $(MARIADB_DATA_DIR)/*
@sudo rm -rf $(PORTAINER_DATA_DIR)/*
logs:
@docker-compose -f $(DOCKER_COMPOSE_FILE) --env-file $(ENV_FILE) logs -f
.PHONY: all build down re clean fclean logs create_dirs make_dir_up make_dir_up_build
create_dirs:
@printf "Creating data directories...\n"
@mkdir -p $(WORDPRESS_DATA_DIR)
@mkdir -p $(MARIADB_DATA_DIR)
@mkdir -p $(PORTAINER_DATA_DIR)
make_dir_up:
@printf "Launching configuration ${name}...\n"
@docker-compose -f $(DOCKER_COMPOSE_FILE) --env-file $(ENV_FILE) up -d
make_dir_up_build:
@printf "Building configuration ${name}...\n"
@docker-compose -f $(DOCKER_COMPOSE_FILE) --env-file $(ENV_FILE) up -d --build
A Makefile is used to automate tasks and manage project builds. In the context of Docker and Docker Compose, a Makefile can simplify the process of starting, stopping, cleaning, and managing Docker containers. Here's a detailed breakdown of the provided Makefile:
- Variables
- DOCKER_COMPOSE_FILE: Path to the Docker Compose file.
DOCKER_COMPOSE_FILE := ./srcs/docker-compose.yml
- ENV_FILE: Path to the environment file containing environment variables.
ENV_FILE := srcs/.env
- DATA_DIR: Base directory for storing persistent data.
DATA_DIR := $(HOME)/data
- WORDPRESS_DATA_DIR: Directory for WordPress data.
WORDPRESS_DATA_DIR := $(DATA_DIR)/wordpress
- MARIADB_DATA_DIR: Directory for MariaDB data.
MARIADB_DATA_DIR := $(DATA_DIR)/mariadb
- PORTAINER_DATA_DIR: Directory for Portainer data.
PORTAINER_DATA_DIR := $(DATA_DIR)/portainer
- name: A variable to store the name of the configuration.
name = inception
- Targets
- all: Default target that creates necessary directories and starts the Docker Compose services.
all: create_dirs make_dir_up
- build: Creates directories and starts the Docker Compose services with build.
build: create_dirs make_dir_up_build
- down: Stops the Docker Compose services and removes the containers.
down:
@printf "Stopping configuration ${name}...\n"
@docker-compose -f $(DOCKER_COMPOSE_FILE) --env-file $(ENV_FILE) down
- re: Restarts the configuration by stopping, creating directories, and building services.
re: down create_dirs make_dir_up_build
- clean: Stops the services, prunes Docker system to free up space, and removes data from directories.
clean: down
@printf "Cleaning configuration ${name}...\n"
@docker system prune -a
@sudo rm -rf $(WORDPRESS_DATA_DIR)/*
@sudo rm -rf $(MARIADB_DATA_DIR)/*
@sudo rm -rf $(PORTAINER_DATA_DIR)/*
- fclean: Completely cleans up all Docker configurations, including stopping all containers, removing networks, and volumes.
fclean: down
@printf "Total clean of all configurations docker\n"
@docker system prune --all --force --volumes
@docker network prune --force
@docker volume prune --force
@sudo rm -rf $(WORDPRESS_DATA_DIR)/*
@sudo rm -rf $(MARIADB_DATA_DIR)/*
@sudo rm -rf $(PORTAINER_DATA_DIR)/*
- logs: Displays the logs of all running Docker Compose services.
logs:
@docker-compose -f $(DOCKER_COMPOSE_FILE) --env-file $(ENV_FILE) logs -f
- Additional Targets
- create_dirs: Creates the necessary directories for data storage.
create_dirs:
@printf "Creating data directories...\n"
@mkdir -p $(WORDPRESS_DATA_DIR)
@mkdir -p $(MARIADB_DATA_DIR)
@mkdir -p $(PORTAINER_DATA_DIR)
- make_dir_up: Launches Docker Compose services in detached mode.
make_dir_up:
@printf "Launching configuration ${name}...\n"
@docker-compose -f $(DOCKER_COMPOSE_FILE) --env-file $(ENV_FILE) up -d
- make_dir_up_build: Builds and starts Docker Compose services in detached mode.
make_dir_up_build:
@printf "Building configuration ${name}...\n"
@docker-compose -f $(DOCKER_COMPOSE_FILE) --env-file $(ENV_FILE) up -d --build
- Phony Targets .PHONY: Specifies that these targets are not files but commands. It prevents Make from being confused by files with the same names.
.PHONY: all build down re clean fclean logs create_dirs make_dir_up make_dir_up_build
This Makefile provides a set of commands to manage Docker containers and volumes effectively. It simplifies the process of setting up, building, and cleaning up Docker services. With targets to create directories, start services, clean up data, and display logs, it ensures a streamlined workflow for managing the Inception project.
Clone the repo into the virtual machine as specified in this article Setting up the system and the virtual machine
https://github.com/Vikingu-del/Inception-Guide.git
Allow all the exposed ports for each service for example:
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
To make it able to search by eseferi.42.fr (eseferi
my username) change the dns by running
sudo echo "127.0.0.1 username.42.fr" >> /etc/hosts
run make
make
Install firefox
apk update && apk add firefox
Open the browser and type:
https://username.42.fr
And have fun exploring.
Check the other links below for setting up the other services
- Mandatory
- Bonus
- DockerCompose and Makefile
- Project Subject