Docker allows developers to package applications with all of their dependencies into standardized units called containers that can run on any infrastructure regardless of the underlying operating system. It provides isolation and security so that many containers can run simultaneously on a single host. The document discusses how to set up both new and existing Magento projects using Docker, including downloading necessary files, importing databases, and using important Docker commands.
2. The problems
● IROMS (It Runs On My System) Syndrome.
● Unwanted updates to a system library / package / service.
● Underlying OS / OS Components changed.
● Upgrade in one service for Project A affected Project B.
● Team does not have standardized setup.
● Setup on new systems takes a lot of time.
3. Containerization
● Containerization involves encapsulating or packaging up software code and all its
dependencies so that it can run uniformly and consistently on any infrastructure.
● Develop and run the application inside an isolated environment (known as a container)
that matches your final deployment environment.
● Put your application inside a single file (known as an image) along with all its
dependencies and necessary deployment configurations.
● And share that image through a central server (known as a registry) that is accessible by
anyone with proper authorization
● Docker is One of many implementations of the ides of Containerization.
● It's an open-source containerization platform that allows you to containerize your
applications, share them using public or private registries, and also to orchestrate them.
4. What is Docker?
01 Docker is an open platform for developing, shipping, and running applications.
Docker enables you to separate your applications from your infrastructure so
you can deliver software quickly.
02 Docker provides the ability to package and run an application in a loosely
isolated environment called a container. The isolation and security allow you to
run many containers simultaneously on a given host.
03 Docker is a tool designed to make it easier to create, deploy, and run
applications by using containers. Docker containers are lightweight alternatives
to Virtual Machines and it uses the host OS.
5. Docker Benefits
● Runs on my machine = runs anywhere.
● New team member can be productive from day 1.
● Test app's compatibility with the newer version of
language/database.
● Boosts your career. (Preference for Docker Skill up by 50%).
● And lot more….
8. Prerequisites
● Docker hub account
● Docker Desktop (Mac OS and Windows)
● Docker WSL Linux Image setup (Windows only)
● Docker Engine (for Linux)
○ https://docs.docker.com/engine/install/ubuntu/
● Post-installation steps for Linux
○ https://docs.docker.com/engine/install/linux-postinstall/
● Docker Compose
○ https://docs.docker.com/compose/install/
● Git
● Composer
● Magento Marketplace Keys
● Curl
9. Setup New Project - Automated
1. Create your project directory then go into it:
a. mkdir ~/Sites/magento
b. cd $_
2. Run this automated one-liner from the directory you want to install your project.
a. curl -s
https://raw.githubusercontent.com/markshust/docker-magento/master/lib/onelinesetup |
bash -s -- magento.test 2.4.3-p1
3. After the one-liner above completes running, you should be able to access your site
at https://magento.test
10. Setup New Project - Manual
1) Create your project directory then go into it:
a) mkdir ~/Sites/magento
b) cd $_
2) Download the Docker Compose template:
a) curl -s
https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template |
bash
3) Download the version of Magento you want to use with:
a) bin/download 2.4.3-p1
4) Run the setup installer for Magento:
a) bin/setup magento.test
5) open https://magento.test
11. Setup Existing Projects
1. Take a backup of your existing database:
a. bin/mysqldump > ~/Sites/existing/magento.sql
2. Create your project directory then go into it:
a. mkdir ~/Sites/magento
b. cd $_
3. Download the Docker Compose template:
a. curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
4. Replace with existing source code of your existing Magento instance:
a. cp -R ~/Sites/existing src OR
b. git clone git@github.com:myrepo.git src
5. Start some containers, copy files to them and then restart the containers:
a. docker-compose -f docker-compose.yml up -d
b. bin/copytocontainer --all
12. Setup Existing Projects - Contd…
6. Import existing database:
a. bin/mysql < ../existing/magento.sql
7. Update database connection details to use the above Docker MySQL credentials:
a. creds for the MySQL server are defined at startup from env/db.env
8. Import app-specific environment settings:
a. bin/magento app:config:import
9. Create a DNS host entry and setup Magento base url
a. bin/setup-domain yoursite.test
10. bin/restart
11. open https://yoursite.test
14. Important CLI commands
● bin/bash
○ Drop into the bash prompt of your Docker container.
● bin/cli
○ Run any CLI command without going into the bash prompt. Ex. bin/cli ls
● bin/composer
○ Run the composer binary. Ex. bin/composer install
● bin/copyfromcontainer
○ Copy folders or files from container to host. Ex. bin/copyfromcontainer vendor
● bin/copytocontainer
○ Copy folders or files from host to container. Ex. bin/copytocontainer --all
● bin/cron:
○ Start or stop the cron service. Ex. bin/cron start
15. Important CLI commands - Contd…
● bin/fixowns
○ This will fix filesystem ownerships within the container.
● bin/fixperms
○ This will fix filesystem permissions within the container.
● bin/magento
○ Run the Magento CLI. Ex: bin/magento cache:flush
● bin/mysql
○ Run the MySQL CLI with database config from env/db.env
● bin/mysqldump
○ Backup the Magento database. Ex. bin/mysqldump > magento.sql
● bin/status:
○ Check the container status.
16. Important CLI commands - Contd…
● bin/stop
○ Stop all project containers.
● bin/start
○ Start all containers, good practice to use this instead of docker-compose up -d, as it may contain
additional helpers.
● bin/restart
○ Stop and then start all containers.
● bin/setup-domain
○ Setup Magento domain name. Ex: bin/setup-domain magento.test
● bin/update
○ Update your project to the most recent version of docker-magento
17. Miscellaneous Commands
● Get IP address of remote host (host.docker.internal)
○ docker run --rm alpine ip route | awk 'NR==1 {print $3}'
● Get IP address of container
○ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_id>