Understand the docker-compose application structure in Docker
Understand how to navigate a Docker Compose project structure and identify the purpose of its configuration, scripts, environment, and image files.
Lesson Content
The Docker Magento project is organized into a few directories, each with a specific responsibility. Understanding this structure helps you know where to look when you need to change the application configuration, build an image, or troubleshoot setup.
Start with the compose directory. This is the foundation of the local Docker Magento installation and the directory that gets checked out onto your machine when you install the project.
The Docker Compose YAML files in this directory orchestrate the containers. They define which services run, how those services are configured, and how they work together. At least two of these files are combined when you run bin/start.
There are also alternative development configuration files for SSH and Linux environments. To use one of these configurations, copy the appropriate file over the development YAML file.
The Makefile provides shortcuts for the commands available in the project. Run make without an argument to display the available documentation and commands:
makeThe bin directory contains the helper scripts used by those Makefile commands. These scripts handle common tasks such as starting the application, setting it up, and downloading the required files.
The env directory contains environment variables for the individual services. For example, db.env defines values such as the database host, root password, database name, database user, and database password.
These values are used when Magento is installed. The database service references this file through the env_file property in docker-compose.yml, so the service receives the configured environment variables when it starts.
Next, look at the images directory. This directory contains the instructions used to build the Docker images for the project.
Each service typically has its own directory, with additional directories for the versions supported by that service. For example, the PHP 7.4 image is located in a 7.4 directory inside the PHP image directory.
The Dockerfile in each version directory is the blueprint for that image. It explicitly defines how Docker builds the image. Each RUN instruction creates a layer containing part of the final image.
The image directory also contains a conf directory. This holds configuration files and other files that the Dockerfile copies into the image during the build process.
For example, the PHP image includes a php.ini file. The Dockerfile copies this file to PHP's standard configuration location. You can inspect the end of the Dockerfile to see the exact source and destination paths used for the copy.
The lib directory contains scripts used during installation. The one-line setup script runs a script from this directory, which downloads the project template and then executes bin/download and bin/setup.
The template file defines how the project template is downloaded. It uses Git to check out the Docker Magento code, primarily the compose directory, and then removes the files that are not needed in the local installation.
The template process also creates empty directories when they do not already exist. This prevents Docker from creating those directories as root inside the container when the services start.
For the most part, the project follows this structure:
composecontains the Docker Compose configuration used locally.Makefileprovides shortcuts for project commands.bincontains helper scripts.envcontains service-specific environment variables.imagescontains the Docker image build instructions.confcontains configuration files copied into images.libcontains installation and template scripts.
When you need to understand how a service runs, start in compose. When you need to change how its image is built, look in images. When you need to change service credentials or connection details, check the appropriate file in env.
Join the discussion!
Comments
Want to comment on this lesson?
Log in to leave comments.