Skip to content

Docker Local Environment For A New Project

Alexander Lukyanov edited this page Oct 19, 2022 · 22 revisions

The docker local environment containers in the basic configuration have 1 file and 2 directories:

  • docker-compose.yml - Docker compose stack
  • dev - The directory used to keep stored data for rabbitmq and redis
  • src - The directory with a Magento 2 source code

Example of the directory structure:

image

Before You Get Started

  1. Install, run and verify that Docker Local Services working properly.

Get Started In 5 Steps

For the predefined configurations you need to:

  1. Create a project directory. Create an empty directory with the name: dev. Create an empty directory with the name: src.
  2. Copy Magento 2 source code to the src directory.
  3. Copy a YML file with to the project directory. (List Of Exmaple YML Files)
  4. Rename the YML file to docker-compose.yml and update project code and domain in the file. The example file has project code mag22 and project domain mag22.test.
  5. Run containers from the project directory using the command
docker-compose up -d 

Don't forget to add your project domain to the your OS hosts file. For example: mag22.test

127.0.0.1 mag22.test

NOTE: The hosts file location may be unique to a OS. The common hosts file path is C:\Windows\System32\drivers\etc for Windows or /etc/hosts for Linux

Example Local Environment YML Files

  • Magento 2 + Redis + Elasticsearch + RabbitMQ View
  • Magento 2 + Redis + Elasticsearch + RabbitMQ + Varnish View

PWA Venia Storefront Example

When you install PWA Venia Concept you will use the same docker-compose stack and frontend project will be installed locally.

  1. create a pwa folder for the frontend project. Magento: Setup a storefront project
  2. Install PWA package for your Magento 2 store:
docker-compose exec -u www cli composer require magento/pwa
docker-compose exec -u www cli bin/magento setup:upgrade
  1. (Optional) Install [Sample Data] (https://developer.adobe.com/commerce/pwa-studio/guides/packages/venia/sample-data/) for the sample data
  2. Make sure that your local environment has Node >= 16 Minimum requirements
node -v
  1. Setup a storefront project locally Magento Instructions
npm init @magento/pwa

  1. Edit pwa/.env At the PWA project’s root directory edit the .env file:
  • Modify the variable MAGENTO_BACKEND_URL to be same as your Magento URL and MAGENTO_BACKEND_EDITION is a correct Magento edition.
  1. Run development server
npm run watch

After this you will see information on how to access the Development instance.

For Example:

image

Access

NOTE: The website domain can be changed at the docker-compose.yml file

The following example where website domain is mag22.test`

Service Host
Magento 2 Website mag22.test
Elasticsearch elasticsearch.mag22.test
RabbitMQ rabbitmq.mag22.test
Redis redis.mag22.test
Varnish varnish.mag22.test
PWA TBD