Install Magento 2 Docker

/ Comments off

Docker image for Magento 2.4.x. Magento 2.4.x has been available for a while and I created the images during the setup of my Magento 2.4.x instance. It took some time and it's better to share for easier onboard for others! Multiple containers approach. This repo provides Docker images for Magento 2.4.x versions. In Magento 2.4, the platform upgrades will enhance the performance of Magento store along with its security. It will be supported by PHP 7.4. Moreover, there is also the support for PHPUnit 9.x, Elasticsearch 7.6.x support, and MySQL 8.0 support.

Docker and Magento. In this first post, of which many will follow, we show you how to set up Docker for Magento 2 development. Way back when I first heard of Docker, I was still using WAMP, MAMP, Vagrant, VMWare and anything else I could get my hands on.

Magento 2 0.42.0-beta1 is available since a few days. In order to test it right away, we will see how to install a running demo in 5 minutes sharp thanks to Docker. If you don't know Docker, please report to our previous tutorial.

We will even go further and give you the choice between two types of setup:

  • a read-only discovery mode running instance of Magento 2 in order to discover the new admin interface and click
  • a developer mode, in order to have a development environnement and start playing with the brand new technical features of Magento 2.

Disclaimer : We assume you have a running and fonctionnal Docker on your computer.

Discovery mode

Ready ? Go and open a terminal, then copy/paste the following shell command (just adapt the password to your environnement)

That's it. You just have to copy the port that the last command just returned you and go to http://127.0.0.1:PORT in your favorite browser to start installing Magento 2 beta.

When asked for database information, set the host to db. For mySQL user, password, and database name, stick to what you entered in the previous MySQL Docker command.

Install Magento 2 Docker

If you stumble upon the following error message 'Cannot determine required PHP extensions: Missing key 'platform-dev' in 'composer.lock' file', click on 'Try Again' until 'Next' is available. Then, at the final step, another message will warn you about an error, don't pay attention to it, it's a var_dump still present in Magento 2 codebase. When the progress bar reaches 100%, go back tohttp://127.0.0.1:PORT.

Magento 2 setup wizard

Developer mode

Disclaimer: We assume you have Composer and fig installed and functionnal on your computer

This will go quickly too, except that we will have to install Magento 2 locally this time.

Open a terminal and enter:

Now add this fig.yml YAML config file for fig, don't forget to change the passwords :

Then we start our containers:

Copy the port given by the last command and go to http://127.0.0.1:PORT so start Magento 2 setup wizard.

When asked for database information, set the host to db. For mySQL user, password, and database name, stick to what you entered in the previous MySQL Docker command (see above).

As you have the source code on your computer, you can start adding your modules in app/code, changes will be visible in Docker.

And voilà ! We felt it was important to share this in order to allow you tio get your hands on Magento 2 very quickly.

Bonus : You can grab the sample data on Github for your testing purpose, as they are not yet available by default.

The most recent release of Magento Commerce, 2.4 included many new features and updates. The upgrade introduces support for PHP 7.4, Elasticsearch 7, and MySQL 8 versions. Not only that, but there is a significant security enhancement with two-factor authentication enabled by default for the Magento administrator. The release also introduces a default search engine catalog for Elasticsearch.

In this post, I will go over a few things you can do to get the best results from Magento 2.4.

Setup Magento 2.4 with a Docker Container

Upgrade or install Magento 2.4 in a Docker-isolated container for development. Doing this provides better elasticity and the ability to create separate instances for various purposes on a single underlying host machine. Please note that the Docker container can run on different PHP versions at the same time. Also, it provides an additional security layer for accessing the website code.

Why Elasticsearch is Must for Magento 2.4

Instead of using MySQL for search, Magento 2.4 now uses Elasticsearch as the default search engine. An Elasticsearch active node is required to complete the Magento 2.4 version. Similarly, a RabbitMQ can also be used for publishing messages in a queue and can define consumers that receive messages asynchronously. The Elasticsearch service can be created in a Docker container as well. For development purposes, we observed the recommended and supported version of Elasticsearch-7.6.x has some performance optimization when compared to the earlier version.

It’s important to follow the necessary system configuration process as recommended in the Elasticsearch documentation with respect to the file descriptor and virtual memory. If the underlying host is using a SWAP memory, then it’s recommended to limit the memory usage to avoid service killed due to high memory usage.

Use Varnish with Magento 2.4

Varnish, also referred to as ‘HTTP accelerated’, is designed for use with the HTTP protocol. Magento 2.4 supports the Varnish-6.x version. With the introduction of the latest Varnish support, the platform is optimized to serve the HTTP assets quickly back to the user.

Digitizing the Healthcare and Patient Experience

Find out how more than 100 healthcare executives and their respective organizations are modernizing patient and customer experiences.

Read the Report

Install Magento 2 Docker Windows 10

As shown below, any asset requests can be fulfilled by Varnish. For requests that don’t reach the Web servers, Varnish can also return the cached content and reduce the number of subsequent requests that must be filled by Magento.

In the latest release of Varnish for Magento 2.4, it’s recommended to use the VCL for the same Varnish-6.x version. This is due to the fact that some old variables have been deprecated and features such as restart the transaction after TTL or grace expiration. The Varnish service will fail to start if it isn’t supported by a VCL configuration.

Configure and Use Redis

For storing the PHP session and FPC, Magento provides a CLI option to configure Redis caching. The caching setting can be configured by making changes in the app/etc/env.php file for high-speed backend cache with full cache tag support. This is recommended in multi-server environments.

Using MySQL-8

Magento 2.4 is tested with the MySQL-8, but it also supports older versions like MySQL5.7. However, this has not been tested and recommended. The MySQL-8 version has some changes that support query optimization and indexer to optimize the Magento performance.

The MySQL-8 has binary logging enabled by default for database replication, which can be turned off to reduce the transaction time and database workload. But, in a cluster environment database replication, it’s a good thing to have for quicker fall back to a healthy node and to bifurcate the READ and WRITE database operation.

Infrastructure Setup for Magento2.4

As shown in the diagram below, an Azure CDN has been set up for delivering high-bandwidth static contents, accelerated dynamic contents, and WAF for blocking any unauthorized access for sensitive files. Then, Varnish is placed for accepting HTTP requests and serves cached contents that are available on its memory.

The uncached assets will proxy to the Magento container running on a dedicated cloud server. For search functionality, an Elasticsearch service is shared between both the WEB servers and a MySQL-8 database server, as well as with the Redis cache services to store Magento sessions and backend cache.

Using the architecture above, we’ve released six different environments for Magento-2 developments.

Install Magento 2 Docker Windows

Why It Helps

Install Magento 2 Docker For Mac

Docker technology is more controllable and granular as it is a microservices-based method focused on efficiency. Using containers, developers can create required environments that are isolated from other apps running on the same host if you are building code with repeatable infrastructure and configuration. When an application is containerized, it’s isolated from other apps running in the same system, thus direct access to the application code is not easy. Docker allows us to build, test, and release images that can be deployed across multiple servers and provides flexibility to scale out the instances in a short duration, and starts serving the production traffic. The use of accelerator, like Varnish & CDN, enhance the operability of the application and can reuse the cached contents for faster content delivery.