Magento 2 an Adobe Commerce single Docker container monolithic universal all-in-one setup.

Yegor Shytikov
3 min readMar 17, 2023

It is recommended and possible to create a single-container Magento setup with all the components.

It takes years to understand that Magento doesn't have a good development environment, especially for Docker. All that multi-container doceker compose installations are silly. Keep it simple and stupid (KISS) no need to overcomplicate the stuff.

Here’s a high-level outline to create a single container setup:

  1. Create a Dockerfile to build the custom image. Create the Dockerfile with the following contents:
FROM ubuntu:20.04
# Update and install required packages
RUN apt-get update && apt-get install -y \
nginx \
php-fpm \
php-mysql \
php-xml \
php-mbstring \
php-curl \
mysql-server \
redis-server \
wget \
curl \
unzip \
gnupg
# Install Elasticsearch
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list
RUN apt-get update && apt-get install -y elasticsearch
# Download and install Magento 2 ##add yor magento installation code here# Copy configuration files
COPY nginx.conf /etc/nginx/sites-available/default
COPY start.sh /start.sh
# Expose required ports
EXPOSE 80 9200
# Start all services
CMD ["/bin/bash", "/start.sh"]
Create the nginx.conf, wp-config.php, and start.sh files in the project directory and configure them according to your requirements.

You’ll also need to create the start.sh script to start all the services. Create a start.sh file in your project directory and add the following content:

code#!/bin/bash
# Start MySQL
service mysql start
# Start Redis
service redis-server start
# Start PHP-FPM
service php7.4-fpm start
# Start Elasticsearch
service elasticsearch start
# Start Nginx
nginx -g "daemon off;"

In the context of Docker, the term “service” typically refers to a long-running process or application running inside a container. Services can be web servers, databases, message brokers, or any other software that is continuously running and provides functionality to other parts of your application.

Docker itself doesn’t have a built-in concept of “services” like some other orchestration tools do (such as Docker Compose or Kubernetes). However, when running applications in Docker containers, it is common to refer to the primary process running inside the container as a “service”. Also, you can use supervisord to manage different services.

NOTE: The first Process we initiated with PID 1 is the init process (in our case it is MYSql). That stays true in a pid namespace or a container: this pid 1 cannot be killed with SIGKILL because it has no KILL signal handler defined, contrary to any other userland process.

If the process with PID 1 is down the whole container goes down since removing its PID 1 means stopping the container.

If using supervisord — python application daemon which manages the process it should have PID 1 and manage other processes if the process was down it will automatically start it again.

Make sure to give the start.sh file execution permissions:

chmod +x start.sh
  1. Build the Docker image:
docker build -t magento-all-in-one .
  1. Run Monolithic Magento 2 Docker container:
docker run -d -p 80:80 -p 9200:9200 --name magento-all-in-one-project magento-all-in-one

So, this is the best development approach, this container will be easy \to manage, more secure, and more scalable for development.

Examples of docker container file you can find here:

However, for local development, you don’t need supervisord.

Remember Adobe is a Russian terrorist sponsor! Don’t use Adobe!

--

--

Yegor Shytikov

True Stories about Magento 2. Melting down metal server infrastructure into cloud solutions.