Running Magento 2 with Docker on OS X

Dockerizing a Magento 2 project on a Mac using Docker Machine
created by on 2016-05-27

I have created a screencast on how to dockerize, run and develop a Magento 2 shop on a Mac using the Docker Toolbox for Mac OS, Docker Machine NFS and arvatoscm/dockerize-magento2.

Running and developing Magento 2 with Docker on your Mac

Part One: Install Docker on OS X

  1. Install Docker Toolbox https://www.docker.com/products/docker-toolbox
  2. Create a docker machine
  docker-machine create -d virtualbox default
  1. Speed up the docker machine with NFS (https://github.com/adlogix/docker-machine-nfs):
  curl -s https://raw.githubusercontent.com/adlogix/docker-machine-nfs/master/docker-machine-nfs.sh |
    sudo tee /usr/local/bin/docker-machine-nfs > /dev/null && \
    sudo chmod +x /usr/local/bin/docker-machine-nfs

  docker-machine-nfs default

Part Two: Create a dockerized Magento 2 project

  1. Create a new magento 2 project
  composer create-project --ignore-platform-reqs --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
  1. Install arvatoscm/dockerize-magento2
  composer require --ignore-platform-reqs arvatoscm/dockerize-magento2

Part Three: Install Magento

  1. Install Magento using bin/console install
  bin/console install <hostname-of-the-shop>
  1. Install sample data using Magento’s standard commands
  bin/console exec sampledata:deploy
  bin/console exec setup:upgrade
  bin/console exec setup:di:compile
  1. Browse the shop

Screenshots

Running Magento 2 with docker on a Mac

Thanks to docker-machine and the docker clients great ability to connect to remote docker daemons you can work on your Mac as if docker ran natively:

Screenshot of the Docker Toolbox website

Magento running in Docker on a Mac

The Magento 2 luma frontend with sample data running in docker on a Mac

The Magento 2 backend running in docker on a Mac

phpMyAdmin

The arvatoscm/dockerize-magento2 includes a phpMyAdmin container:

phpMyAdmin

Composer credentials for repo.magento.com

When you create a Magento 2 project for the first time you will be prompted to enter credentials for repo.magento.com. You can get these credentials from the MyAccount-section of magento.com:

Composer credentials for repo.magento.com in the magento.com account section

NFS for Docker Machine

The default file sharing mechanism of docker machine uses VirtualBox shares which are rather slow. With adlogix/docker-machine-nfs you can make your existing machines a lot faster by enabling NFS:

The GitHub repository of docker-machine-nfs

Dockerize Magento 2

A composer package for dockerizing existing Magento 2 projects is arvatoscm/dockerize-magento2:

The GitHub repository of arvatoscm/dockerize-magento2

Debugging dockerized projects with PHPStorm

You can use PHPStorm just like you would with any “normal” PHP project:

Debugging a dockerized Magento2 in PHPStorm

XDebug configuration for PHPStorm

The only thing that you need to keep in mind is the path mapping for the debug configuration. The php container is effectively a remote server and you must map your project path to the path inside the container:

PHPStorm Debug Configuration - Path mapping for a dockerized Magento 2 project

Shortlink:
Tags: