A Magento Development Environment Made of Docker Containers

Overview

Docker for Magento 1 Extension Development

Tl;dr How do I use this?

  1. Clone it.
  2. Type docker-compose up -d.
  3. Install a Magento
  4. Mount your file share.
  5. Develop
  6. Profit!!!

How should we build this?

Normally with Magento you get a plain LAMP stack; Apache with mod_php. That's fine, but since Docker containers are so nicely isolated, I want this approach:

 ---------------------       -------------       -------
| HTTPD/FastCGI Proxy | <-> | FastCGI PHP | <-> | MySQL |
 ---------------------       -------------       -------
                                    \               /
              ------------       -----------------------
             | File Share | <-> | Data Volume Container |
              ------------       -----------------------

Separating the HTTP server from the PHP process gives us a more true-to-form web architecture where the web application server is distinct from the web server. It means we can scale and reconfigure the different server layers independently. It means we can destroy or replace a component without destroying the other containers or their data.

What do we need to get started?

  1. A container for the HTTPD. We'll build from nginx and try to configure it for FastCGI.
  2. A container for MySQL. mysql:5 should do.
  3. A container for PHP. We'll use the official Docker PHP images with additional extensions Magento requires.
  4. A container for data volumes. The simplest docker container needs a no-op executable like true and some files. We'll start from scratch and add on from there.
  5. A container for humans to touch data volumes.

How do we set it up?

Docker has a nice tool for orchestrating multiple containers for dev environments called Compose. I defined a docker-compose file that builds and connects the aforementioned containers from its Dockerfile in each of the directories named after the service: nginx, php, mysql, data, fs. So just run docker-compose up.

How should I access the web server?

In Docker, the exposed ports run on the Docker host. If you're using boot2docker, you can get the ip with boot2docker ip. The included browse command should be a shortcut for OS X users.

How do I get to my data?

How Docker actually houses live data is a little confusing, particularly if you're viewing it from a workstation instead of the Docker daemon host, where the volume actually resides. It might help to review Docker's own documentation on the subject. Anyway, the tl;dr version is that's what the file share container is for.

How do I use the file share container?

The file share container creates a CIFS share for the Magento directory.

OS X

mkdir -p <mountpoint>
mount_smbfs -N //guest@<docker host ip>/magento_data_1 <mountpoint>

Windows

net use 
   
    : \\guest@
    
     \magento_data_1

    
   

Linux

Similar to the OS X one, probably uses mount -t cifs. I didn't try it. Alternatively, you can run docker directly on the linux machine and access its volumes directly.

(The above commands assume the file share container name is magento_data_1. That will be true if you work in a directory named magento. For how to make this work with other directory names, see my note on container names over at the tools README.)

Known issues

  • Speed: The CIFS share is a little slow. I tried to set up an NFS share, but couldn't get it working. Taking pull requests for faster shares.
  • Disappearing data: Don't panic - if you try something like docker cp or docker export on the data container it will appear unchanged. The data is safe (in fact, the data is still on the host machine even if you delete the container, as long as you don't docker rm -v it.) Try something like
docker run --volumes-from magento_data_1 debian tar x /srv/magento > export.tar

to get a snapshot of your data. (Although it might be easier just to use the share.)

