Skip to content

This project aims to broaden our knowledge of system administration by using Docker. We will virtualize several Docker images, creating them in our new personal virtual machine.

Notifications You must be signed in to change notification settings

MarouanDoulahiane/inception-42

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Inception

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.

Project Structure

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.

Usage

To launch this project, follow these steps:

  1. Clone this repository and navigate into it:

    git clone <repository_url>
    cd <repository_directory>
  2. In the srcs folder, fill out the ExampleEnvFile and save it as srcs/.env.

  3. Edit the login variable in the Makefile to reflect your 42 school login.

  4. Build and launch the Docker containers using make:

    make
  5. The website should be accessible at https://localhost or http://<your_login>.42.fr (replace <your_login> with the value in the Makefile).

Project Notes

Viewing Docker Images, Containers, Volumes, and Networks

  • 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

Useful Commands for Debugging Docker Containers

  • 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

Dockerfile Basic Commands

  • 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 the docker run command.
  • ENTRYPOINT ["command", "args"]: Defines the command to run at container startup. Unlike CMD, this command cannot be overridden by docker run.

Useful Resources

Docker

Alpine Linux

Nginx

MariaDB

WordPress

Advanced Tips

Persistent Data

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

Security

  • Use strong, unique passwords for your MariaDB and WordPress instances.
  • Regularly update your Docker images to include the latest security patches.

Performance

  • 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 !

About

This project aims to broaden our knowledge of system administration by using Docker. We will virtualize several Docker images, creating them in our new personal virtual machine.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published