This project has been created as part of the 42 curriculum by zelkalai
the goal of this project is to implement a multi service web infrastructur using docker. i configure nginx, wordpress, and mariadb as separate containers interacting over a dedicated network inside a virtual machine
to understand docker, we first look at the "but it works on my machine" problem.
imagine code works on your laptop because you have PHP 8.1 but your friend has PHP 7.4 so it crashes for hem. docker solve this by pakaging the application and all its dependencies into a single unit. this ensures the code runs identicaly everywhere using two key concepts: images and containers. every image start as a set of written instructions (dockerfile).
Everything starts here. Technically, a Dockerfile is just a simple text file that contains a list of instructions. it is a script containing a sequence of instructions that tells the docker engine how to assemble a custom docker image. Instead of you manually typing commands into a terminal one by one, you write these steps down in the Dockerfile to build a docker image automatically.
In system administration, we use Dockerfiles for three specific technical reasons:
Reproducibility: The ability to create the exact same environment every single time.
Customization: Extending a Base Image to add specific configurations.
Infrastructure as code: Your dockerfile is code you can push it to git. you can share it. you are not managing a "server" you are managing a "text file" that becomes a server.
A dockerfile is read from top to bottom. each line creates a new "layer" in your image.
when docker reads your dockerfile it does not create one big block of data. it creates layers.
Every instruction (like RUN apt-get install) creates a new layer. a layer is just a set of changes made to the file system. so docker stacks these layers on top of each other to form the final image.
why it does that ? caching. If you change the last line of your dockerfile, docker doesn't rebuild the whole thing. it reuses the first few layers (which haven't changed) and only rebuilds the last one. this makes building very fast.
The magic glue that holds these sheets together is called the Union File System (UnionFS). UnionFS takes these separate, read-only layers and merges them into a single view so the container thinks it is looking at one normal hard drive
it is an read-only template contain the technologies we need and any other tools/instruction used to create containers.
it is a runnable instance of an image that runs in an isolated user-space environment.
hen you start a container docker takes the read-only image and adds a thin "Read-Write" layer on top. another thing i should point to is, by default, containers are designed to be temporary. If you delete the container, that top "Read-Write" layer is destroyed, and your data is lost (unless you use Volumes).
virtual machines : each VM runs a full Operating System (kernel + user space). docker containers: They share the host's kernel but run in isolated user spaces (using Namespaces and cgroups). they are lightweight, start instantly, and use fewer resources.
Namespaces: this lies to the process. It tells the container "you are the only process running here" and "you have your own network" even though it's on your main computer. it isolates what the container sees.
cgroups (control groups - restriction): This limits the process. it tells the container "you can only use 10% of the CPU and 512MB of RAM." it limits what the container uses.
Environment Variables: variables stored in an .env file. They are easy to configure but less secure, as they can sometimes be seen in system inspection tools.
Docker Secrets: A safer method that stores sensitive data as files.
Host Network: the container uses the host's IP address directly. There is no network isolation between the container and the machine.
Docker Network: the standard for this project. containers run on a private internal network and communicate securely using their service names instead of IP addresses.
Docker Volumes: storage managed entirely by docker. you generally do not see or touch the actual file location.
Bind Mounts: links a specific folder on your machine to the container. we use this method to have full control over exactly where our data is stored on the disk.
i used AI to outline the necessary steps and phases for this project. it acted as a guide to keep my progress organized and ensure i followed the correct order of operations.