This project has been created as part of the 42 curriculum by ckhater
This project aims to set up a complete working environment using Docker technology. We must deploy Nginx, MariaDB, and WordPress in separate containers.
Docker is a platform for running and shipping applications. It solves a major problem: ensuring that applications run the same way on any system. Unlike virtual machines, where updates or configuration differences can break an application, Docker uses images that provide isolation and consistency. This also protects your host system from potential issues caused by misbehaving software or malicious code.
In this project, we run a website that depends on networking, since containers must communicate with each other.
-
Docker Network (Bridge Mode):
Each container gets its own IP address inside a private network. This is ideal for isolation between containers and allows them to communicate securely. I used bridge mode for this project. -
Host Network:
Containers share the host machine’s network stack. This means containers use the same IP as the host, and ports are accessed directly. It can be faster since there’s no extra network layer, but it is less secure, as containers are fully exposed to the host network.
-
Docker Volumes:
Volumes are storage areas managed by Docker, stored in Docker’s internal directory. They are ideal for persistent data such as databases because Docker handles permissions, backups, and portability between hosts. -
Bind Mounts:
Bind mounts link a folder from the host machine directly into a container. Changes in the host folder immediately appear in the container and vice versa. This is useful for development, live editing, or debugging.
-
Secrets:
Stored as files and are more secure. Used for sensitive data like database passwords. They are not baked into the Docker image, which prevents accidental exposure. -
Environment Variables:
Easier to use but less secure if someone can access the container environment. In this project, non-sensitive configuration is set via environment variables, while passwords are stored in secret files.
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER- Clone the repository:
git clone https://github.com/ckhater/Inception.git
cd Inception- Prepare secret files and environment variables:
mkdir -p secrets
echo "my_db_password" > secrets/db_pass.txt
echo "my_wp_password" > secrets/wp_pass.txt
echo "my_wp_admin_password" > secrets/wp_ad_pass.txt
echo "my_root_sql_password" > secrets/db_root.txt
touch /srcs/.envi'm going to write an example and it should be filled
DOMAIN_NAME=domain_name
DATABASE_SQL=wordpress
SQL_USER=sql_user
WP_AD_USER=wp_ad_user
WP_AD_EMAIL=wp_ad_email
WP_USER=wp_user
WP_EMAIL=wp_email
🚨 do not forget to add the domain name in /etc/hosts
127.0.0.1 domain_name
cd Inception
make up #build and start Docker containers
make down #stop and remove containers AI is a useful tool. It reduces the time needed to search for information. I used it to explain my problems and why I encountered them, so in future projects I won’t make the same mistakes. When I look for informations, it is provided instantly, with resources and detailed explanations.
For all information about docker i took them from :
- https://docs.docker.com/
- https://docs.docker.com/compose/how-tos/use-secrets/
- https://docs.docker.com/reference/compose-file/volumes/
there is also two books :
- docker deep dive by nigel poulton
- docker in action by Jeff Nickoloff and Stephen Kuenzli
and here other resources :
- https://developer.wordpress.org/cli/commands/
- https://medium.com/@amehri_tarik/42-inception-mariadb-wordpress-nginx-bonus-29c7c8e40453
- https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-nginx-mariadb-and-php-on-debian-10
- https://www.hostinger.com/fr/tutoriels/wordpress-nginx