Inception is a 42 project focused on learning Docker and Docker Compose. The objective is to create a small network of three Docker containers: one for Nginx, one for WordPress, and one for MariaDB. These containers must interact over the Docker network to serve a local website.
The project is structured as follows:
srcs/
: Contains the Docker configurations and project files.nginx/
: Configuration files for the Nginx container.wordpress/
: Files related to the WordPress installation.mariadb/
: MariaDB configuration and initialization files..env
: Environment variables file.
To launch this project, follow these steps:
-
Clone this repository and navigate into it:
git clone <repository_url> cd <repository_directory>
-
In the
srcs
folder, fill out theExampleEnvFile
and save it assrcs/.env
. -
Edit the
login
variable in the Makefile to reflect your 42 school login. -
Build and launch the Docker containers using
make
:make
-
The website should be accessible at
https://localhost
orhttp://<your_login>.42.fr
(replace<your_login>
with the value in the Makefile).
-
Show Docker images:
docker images
-
Show Docker containers:
docker ps
Add
-a
to view stopped/exited containers:docker ps -a
-
Show Docker volumes:
docker volume ls
Inspect a volume:
docker volume inspect <volume_name>
-
Show Docker networks:
docker network ls
-
Show logs:
docker-compose logs
Follow logs for a specific container:
docker-compose logs --follow <container_name>
-
Run a container in interactive mode:
docker run -it <image_ID>
-
Execute a command inside a running container:
docker exec <container_name> <command>
-
Execute an interactive command inside a running container:
docker exec -it <container_name> <command>
-
Open a shell inside a running container:
docker exec -it <container_name> sh
FROM
: Sets the base image for the container. For example, Alpine:3.18.RUN
: Executes commands during the build process, such as installing software.COPY
: Copies files from the host to the container.EXPOSE
: Exposes a port to the outside.CMD ["command", "args"]
: Specifies the default command to run in the container. It can be overridden by providing a different command in thedocker run
command.ENTRYPOINT ["command", "args"]
: Defines the command to run at container startup. UnlikeCMD
, this command cannot be overridden bydocker run
.
- NGINX Configuration Beginner's Guide
- OpenSSL Man Page
- Generate Self-Signed SSL Certificate with OpenSSL
- How do I find the MySQL my.cnf location
- How to Install and Configure Mariadb
- Configuring MariaDB with Option Files
- MariaDB Server System Variables
- Configuring MariaDB for Remote Client Access
- How to Allow Remote Access to MariaDB in Ubuntu Linux
Ensure your data persists between container restarts by properly configuring Docker volumes. For instance, in the docker-compose.yml
file:
volumes:
db_data:
driver: local
wordpress_data:
driver: local
- Use strong, unique passwords for your MariaDB and WordPress instances.
- Regularly update your Docker images to include the latest security patches.
- Use optimized images, such as Alpine, to reduce the container size.
- Leverage multi-stage builds in Dockerfiles to keep your images lean and performant.
For 42 Student you can run the script ./init_docker.sh inside this repo https://github.com/alexandregv/42toolbox.git to use docker in goinfre !