Skip to main content

Docker Compose install Magento 2

Victoria Harbour, Hongkong

Docker Compose

I am using the docker-compose file from @markshust and I am going to choose the manual installation for an existing project. You can use the provided shell script to download the necessary files from Github:

cd /opt/docker-magento2
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash

You will end up with the following files:

/opt/docker-magento2
├── .git
├── .gitignore
├── .vscode
├── bin
├── docker-compose.dev.yml
├── docker-compose.yml
└── env
└── db.env

The bin folder contains a couple of custom CLI commands and the MySQL user password is set inside the db.env file.

Editing the Compose File

version: "3"

services:
app:
image: markoshust/magento-nginx:1.18-4
ports:
- "80:8000"
- "443:8443"
links:
- db
- phpfpm
volumes: &appvolumes
- ~/.composer:/var/www/.composer:cached
- appdata:/var/www/html
- sockdata:/sock
- ssldata:/etc/nginx/certs

phpfpm:
image: markoshust/magento-php:7.4-fpm-2
links:
- db
volumes: *appvolumes

db:
image: percona:5.7
command: --max_allowed_packet=64M
ports:
- "3306:3306"
env_file: env/db.env
volumes:
- dbdata:/var/lib/mysql

redis:
image: redis:5.0-alpine

elasticsearch:
image: markoshust/magento-elasticsearch:7.6.2-2
ports:
- "9200:9200"
- "9300:9300"
environment:
- "discovery.type=single-node"

rabbitmq:
image: rabbitmq:3.7-management-alpine
ports:
- "15672:15672"
- "5672:5672"
volumes:
- rabbitmqdata:/var/lib/rabbitmq

The compose file sets up an NGINX web proxy, a PHP container, a MySQL Database as well as Redis, Elasticsearch and RabbitMQ. Since the Magento source code I inherited requires PHP v7.3 I will change the PHP image to markoshust/magento-php:7.3-fpm.

Magento Source

Download the version of Magento you want to use with:

bin/download 2.4.1

Create a DNS host entry for the site so you are able to access the frontend through this URL:

echo "127.0.0.1 ::1 my.magento.test" | sudo tee -a /etc/hosts

Run the setup installer for Magento:

bin/setup my.magento.test

You will be asked to login with your Magento Marketplace user credentials - use your public key as username and private key as password

Open https://my.magento.test