What are the reasons to set up Magento 2 on Docker
Have you at any point considered how long the normal software engineer spends simply setting up a dependable configuration of work tools? The response certainly shifts from one association to another; the software stack the developer refers to has a great influence; the documentation accessibility level is another reason. Most engineers, regardless industry they work in or stack they utilize, can identify with their own battling to set up a work system configuration. Some of those have seen how their work group has such struggles.
Benefits on Docker utilization are more evident when developers work in a group. The work configuration can be set up fast enough to begin generating software builds rapidly.
What benefits Docker brings when it is set up for Magento 2
On the off chance that a developer actually wonders about configuring Magento 2 using Docker, the accompanying reasons can assist with settling on a choice. The following are some principal justifications for why Magento software should be set up on Docker:
- Docker transforms the development process into solid experience. Its movability and adaptability are ideally suited for developing Magento 2.
- Installation simplicity and ease of usage.
- The software can be set up on a local computer for fast start of development.
- Reliability of the Docker simplifies the development of PHP-based applications, including Magento.
Prepare to Docker set up
Set up of local environment
The first step is the configuration process is to obtain an account on Adobe Commerce web site. Those users who already have this account do not need to register a new one. Login into the Adobe Commerce account and create or copy the existing pair of authentification keys. The account may already have these keys since it is used for Magento Marketplace.
Check system requirements for Docker
Depending on the particular usage case for the Docker a paid subscription may be required. Docker is not free of charge for professional users in businesses with 250 employees or more than $10 million in annual revenue.
Docker pushes such requirements for the system configuration:
Windows The host system for containers can be Windows 11 and Windows 10. Both can be Home, Pro, Enterprise, Education editions. The former should be not older that 21H2, the latter shoudl be build 19041 for Home or Pro, and build 18363 Enterprise or Education editions. The operation system should have the WSL 2 subsystem installed on Windows Or Hyper-V. Windows features for containers must be enabled. Hardware requirements are not strictly defined. The machine should be capable to run WSL 2 on both Windows 10 and Windows 11. It means that the processor should be a 64-bit one with Second Level Address Translation (SLAT) support. The system should have at least 4GB of RAM. Virtualization should be enabled in BIOS. In case Docker is configured on Mac the latter should have the following specification: - Intel x86 processor - macOS 10.15 or newer (Catalina, Big Sur, Monterey). - 4 GB of RAM. - VirtualBox 4.3.30 or older should be uninstalled since it incompatible with Docker. Owners of Mac computers on Apple M1 ARM processors should use the Rosetta 2 translator in order to run Docker.
In order to correctly configure and run Docker a Compose tool is required. This software utility allows characterizing and loading applications in Docker’s multi-holders. With Compose, a specific YAML record is used to arrange the application's configuration. Then, at that point, with a solitary command line, it becomes possible to make and start every one of the configured services. See the rundown of Compose elements in case you wonder on the every one of the function highlights Compose provides. Compose works in all configured software systems for software creation, improvement, testing. Read on the official documentation for common use cases. You can start using the tool with a process that basically consists of thee steps:
- Define your application's current configutation by using a specific Dockerfile, which later can be reused anyplace.
- Set up all required services for the application to run. Use the docker-compose.yml file to make such configuration. This allows using the app in the detached software environment.
- Run the Docker commands for createing and composing commands to launch the app. Alternativel, the app can be launched via the docker-compose binary.
Check the template for the docker-compose.yml in order to use it i your configuration:
version: "3.9" # optional since v1.27.0
On Mac computers follow the algorithm for Docker installation:
- Get a local copy of Docker.dmg file
- Open the app installer by double clicking on the downloaded Docker installation package. When finished, the Docker can be dragged to the applications folder.
- Navigate to the applications folder and start Docker by double-clicking on its Docker.app file.
- The screen will display the Docker menu, that includes a window with the service conditions and user agreement. Accept the document to get the access to Docker.
On desktop Windows computers install Docker using the following algorithm:
- Download the official installation file for Docker from the Docker Hub. Typically this file is downloaded to the default download folder your browser uses, which is a system download folder.
- Double click on the obtained file to launh the installation. Ensure that all required Windows software features are enabled, namely Hyper-V and WSL 2. Install those components if necessary.
- Follow the guidance of the Docker’s setup wizard to proceed and when successfully finished click Close.
- In case the current user account doesn’t have the admin access level, add it to the docker-users group. Do it by running the Windows Computer Management tool as an administrator. Navigate to the menu Local Users and Groups > Groups > Docker-users. Add the current user to the Docker group by right clicking on the option. Make a re-login into the system to apply the changes.
To install and run Docker on server Windows edition do the following:
- Start an "elevated" PowerShell (run it as administrator). Search for PowerShell, right-click, and choose Run as administrator. When asked if you want to allow this app to make changes to your device, click Yes.
In PowerShell, since GitHub now requires TLS1.2, run the following:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Then run the following command to download the current stable release of Compose (v1.29.2):
Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\Docker\docker-compose.exe
Note: On Windows Server 2019, you can add the Compose executable to
$Env:ProgramFiles\Docker. Because this directory is registered in the system PATH, you can run the
docker-compose --version command on the subsequent step with no additional configuration.
To install a different version of Compose, substitute
1.29.2with the version of Compose you want to use.
- Test the installation.
docker-compose version 1.29.2, build 01110ad01
In case Docker is required under Linux environment install it as follows:
- Run this command to download the current stable release of Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
To install a different version of Compose, substitute 1.29.2 with the version of Compose you want to use.
Apply executable permissions to the binary
sudo chmod +x /usr/local/bin/docker-compose
Note: If the command docker-compose fails after installation, check your path. You can also create a symbolic link to
/usr/bin or any other directory in your path.
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Optionally, install command completion for the bash and zsh shell.
Test the installation by running the command
Start Docker instance
Ready to start - In this step, you still need to open your terminal to /path/to/docker. - It’s time to fire up your virtual machine. As soon as you spin up, it takes some minutes so that Dockers can download the images. After that, spin-ups in the future will take a few seconds.
docker-compose up -d –build
- Please make sure that everything is set up and run as per your plan.
Install Magento 2 in Docker
Access your command line that contains your Docker web:
docker exec -it web bash
Please go-ahead to the web document
root: cd /app
Although this is an optional step, highly recommended to deploy sample data with
php bin/magento sampledata:deploy
Install Magento 2. Learn how to install Magento2 via Composer in our article
Note: We have created a clear Magento installation. But if you will need, you can install any additional extensions like layered navigation extension and use them together.
- Navigate to your website at
https://local.domain.comor whatever domain you select. You need to spend some minutes loading the page when you access the website for the first time. The reason for this is that nothing is cached and the Magento system will automatically create files when loading the pages. Don’t worry, as the loading process will be quicker next time.
Note: Additionally, as the web container applies a self-signed SSL certificate, you can get a security alert from the browser when visiting the URL for the first time.
Congratulations! You succeed in setting up Magento 2 on Docker. Please remember that you can repeat this process for other projects through our step-by-step guide.
Installing Docker on any popular platform does not take much time while allowing preparing the workplace very quickly. Containerization is an excellent alternative to hardware virtualization. All processes in container take place at the operating system level, which allows significantly saving resources and increasing the efficiency of working with applications.
Here the most profound advantages of using Docker:
- Minimal resource consumption. Containers do not virtualize the entire operating system (OS). They use the host kernel and isolate the program at the process level. This way the app consumes much less resources of the local computer than the virtual machine.
- High-speed deployment. Installation of the auxiliary components can be skipped with the ready-made docker templates. For example, a developer can skip constant installation and configuring Linux environment for his apps. He can make a single template and reuse it when necessary.
- Convenient hiding of processes. Different data processing methods can be used for each container, hiding background processes.
- Work with insecure code. Container isolation technology allows running any code without harm to the host OS.
- Easy scaling. Any project can be expanded by introducing new containers.
- Convenient launch. The application located inside the container can be run on any docker host.
- File system optimization. The image consists of layers that allow using the file system very efficiently.