Although I have tried so many docker-compose projects, I didn’t find any project that matches my requirement:
- Uses only Official Images.
- Simply enough to setup/modify.
- No extra deployment step from host to containers after changing the code.
So I have created a docker-compose project. Below are the reasons for you to use or not use it:
- Running Magento 2 project really fast on your machine.
- Just a few steps to setup.
- No extra step to deploy code from host to container.
- Easy to modify PHP, MySQL, and Nginx configurations.
- Works on Linux, macOS, and Windows.
Disadvantages (can be reduced in future releases):
- Lack of advanced tools like Redis, Varnish, XDebug.
- Lack of Environment variables configuration.
- Lack of tests on various types of projects.
You can now jump to the Github project or read the installation instruction below (Linux only).
1. Install Docker & docker-compose
// Install Docker $ curl -fsSL https://get.docker.com -o get-docker.sh $ sh get-docker.sh // Install docker-compose $ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose $ sudo chmod +x /usr/local/bin/docker-compose // Check docker status $ docker info
If you install docker with a non-root user, you will have permission issue, this is how to fix:
// Create the docker group if it does not exist $ sudo groupadd docker // Add your user to the docker group. $ sudo usermod -aG docker $USER // Run the following command or Logout and login again and run (that doesn't work you may need to reboot your machine first) $ newgrp docker // Check if docker can be run without root $ docker run hello-world
2. Getting started
It’s time to jump to the project README.md.
3. Some useful tips & tricks
APP_NAME: when you change this, everything that relates to APP_NAME will be changed too. For example, if you the change APP_NAME to
myapp, the login command will be:
docker exec -it myapp bash
MYSQL_IMAGE: Don’t use the version lower than 5.7 (5.6 for example). You may lose your data when run
Stop all other running containers to prevent port confliction:
// Stop all containers $ docker stop $(docker ps -a -q) // Stop all containers from system startup $ docker update --restart=no $(docker ps -a -q)
Remove old unused images to reclaim disk space:
$ docker image prune -a
Reset MySQL database (be careful, it will remove all MySQL data):
// Remove the mysql container first $ docker rm app_db // List all volumes $ docker volume ls // Remove the dbdata volume, the [volume_name] depends on current directory // So it look like "currentdirname_dbdata" $ docker volume rm [volume_name]
This post will be updated frequently