‹‹ Go to homepage

Quickstart Magento 2 development (on a Mac)

28 of February, 2016


0. Install and Start Docker

Install Homebrew (if you don’t have it yet)

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Get and start Docker Machine from Docker Toolbox.

brew tap caskroom/cask
brew install brew-cask
brew cask install virtualbox
brew cask install dockertoolbox
docker-machine create --virtualbox default
eval "$(docker-machine env default)"

Setup docker environment into your bash profile.

echo "eval \"\$(docker-machine env default\)\"" >> ~/.bash_profile

1. Setup Magento2 Docker Container

Start with creating empty directory for your project.

mkdir -p ~/Projects/magento2-dev-example
cd ~/Projects/magento2-dev-example

Setup host for access with friendly name

echo "$(docker-machine ip default) magento2-shop.dev" | sudo tee -a /etc/hosts

Run container interactively. You will end up in command line inside of container. Don’t exit it or docker will stop the container.

docker run -it \
  --name magento2-dev-container \
  -p 8080:80 \
  -v $(pwd):/var/www/app/magento2.docker.loc/magento2 \
  asarturas/magento2-docker:latest

2. Install Magento2 Community Edition with test data

Once it starts and you are in command line inside of container - install magento via composer.

NB: you will have to provide your Magento Connect repository username/password.

Use existing credentials or generate new ones at Magento Connect > My Account > Connect > Developers > Secure Keys. Username is your public key, password - a private key. ¯\(ツ)

composer create-project -n magento/community-edition . 2.0.2
bin/magento setup:install \
  --backend-frontname=admin \
  --db-host=localhost \
  --db-name=magento \
  --db-user=root \
  --base-url=http://magento2-shop.dev:8080/ \
  --use-rewrites=1 \
  --admin-user=admin \
  --admin-password=admin123 \
  --admin-email=admin@example.com \
  --admin-firstname=Admin \
  --admin-lastname=Admin \
  --cleanup-database \
  --use-sample-data 
bin/magento deploy:mode:set developer
bin/magento cache:flush
bin/magento indexer:reindex
bin/magento setup:static-content:deploy en_US

3. …

Now in frontend you should see fully functional Magento 2 shop in developer’s mode. At the time of writing there was an issue, where one stylesheet returns 404 because it is called with {{MEDIA_URL}}/styles.css. It seems to be a known issue with no resolution so far, but doesn’t seem to affect functionality of store.

open http://magento2-shop.dev:8080/

4. Profit :-)

To stop container just exit the terminal inside of the container.

exit

To bring dev environment up again just start container with interactive mode again.

docker start -i magento2-dev-container
comments powered by Disqus