Comments
  • followed the tl;dr and got an error

    followed the tl;dr and got an error

    Environment is ubuntu 14 lts

    Cannot start container 3fd93bcca858ad03a1c33a196efea29575fa84fa24a40058284ee5e3e7644919: [8] System error: exec: "/usr/sbin/php5-fpm": stat /usr/sbin/php5-fpm: no such file or directory

    opened by javaknight 6
  • Documentation...

    Documentation...

    I am new to docker, and have setup multiple projects. I got the app stack running and see the basic html file that shows me it works.

    However, I have not been able to follow to magento tools documentation to get everything up and working. Could be just me, but maybe check through and let me know if you update this documentation at all. I'd like to try again as this is a great project!

    opened by brandontamm 2
  • Work around docker-compose bug #919 (missing /bin/echo)

    Work around docker-compose bug #919 (missing /bin/echo)

    I am not sure if this is a proper workaround, but it looks like it works for me.

    I was unable to restart data only container after it was started once. I got the following error:

    (M=71433 *1 ?3) az@ares p4 ~/docker-magento> docker-compose up
    Recreating dockermagento_data_1...
    Cannot start container dad3c1c01745482fd28bea85accfca4d5110036e32b85dd2b286d0c0e5b472eb: [8] System error: exec: "/bin/echo": stat /bin/echo: no such file or directory
    

    But with this fix, it works now.

    The original docker-compose bug: https://github.com/docker/compose/issues/919

    opened by overlordtm 1
  • The PHP container does not listen on 9001

    The PHP container does not listen on 9001

    Seems like there are two configurations for php-fpm, and wrong one is read.

    You can see in logs that nginx cannot connect to upstream:

    connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.42.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fa
    stcgi://172.17.0.18:9001", host: "localhost"
    

    Configurations available in PHP container:

    /usr/local/etc/php-fpm.conf
    /etc/php5/fpm/php-fpm.conf
    

    Second one is the right one, but first one is read by default. Following command fixes it.

    php-fpm -y /etc/php5/fpm/php-fpm.conf

    opened by overlordtm 1
  • Example has 'magento-data-1' hardcoded

    Example has 'magento-data-1' hardcoded

    In the example where to mount a volume, it says; mkdir -p <mountpoint> && mount_smbfs -N //guest@<docker host ip>/magento_data_1 <mountpoint>

    It has 'magento_data_1' in the line, which leads me to believe that the directory you were working in was called 'magento' and Fig has used that as a prefix to '_data_1'. This might differ for other users.

    opened by peterjaap 1
  • How to reach Magento install?

    How to reach Magento install?

    I had no idea how to reach the Magento install (new to Docker) but I figured it out, running 'boot2docker ip' gave me the IP where nginx was running. Maybe an idea to include this in the README?

    opened by peterjaap 1
  • Example docker command line to install magento fails when run from repo clone

    Example docker command line to install magento fails when run from repo clone

    If you follow the instructions in the main README you will clone into a directory called docker-magento. If you run the fig up command without setting the FIG_PROJECT_NAME environment variable, fig will create containers with the string dockermagento prepended to the name (ex.: dockermagento_db_1). The sample command line to install magento given in the README file will use the current directory docker-magento as the prefix to the container names and the command will fail.

    The problem is that fig strips anything that isn't a letter or digit from the prefix so we just have to be careful what directory we run fig from or what we set FIG_PROJECT_NAME to.

    opened by ChrisKemmerer 0
  • Cannot browse on Mac OS X using Docker Quickstart Terminal

    Cannot browse on Mac OS X using Docker Quickstart Terminal

    Hello,

    thanks for your great work here!

    I have cloned your repo on my Mac OS X, then I have run "docker-compose up -d" everything seems working well, pulling the images and run container using these images.

    However when I browse into http://192.168.99.100 (IP given from Docker Quickstart Terminal), looks like it doesn't find the server.

    opened by ankermarco 0
  • PHP modules (ioncube loader)

    PHP modules (ioncube loader)

    Just a non-priority feature request:

    Would be great to have the ability to specify extra php modules.

    Specifically, many premium extensions use ioncube loader.

    opened by tatemz 1
  • Fix jpeg thumbnail creation

    Fix jpeg thumbnail creation

    Hey,

    Took me quite some time to figure out why thumbnails were not displayed when I run magento from docker. It seems that when installing php extensions via docker-php-ext-install gd it is not configured same way as when running apt-get php5-gd. I have added libjpeg62-turbo-dev to php container and configured gd to use it. Now even when cleaning cache, thumbnails are generated again :)

    Source of fix: https://hub.docker.com/_/php/

    opened by overlordtm 0
  • [WIP] Add Working PHPBrew Docker File

    [WIP] Add Working PHPBrew Docker File

    Create working apache Image that uses PHP Brew to facilitate working with multiple versions. The image size is quite large, in part, because there are two instances of php installed. Will have to play around some more to get rid of unecessary garbage.

    opened by mrphang 1
  • Different PHP versions

    Different PHP versions

    I would like to get different versions of PHP by creating different tags of the tools and php services. I hit snags with Debian's built-in support for various versions, but will try this again later if nobody picks this up.

    enhancement 
    opened by kojiromike 7
Releases(v0.10.0)
  • v0.10.0(Nov 3, 2014)

    • Enable Remote Debugging with XDebug
    • Don't Require MAGENTO_HOST to Install Magento
    • Reorder Tools Dockerfile to Make Change Easier
    • Add APC
    • Fix Filesystem Permissions when Installing Magento
    • Automatically Determine FIG_PROJECT_NAME in README
    • Support Installing with Magento Sample Data
    • Add MySQL to Tools
    • Rename Init to Tools
    • Add Xsl to PHP Dependencies
    Source code(tar.gz)
    Source code(zip)
Owner
Michael A. Smith
Developer, Architect, Ops, Python, Docker, Bash Principal Engineer at http://www.syapse.com. Opinions are my own; facts are everyone's.
Michael A. Smith
A complete stack for running Symfony 5 into Docker containers using docker-compose tool and with Certbot for the HTTPS certificate.

?? Docker + PHP 7.4 + MySQL8.0 + Nginx + Certbot(HTTPS) + Symfony 5 Boilerplate ?? Edited from https://github.com/ger86/symfony-docker version -> http

null 6 Nov 9, 2022
Mage2click toolset to create and manage the Magento Docker development environment with mutagen.io file-sync for macOS and native filesystem mounts on Linux.

Mage2click - Magento Docker Toolset Mage2click toolset is a system-wide command-line tool for creating and managing simultaneously running Magento Doc

Mage2click 69 Nov 28, 2022
OSX/Linux Docker containers installer for Magento 2

Magento 2 OSX/Linux Docker Requirements MacOS: Docker, docker-sync, Git Linux: Docker, Docker-compose, Git on Debian based OS (Example: Ubuntu, Linux

Osiozekhai Aliu 54 Dec 10, 2022
Docker-magento - Docker image for Magento 1.6 to 1.9

Docker image for Magento 1.x This repo creates a Docker image for Magento 1.x. Please note The primary goal of this repo is to create Docker images fo

Fu Cheng 144 Nov 18, 2022
Full PHP development environment for Docker.

Full PHP development environment based on Docker. Use Docker First - Learn About It Later! Join Us Awesome People Laradock is an MIT-licensed open sou

laradock 11.7k Jan 7, 2023
Easily install PHP extension in Docker containers

Easy installation of PHP extensions in official PHP Docker images This repository contains a script that can be used to easily install a PHP extension

Michele Locati 2.8k Jan 4, 2023
Main ABRouter product repository that contains docker-compose file and orchestrates the project containers.

ABRouter-Compose ?? ABRouter is the open-source tool to perform and track A/B tests which is also known as the experiments. Additionally, feature flag

ABRouter 29 Dec 22, 2022
A dockerized magento 2 community environment ready for development or production.

Painless Magento 2 & 1 A dockerized magento 2 community environment ready for development or production. It supports magento 1.9.x for development Ins

Cocoa Web Studio 10 Apr 23, 2022
🐋 This project aims to broaden knowledge of system administration by using Docker: virtualizing several Docker images, creating them in a new personal virtual machine.

?? This project aims to broaden knowledge of system administration by using Docker: virtualizing several Docker images, creating them in a new personal virtual machine.

Anton Kliek 1 Jan 26, 2022
Phpcs-magento-rules - A set of PHPCS rules used by made.com when hacking Magento

Made.com PHPCS Magento Rules A set of PHPCS rules used by made.com when hacking Magento. Pre-Requisites PHPCS Installation Short Version Clone this re

Made.com Tech Team 26 Jun 3, 2020
Nuber is an open source container management platform it provides a front end to manage your own cloud infrastructure, using Linux Containers virtualization technology

Nuber is an open source container management platform it provides a front end to manage your own cloud infrastructure, using Linux Containers virtualization technology

null 33 Dec 14, 2022
This package provides a set of factories to be used with containers using the PSR-11 standard for an easy Doctrine integration in a project

psr-container-doctrine: Doctrine Factories for PSR-11 Containers Doctrine factories for PSR-11 containers. This package provides a set of factories to

Roave, LLC 84 Dec 14, 2022
A simple shell script which loads a magento environment

A simple shell script to load up a Magento environment and execute PHP code Very experimental and should only be ran on dev servers REQUIRES php pcntl

beeplogic 28 Feb 4, 2022
Enables developers to modify Magento installations (configuration, data) based on the given environment using n98-magerun.

Enables developers to modify Magento installations (configuration, data) based on the given environment using n98-magerun.

LimeSoda Interactive Marketing GmbH 73 Apr 1, 2022
A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2

Simple Import / Export tool A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2. Table data

EcomDev B.V. 51 Dec 5, 2022
Production ready scalable Magento setup utilizing the docker

Magento docker image Requirements This docker image expects 2 other linked containers to work . Mysqldb or Mariadb linked as 'db' Memcached linked as

Paim pozhil 49 Jun 21, 2021
Mark Shust's Docker Configuration for Magento

markshust/docker-magento Mark Shust's Docker Configuration for Magento Table of contents Docker Hub Free Course Usage Prerequisites Setup Updates Cust

Mark Shust 1.8k Jan 8, 2023