Prepare Commerce for Docker

Cloud Docker for Commerce is one of the Cloud Suite for Commerce packages designed to deploy and manage local Adobe Commerce Docker environments for both cloud and on-premises projects.

If you are using Adobe Commerce on Cloud, you most likely have the magento/magento-cloud-docker package installed together with the magento/ece-tools package.

An on-premises installation requires the stand-alone magento/magento-cloud-docker package available in the Magento Cloud Docker GitHub repository.

Initialize the Commerce project

Cloud Docker for Commerce supports the Adobe Commerce installation for both cloud and on-premises projects. The initialization steps are different for each project type.

Cloud projects

To install a Adobe Commerce on cloud infrastructure project:

  1. Download an application template from the Magento Cloud repository. Be careful to select the branch that corresponds with the Commerce version.

  2. Optionally, you can clone the latest template.

    1
    
    git clone https://github.com/magento/magento-cloud.git <install-directory-name>
    
  3. Change to the new project directory.

  4. Add your access credentials to the auth.json file.

On-premises projects

When you initialize a Adobe Commerce project for Docker development, you must create a .magento.docker.yml configuration source file to create the Docker containers for the local environment.

To install an Adobe Commerce on-premises project:

  1. Create a project using Composer.

    1
    
     composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <install-directory-name>
    

    This command installs the latest release. To install a specific version, specify the version number, for example magento/project-enterprise-edition=2.3.5.

  2. Change to the project directory.

  3. Add the ece-tools and Cloud Docker for Commerce packages.

    1
    
    composer require --no-update --dev magento/ece-tools magento/magento-cloud-docker
    
  4. Create the default configuration source file, .magento.docker.yml to build the Docker containers for the local environment.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    
    name: magento
    system:
        mode: 'production'
    services:
        php:
            version: '7.3'
            extensions:
                enabled:
                    - xsl
                    - json
                    - redis
        mysql:
            version: '10.3'
            image: 'mariadb'
        redis:
            version: '5.0'
            image: 'redis'
        elasticsearch:
            version: '7.5'
            image: 'elasticsearch'
    hooks:
        build: |
            set -e
            php ./vendor/bin/ece-tools run scenario/build/generate.xml
            php ./vendor/bin/ece-tools run scenario/build/transfer.xml
        deploy: 'php ./vendor/bin/ece-tools run scenario/deploy.xml'
        post_deploy: 'php ./vendor/bin/ece-tools run scenario/post-deploy.xml'
    mounts:
        var:
            path: 'var'
        app-etc:
            path: 'app/etc'
        pub-media:
            path: 'pub/media'
        pub-static:
            path: 'pub/static'
    

    This default configuration file provides the minimum configuration for the Docker environment. For more detailed configuration information, see Configure and manage your project and environment.

Update the hosts file and install dependencies

Before you use Cloud Docker for Commerce, you must update the etc/hosts file and install required dependencies. You can do this manually, or using an installation script.

To update and install manually:

  1. Add the default magento2.docker host to the hosts file to make Cloud Docker recognizable on the local machine.

    1
    
    echo "127.0.0.1 magento2.docker" | sudo tee -a /etc/hosts
    
  2. Update the project dependencies.

    1
    
    composer update
    

To update and install using the installation script:

  1. Install the template dependencies and add the default hostname to your /etc/hosts file.

    1
    
    curl -sL https://github.com/magento/magento-cloud-docker/releases/download/1.2.0/init-docker.sh | bash -s -- --php 7.4
    

    If required, you can add options to the init-docker.sh initialization script to customize your Docker environment. Run the following command to see the available options:

    1
    
    curl -sL https://github.com/magento/magento-cloud-docker/releases/download/1.1.1/init-docker.sh | bash -s -- --help
    

After you complete the installation, you can begin using the Docker environment.