Compose Magento 2

 

 

Getting started

Make sure you first followed the global getting started steps.

1. Clone the git repository next to your project folder.

$ git clone git@github.com:dockerwest/compose-magento2.git

2. Copy .env-sample to .env and update accordingly

Set the relative path to the folder where your project is located:

APPLICATION=../magento2

3. Start the project-specific environment

$ ./environment

4. Start the docker environment

$ run up

The helper command run is an alias to docker-compose, specific for the current environment.

5. Access your project in the browser

This can be done in one of the following ways:

  • Use Docker Developer DNS
    This way you can access the environment by browsing magento2.dev in your browser.
  • Use Nginx Proxy
    This way you can access the environment by browsing magento2.dev in your browser.
  • Add ports section to the nginx config in the docker-composer.yml file:
    nginx:
        ports:
            - "80:80"
                
    This way you can access the environment by browsing localhost:80 in your browser.

What's in the box?

The following technologies are out-of-the-box available in this environment.
Click on one of the names for more information.

php-magento2 image named application, which mounts the APPLICATION path to the image and links to mysql, redis and mailcatcher.

You can access the php-cli using the php helper. (see below)

The following packages are installed: php-gd php-common php-intl php-mbstring php-mcrypt php-mysql php-readline php-soap php-xsl php-bcmath

nginx-magento2 image named nginx, which mounts the APPLICATION path to the image and links to application.

This nginx container is available at magento2.dev and www.magento2.dev through

- VIRTUAL_HOST=${BASEHOST:-magento2.dev},www.${BASEHOST:-magento2.dev}

Redis image named redis.

This redis container is available at redis.magento2.dev through

- DOMAIN_NAME=redis.${BASEHOST:-magento2.dev}

Connection settings:

host: redis

Mysql image named mysql.

The mysql root password is provided through the environment variable in the .env file through:

- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-toor}

This mysql container is available at mysql.magento2.dev through

- DOMAIN_NAME=mysql.${BASEHOST:-magento2.dev}

You should first create a new database through the create_db helper command (see below).
Connection settings:

host: mysql
port: 3306
user: root
password: toor  (unless changed in .env file)

Mailcatcher container named mailcatcher.

This mailcatcher container is available at mailcatcher.magento2.dev:1080 through

- DOMAIN_NAME=mailcatcher.${BASEHOST:-magento2.dev}

SMTP settings for your application are:

host: mailcatcher
port: 1025

Available helper commands

Click on one of the commands for more info and an example.

Run docker-compose for the current project, setting the project name to the BASEHOST variable from the .env file

$ run up

Execute the php command inside the running php container, or inside a php-magento2 container if none is running.

The working directory will be the current directory you are executing this command from.

eg.
$ php -v

Run the composer command inside the php docker container. The working directory will be the current directory you are executing this command from.

Your $HOME/.ssh and $HOME/.composer folders wil be mounted inside this container to enable you to make use of your ssh keys and composer cache.

eg.
$ composer require package_name

Run the bin/magento command inside the php docker container. The working directory will be the current directory you are executing this command from.

eg.
$ magento setup:install

Run the magerun command inside the php docker container. The working directory will be the current directory you are executing this command from.

eg.
$ magerun cache:clear

Installs Magento using "setup:install" with default parameters:

db-name=magento2, language=nl_BE, currency=EUR, timezone=Europe/Brussels
admin-user=admin, admin-password=DockerWest123!

Create a new database inside the running mysql container with the given name (eg. 'magento2') and 'DEFAULT CHARSET utf8'.

eg.
$ create_db magento2

Execute a mysql command inside the running mysql container as the root user.

eg.
$ mysql "SELECT * FROM table_name;"

Execute the mysqldump command inside the running mysql container as the root user.

eg.
$ mysqldump db_name > export_file_name.sql

Import a given mysql file into a given database, inside the running mysql container as the root user.

eg.
$ mysqlimport db_name import_file_name.sql

Execute the nodejs command inside a nodejs container. The working directory will be the current directory you are executing this command from.

eg.
$ node js_file.js

Execute the npm command inside a nodejs container.

The working directory will be the current directory you are executing this command from. Your $HOME/.ssh and $HOME/.npm folders wil be mounted inside this container to enable you to make use of your ssh keys and npm cache.

eg.
$ npm install package_name

Execute the yarn command inside a nodejs container.

The working directory will be the current directory you are executing this command from. Your $HOME/.ssh and $HOME/.npm folders wil be mounted inside this container to enable you to make use of your ssh keys and npm cache.

eg.
$ yarn add package_name

Execute the redis-cli command in the running redis container.

eg.
$ redis-cli flushall