4.1: Prepare the ground: Creation of the network and files.

So far, we’ve mostly worked with simple containers. But in the real world, an application is almost never on its own. It often depends on other services: a database, a cache, a search engine, and so on.

In this section, we’ll build a small, classic web stack:

  • a PHP/Apache server to run the site
  • a MariaDB database to store the information

And this time, we’ll do everything manually with docker run.
It’s not the most practical method… but that’s on purpose. The goal is to experience the complexity firsthand so we can better understand whyDocker Compose exists (that will be the next section).

Before launching anything, just like on a construction site, we need to prepare the ground.

🌐 Create a network for our containers

By default,Docker places the containers in an internal network called bridge.
This works, but in a real project it’s better to create a dedicated network for our application.

Why?

Because this network will allow:

  • the containers to communicate with each other
  • isolate our application from the rest of the containers
  • the use of container names as DNS names

In practice, our web server will be able to contact the database simply by using:

mariadb

instead of an IP address.

So let’s create a network calledmonprojet-network:

docker network create monprojet-network

Docker which normally returns a network identifier.

We can verify that it exists with:

docker network ls

You should see something like:

NETWORK ID     NAME                DRIVER
xxxxxxx bridge bridge
xxxxxxx host host
xxxxxxx none null
xxxxxxx monprojet-network bridge

Our network is ready.

📁 Set up the project directory structure

Step two: prepare the project folders.

In Docker, a container is ephemeral.
This means that if you delete the container, everything it contains disappears.

To avoid this, we’ll store some data on the host (your server or your machine).

In our project, we’ll need two things:

  • a folder for the PHP site
  • a folder for the MariaDB database data

Let’s create a project folder:

mkdir monprojet
cd monprojet

Then the following directory structure:

mkdir app
mkdir data

This gives us:

monprojet/

├── app/ → contiendra notre site PHP
└── data/ → contiendra les données MariaDB

These folders will be mounted in the containers at launch time.

🧠 Why do this?

These folders will enable two essential things:

The app

It will contain our PHP site.

DockerAdvantage:
we can modify the files directly from our machine without rebuilding the image.

The folder data

It will contain the MariaDB database files.

Advantage:
if the MariaDB container is deleted or recreated, the data remains intact.


📌 Key takeaway

Before launching containers for an application, it is recommended to set up:

  • a dedicated networkDocker for communication between services
  • a clear project directory structure
  • folders for persistent data

In our case:

monprojet/
├── app
└── data

and the network:

monprojet-network

Everything is now ready for the next phase of the project.

In the next lesson, we’ll start the MariaDB database with docker run`,` using environment variables to configure it automatically. 🚀