Docker for Magento 2 Development

Docker for Magento 2 Illustrative Logo

Docker and Magento

In this first post, of which many will follow, we show you how to set up Docker for Magento 2 development. Way back when I first heard of Docker, I was still using WAMP, MAMP, Vagrant, VMWare and anything else I could get my hands on. While there are pros and cons to all of the different virtual machine platforms, there was really nothing that truly satisfied all of my needs. It always seemed as though I would get some of the features I needed at the expense of others. Try as I might, I could never quite find the balance I was looking for. When I first started to hear about Docker, I was intrigued yet skeptical, maybe even intimidated.

Crawl Before You Can Walk

I am not, nor have I ever been, a server or dev ops guy. I am a programmer. One day, when I had some free time, I decided to download and install Docker. Despite all that I had read online, I had quite a bit of trouble figuring out how Docker worked and what it’s capabilities were. I had read mountains of online documentation and followed countless tutorials. Quite literally, I spent several frustrating weeks, at least 8 hours per day, trying to figure out what I was doing and why it wasn’t working. Anyone less stubborn and hard-headed would have abandoned the idea completely. In fact, it’s probably the reason I’m going bald. Fortunately, a light bulb did finally pop on above my head and nowadays I am extremely happy with Docker.

Due to the massive frustration I experienced and the sanity that I lost, I just knew I had to make this the first tutorial that I write. My goal is to condense years of experience into a one-page tutorial so that you can get up and running with your Magento 2 projects and keep your hair!

Update: Spin Up Magento With a Single CLI Command

Setup Docker for Magento 2 Development

To follow this tutorial on YouTube, click here.

Install Docker

The first, and perhaps most obvious, step is to download Docker, install it, and start it up. Docker is available for all major operating systems including, but not limited to, Mac OS X, Windows, Ubuntu, Debian, CentOS, and more. The steps in this tut assume that you are on a Mac. However, the steps are the same or very similar no matter what operating system you are on.

Install Composer

Although there are other ways to install and manage Magento 2, Composer is the preferred way. Composer will allow you to manage and install packages as well as allow you to run additional scripts after each update. Additionally, you may have noticed “uninstall” scripts in some Magento extensions. These scripts only work when the extension or module is managed with Composer.

Download Magento 2

To download the Magento 2 Open Source metapackage, do the following:

  1. Log in or create an account on Magento marketplace. Once logged in, navigate to Access Keys and keep that window open as you will need the keys in step #3.
  2. Determine a location on your local machine where you would like the website files to live.
  3. Open up a command line terminal. Before copying and pasting the code below, replace the placeholder path with the absolute path of where you plan to download/install Magento.
    cd /path/to/where/you/will/download/magento && \
    composer create-project --repository-url= magento/project-community-edition .
  4. The latest version of Magento 2 is now downloaded to your machine. From this point forward, we will refer to the directory where you installed Magento as /path/to/magento.
  5. Increase the PHP memory limit from the default value of 756M to 2048M.
    find . -name '.htaccess' -exec sed -i '' s/756M/2048M/g {} + && \
    find . -name '.htaccess' -exec sed -i '' s/768M/2048M/g {} + && \
    find . -name '.user.ini' -exec sed -i '' s/756M/2048M/g {} + && \
    find . -name '.user.ini' -exec sed -i '' s/768M/2048M/g {} +
  6. Choose a domain name you would like to use to access the site and add it to your hosts file.
    sudo -- sh -c "echo '' >> /etc/hosts"

Create a docker-compose.yml file

  1. Choose a place on your local machine where you will keep your Docker configuration files. We will refer to this location as /path/to/docker.
  2. cd /path/to/docker
  3. Open a new text document in the text editor of your choice.
  4. Copy and past the following code into the new file.
    version: '3'
            image: webdevops/php-apache-dev:ubuntu-16.04
            container_name: web
            restart: always
            user: application
              - WEB_DOCUMENT_ROOT=/app/pub
              - PHP_DATE_TIMEZONE=EST
              - PHP_DISPLAY_ERRORS=1
              - PHP_MEMORY_LIMIT=2048M
              - PHP_MAX_EXECUTION_TIME=300
              - PHP_POST_MAX_SIZE=500M
              - PHP_UPLOAD_MAX_FILESIZE=1024M
              - /path/to/magento:/app:cached
              - "80:80"
              - "443:443"
              - "32823:22"
              - mysql
            image: mariadb:10
            container_name: mysql
            restart: always
              - "3306:3306"
              - MYSQL_ROOT_PASSWORD=root
              - MYSQL_DATABASE=magento
              - db-data:/var/lib/mysql
            container_name: phpmyadmin
            restart: always
            image: phpmyadmin/phpmyadmin:latest
              - MYSQL_ROOT_PASSWORD=root
              - PMA_USER=root
              - PMA_PASSWORD=root
              - "8080:80"
              - mysql:db
              - mysql
            external: false
  5. Replace the domain name on line 8 with the domain you created earlier in this tutorial.
  6. Replace /path/to/magento on line 17 with the absolute path to the Magento files you downloaded earlier. Leave everything after the colon just the way it is.
  7. Save the new file as /path/to/docker/docker-compose.yml

Now We’re Ready to Fire It Up

  1. At this point in time, your terminal should still be open to /path/to/docker.
  2. Fire up your virtual machine! The first time you spin up, Docker needs to download the images, this may take a few minutes. Future spin-ups will only take a few seconds, usually less than 10.
    docker-compose up -d --build
  3. Let’s make sure that it’s up and running as planned. In a web browser, go to and make sure that you can see phpMyAdmin. If you can, it was a success.

Finally, Let’s Install Magento 2!

  1. Access your Docker web container’s command line.
    docker exec -it web bash
  2. Navigate to the web document root.
    cd /app
  3. Optional but recommended: deploy sample data.
    php bin/magento sampledata:deploy
  4. Install Magento 2! Before copying and pasting the command shown below into the Docker terminal, you must replace the values on lines 2-6 with your own details. On lines 7-8, replace the placeholder domain with the domain name you created earlier.
    php bin/magento setup:install \
    --admin-firstname=John \
    --admin-lastname=Doe \ \
    --admin-user=admin \
    --admin-password='SomePassword123' \
    --base-url= \
    --base-url-secure= \
    --backend-frontname=admin \
    --db-host=mysql \
    --db-name=magento \
    --db-user=root \
    --db-password=root \
    --use-rewrites=1 \
    --language=en_US \
    --currency=USD \
    --timezone=America/New_York \
    --use-secure-admin=1 \
    --admin-use-security-key=1 \
    --session-save=files \
  5. In your web browser, visit your website at or whatever domain you chose. The first time you go to access the site, it might take a couple of minutes for the page to load. This is because nothing is cached yet and the Magento system is automatically generating files as the page loads. Subsequent page loads will be faster. Additionally, because the web container uses a self-signed SSL certificate, the browser will likely present you with a security alert the first time you visit the URL. Just follow any prompts to add an exception so that you can proceed to the local website.
  6. Congratulations! You are now running Magento 2 on Docker. Keep in mind, this process is easily repeatable for other projects. While you might have spent a bit of time reading through this tutorial, once you have repeated the process a few times, it should only take you 15 minutes or less to spin up a brand new Magento 2 project.

Helpful Docker Information & Commands

Now that you have your Magento 2 project up and running on a series of Docker containers, I would like to share some useful information and commands with you so that you can get the most out of it.

Docker Info

  • Your database is persistent due to a data volume contained in the docker-compose.yml file. This means that when you tear down the virtual machine and spin it back up at a later date or time, your database will still be intact and ready to go.
  • If you would like to use Sequel Pro or some other tool to connect to the database, it is accessible at The username is root and the password is root. The name of the database is magento.
  • The VM includes phpMyAdmin for your convenience. It can be accessed from a web browser at

Docker Commands

  • Spin Up
    docker-compose up -d --build
  • Tear Down
    docker-compose down
  • Connect to web container CLI
    docker exec -it web bash
  • Connect to database container CLI
    docker exec -it mysql bash

About the Docker Image

We want to be sure to give credit where credit is due. On line 4 of the docker-compose.yml file is a reference to the image we use for the web service. That image is: webdevops/php-apache-dev and the docs regarding the image are located here. While I could have assembled my own custom image through the use of a Dockerfile, WebDevOps has gone through the trouble of creating approximately 20 different Docker images that are absolutely perfect for most projects. So a big thank you to WebDevOps for making these images available to the public!

Also in the Magento 2 Development Environment Series

90 Replies to “Docker for Magento 2 Development”

  1. Seems like everyone and their pet dog is hitting this error:

    Your requirements could not be resolved to an installable set of packages.

    Problem 1
    – Installation request for magento/product-community-edition 2.2.0 -> satisfiable by magento/product-community-edition[2.2.0].
    – magento/product-community-edition 2.2.0 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.
    Problem 2
    – magento/framework 101.0.6 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.

    Any suggestions for iOS? can’t seem to install this with brew.

    1. Try adding the –ignore-platform-reqs flag to your composer install command. What’s happening when you go to install is that composer is checking to see that your computer meets the requirements of the platform. But since Magento will actually be running inside of Docker, the extensions of your host/local computer aren’t relevant. Another alternative is that you can probably just run the composer install command inside of the Docker container. You can connect to the Docker container with “docker exec -it web bash” and then “cd /app” and in the /app dir is where you can run composer install.

  2. Is there a way to tell docker which version of php to run? Looks like it’s running 7.0.32 by default, but needs at least 7.1 for doctrine.

    1. Yes. The Docker image I use comes in many variations which you can see here. However, you can do this easily by following these steps:

      docker-compose down
      In your docker-compose.yml file, update the image tag from webdevops/php-apache-dev:ubuntu-16.04 to webdevops/php-apache-dev:7.1
      docker-compose up -d –build

      After you do that, you should be running 7.1.

      1. i am also getting same problem and when i put 7.2 in docker-compose.yml file and run command : docker-compose up -d –build , then it shows The “/app/var/.regenerate” file can’t be deleted. Warning!unlink(/app/var/.regenerate): Permission denied
        Now i do not know what should i do
        Please help me

        1. Hi Raghav,

          You would want to log in as root and set proper file permissions, For some reason, the files/directories that need to be deleted are not owned by username ‘application’ and group ‘application’.

          Do like this:

          1. docker exdec -it -uroot web bash
          2. cd /app
          3. chown -R application:application ./

          That should fix it for you.

  3. root@7c2017b03029:/app# bin/magento deploy:mode:set developer

    The file “/app/pub/static/adminhtml/Magento/backend/en_US/fonts/admin-icons/admin-icons.woff2” cannot be deleted Warn
    ing!unlink(/app/pub/static/adminhtml/Magento/backend/en_US/fonts/admin-icons/admin-icons.woff2): No such file or dire

    How can i sovle this?

  4. I keep getting this error when running the docker-compose up -d –build command:

    “ERROR: for web Cannot create container for service web: invalid volume specification: ‘/Users/adamdarby/m2-sandbox/app:cached:rw’: invalid mount config for type “bind”: invalid mount path: ‘cached’ mount path must be absolute”

    The line in my yml file is:

    – /Users/adamdarby/m2-sandbox/app:cached

    Any ideas?

  5. The volume doesn’t seem to have write permissions as I keep getting the below mentioned error every time I access Magento.

    Fatal error: Uncaught Magento\Framework\Exception\FileSystemException: Directory “/app/var/page_cache” cannot be created Warning!mkdir(): Permission denied in /app/vendor/magento/framework/Filesystem/Driver/File.php on line 225

    From what I’ve found, the problem seems to be that all the directories inside the volume are owned by root. A container app can only write to these volumes if the app inside the container is also running as root which is said to be not recommended. Please suggest what changes I need to make to fix the permissions issue.


    1. Thanks for letting me know the issue you’re facing. Fortunately, it’s easy to fix. Connect to the web container with docker exec -it web bash and then cd /app && chown -R application:application ./

      As a permanent fix, I am updating the docker-compose.yml file on the blog. Right after line 6, you can add user:application. Then docker-compose down && docker-compose up -d –build

      I hope this helps!

  6. Thanks Shawn for the great tutorial. I followed your tutorial and have 3 docker images on my local. I finished working on a magento site and want to export both the code and database. How do I export this image to either github/ so anyone could download the image and spin it which will generate the 3 images, website and the Database??

  7. This is all well and good but the past 6 months of experience on Mac OS have shown that there are severe issues with docker. The docs here clearly state:

    “There are a number of issues with the performance of directories bind-mounted with osxfs. In particular, writes of small blocks, and traversals of large directories are currently slow. Additionally, containers that perform large numbers of directory operations, such as repeated scans of large directory trees, may suffer from poor performance. Applications that behave in this way include:

    ember build
    Zend Framework
    PHP applications that use Composer to install dependencies in a vendor folder”

    People need to be aware this is the case and it would be very helpful if Adobe/Magento could engage with docker to get these issues sorted.

    1. Hi Andrew, this is something I am fully aware of and it’s not much of an issue in this case. On line 18 of my sample docker-compose.yml file, I used “:cached” which relieves that issue a bit.

  8. Hello Shawn, thanks for the tutorial.
    I have followed all the steps in your youtube video, however when I proceed to ‘install magento’, it stucks at Module ‘Magento_ConfigurableSampleData’.
    I tried to use ‘ bin/magento setup:upgrade’ to check which module causing problem,
    it stucks at the same place ‘Magento_ConfigurableSampleData’ and showing the error:
    Area code not set: Area code must be set before starting a session.
    I have been googling for nights and tried to edit
    nothing seems helping to solve.

    Can you please advice?
    I am trying to install magento 2.3 -develop

    Thanks a lot!

  9. Hi, when trying to run any command once in the web container to do with bin/magento, I get the following error?

    Could not open input file: bin/magento

    However if I run it in the root magento directory, without going through dockers web container, it’ll work fine. I’m also getting the following error when trying to install sample data.

    SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known

    In InstallCommand.php line 264:

    Parameter validation failed

    1. Hi Elliot, if you’ve followed the steps exactly and you’re on a Mac this shouldn’t happen for you. Here’s a couple of hint’s since I don’t know what steps you’ve taken.

      • Run docker inspect web to and look for the mounts section. Make sure your Magento root directory is mounted to the /app directory in your web container
      • When you docker exec -it web bash, you need to cd /app. /app is where the root is. Then you can run php bin/magento all your want
      • When you go to install the sample data, you need to do it from inside of docker. That’s because the webhost is aliased as “mysql” inside of docker. It’s a container link. Your mac doesn’t know “mysql” is the name of your db host. Howerver, you can add the line mysql into your /etc/hosts file on your Mac and it will then know what “mysql” is pointing at.

      I hope this helps. If that doesn’t fix your problem, please run through the steps again. I know they work because I’ve been following my own instructions for years now. You likely just went wrong somewhere along the way.

  10. Thanks for replying so quickly!

    The volumes path in docker-compose.yml is setup as the following /Users/elliothagerty/Documents/WebDevelopment/****/Sites/new-****:/app:cached

    And the mounts is:

    “Mounts”: [
    “Type”: “bind”,
    “Source”: “/Users/elliothagerty/Documents/WebDevelopment/****/Sites/****”,
    “Destination”: “/app”,
    “Mode”: “cached”,
    “RW”: true,
    “Propagation”: “rprivate”

  11. Hello and thank for your guide. It works great!

    The only issue I’m facing is the speed. Because we mount the entire project folder, docker in order to keep everything sync. Even with the cached flag the speed is kinda unacceptable especially when we try to do development .

    For example when i disable the caches to develop something each page refresh takes easily 30 secs or more. My machine is iMac 2017 i7 32 gigs of ram and I gave everything to docker and in the php.ini. So basically my machine is kinda of a beast

    I know it’s a docker for mac issue but is there something you recommend?

    1. Hi Sakis, no doubt you have a powerful machine. However, Docker has it’s own memory limits so it you should check to see what your settings are and adjust if needed. I go with 4 cpus, 6gb ram, and 1gb swap. It doesn’t fly but its not that bad either.

      Additionally, I make sure I am in developer mode with all caches enabled except for full_page and block_html. Additionally, if I am updating layout xml files I also disable the layout cache.

      Another thing I find helpful is Vinai’s cache clean utility. Its a pretty great dev tool you can find here:

      Also, check .htaccess, .user.ini, pub/.htaccess, and pub/.user.ini and ensure that the memory limit is 2048GB.

      If none of this helps, you’ll probably want to profile any custom code or third party extensions as there is likely to be a bottleneck.

      I hope this helps!

  12. hi shawn,
    would you please help me solving this issue on ubuntu, “Could not open input file: bin/magento”
    i have double checked my docker-compose.yml and docker inspect web file, they all are up to mark.

  13. Hi Shawn,

    i am new to Docker and Mac.
    As i understood, i need to add the self-signed certificate to the keychain to create an exception for Chrome. But i can’t figure out where the certificate is located after spinning up the container.
    I would appreciated you help, thanks.

    1. Hi Nic, thanks for checking out my article. You shouldn’t need to do anything with the certificate itself. Chrome and Firefox should both give you a warning but you should be able to click a link and “accept the risk” and then no further action should be required.

      1. Hi,
        thank you for your quick reply.
        I am not even sure anymore if it is really the certificate. While i am trying to get into the backend i always geht a redirection error. I’ll check the tutorial again and hopefully i can find my mistake.

        1. Hi Nic, if youre getting a redirection error in the admin panel, its likely unrelated to the vm itself, maybe something to do with cookies or something. Try to access the admin panel from a different browser and see what happens.

          1. Good afternoon I am loving this tutorial, I have attempted to follow others but this has been incredibly clear. I am running into a problem when attempting to run php bin/mangento sampledate:deply in that I get
            [Magento supports PHP 7.1.3 or later. Please read……]

            Is there any way to get around this as I did with the –ignore-platform-reqs command in composer?

            Please let me know and thanks for putting this out there.

          2. It sounds like you are running your php commands on your computer instead of inside the Docker container. You should connect to the container and run it inside.

  14. Hi Shawn,

    This article too amazing.
    Could you please update more for docker-compose.yml file with Nodejs and Yarn?
    I’m trying to play with PWA at new magento version but can’t made it run.

  15. And when I run the command :”$docker-compose up” –> the message about the web container was : “error: failed switching to “root”: operation not permitted”

  16. Hi shawn,
    Your work is just great!
    I followed your tutorial step by step and everthing went smoothly until the last part where I have installed the magento 2, I have run the php bin/magento setup:install with all the user settings, but I got this error:
    Warning: Use of undefined constant SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13 – assumed ‘SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13’ (this will throw an Error in a future version of PHP) in /app/vendor/magento/fra
    mework/Encryption/Encryptor.php on line 153
    I have tried different things but it is not working…if you let me know what I am doing wrong, will be much appreciated, thanks in advance

    1. Hi Munir,

      You’re not doing anything wrong. I am currently encountering this issue when attempting to use 2.3.2 with PHP 7.2.21. I read somewhere that 7.2.31 or greater is required but I havent tested that yet. I have actually been able to overcome this issue by continuing to use PHP 7.1 with Magento 2.3.2

  17. Hi Shawn,

    thank you for this great tutorial! I’m absolutely new to docker and Magento very greatful for this tutorial!

    I think i have followed your instructions, but i ran into this issue:
    This command:
    “php bin/mangento sampledate:deploy ”
    caused this error message:
    “[Magento supports PHP 7.1.3 or later. Please read……]”
    In general every “php bin/magento” – command inside the docker app caused this error. Then i changed in the docker.yml in line 4: ubuntu-16.04 to ubuntu-18.04. Everything is working now so far.
    Does anybody can explain that? Perhaps this has something have to do with the current Magento version? ( Magento 2.3) When i ran “php -v” inside Docker and with the setting ubuntu-16.4 in the docker.yml, it displayed php version 7.0.X . Now it’s displaying php 7.2 with ubuntu-18.04 in the docker.yml.

    1. Hi Arne,

      The reason that worked is because 18.04 includes a different php version. You can actually specify the image verions as:

      • webdevops/php-apache-dev:7.0
      • webdevops/php-apache-dev:7.1
      • webdevops/php-apache-dev:7.2
      • etc…
      • Those numbers refer to the php version you’d want.

  18. Hi Shawn.

    Really love this series of tutorials and have managed to get the vanilla Magento 2 store up and running. My end goal is to be able to develop an existing M2 store using a local Docker hosted version. I work with the “Git Flow” model am wondering how you might go about building my existing site from a GIT branch inside the Docker container. For example, would it be possible to use your Docker-Compose script to build the application from my GIT branch, rather than from the Magento Repo? The issue I can see with this is that my own Repo only contains the ‘App’ folder and a few other custom bits, including composer.json etc. So in theory I would need to have a process similar to this:

    1. Build basic Vanilla Magento 2 Store in a Docker Container
    2. Check out existing or new branch to Container
    3. Composer Update / Install etc

    Clearly some of this would require manually connecting to the ‘web’ container and running a series of commands. Surely this must be something you have to do on a regular basis, right?

    Any Tips would be very much appreciated.

    1. Hi James, this is not a difficult task actually and something I find myself doing often. It’s a big one to answer in a comment reply but maybe I can do a blog post detailing the steps. Please keep an eye on the blog in the next couple of days to weeks and I will try to get it up there. Thank you!

  19. Hi Shawn….Definitely want to give this a try for my own setup as currently I’ve been trying to run Magento inside of Docker inside a VM using VirtualBox. My question is, can I use this type of setup with Magento 2 Commerce Cloud? I’m a bit of an old school developer in that I generally have never used anything like Docker or anything remotely command line related. I’ve just pretty much gotten thrown into now needing to help build and maintain one of my company’s new divisional websites in Magento 2 Cloud. I’m used to saving files locally and simply just uploading them to my server running it there without needing really any form of “building” the site or even using version control. I’ve been working my way through the Magento 2 Devdocs, and I’m starting to wrap my mind around it. So far your tutorial has made the most sense to me and I’m hoping I can use it for my situation. Thank you for any insight you can provide.

  20. Hello Shawn, could you suggest what is the best way to config container to listen to another local domain from host file for setup of multi website on single Magento 2 installation?

  21. Hi, when I type in my user name and password after entering :composer create-project –repository-url= magento/project-community-edition .

    it spits out —
    Warning from Your Magento authentication keys are invalid. Please double-check your keys in your Marketplace account. For instructions, visit
    Warning from Your Magento authentication keys are invalid. Please double-check your keys in your Marketplace account. For instructions, visit
    Warning from Your Magento authentication keys are invalid. Please double-check your keys in your Marketplace account. For instructions, visit

    Invalid credentials for ‘’, aborting.

    create-project [-s|–stability STABILITY] [–prefer-source] [–prefer-dist] [–repository REPOSITORY] [–repository-url REPOSITORY-URL] [–dev] [–no-dev] [–no-custom-installers] [–no-scripts] [–no-progress] [–no-secure-http] [–keep-vcs] [–remove-vcs] [–no-install] [–ignore-platform-reqs] [–] [] [] []

    I tried creating a new access key and using it as my username but nothing different happens. Any Ideas?

  22. I have a problem, when I create composer project it only creates a folder update/ and for example “.htaccess” is empty.

    Moreover when I run “php bin/magento sampledata:deploy”, it returns me this error: Could not open input file: bin/magento

    Because that folder “bin” doesn’t exist, any idea?

    1. Hi Manuel, if I had to guess, you either didn’t run the composer command or it didnt complete. From the root of your Magento install, run “composer update –ignore-platform-reqs” and let me know how it goes. Thanks!

  23. Hi Shawn,

    Thanks for this great article, it is very useful.

    I installed Magento 2.3.4 with webdevops/php-apache-dev:7.3 as you suggested in a comment, along with mariadb:10.3 and phpmyadmin/phpmyadmin:latest. It works like a charm. My question is, is this production ready? Can I use these same docker containers in a production server? Will it be still secure? Sorry if I’m asking a dumb question.

    Reagrds, MageNoob101


      1. Thanks again Shawn, I will test that container as well and post here if I run into any issues.

        Please keep up the good work. Cheers!

  24. Here’s a weird one. After building the docker container, I verified I could access the DB, no problem. I then proceed to the next step and get the following error when trying to run bin/magento: “Bus error”.

    jschmidt@ELT-2TK0Q72 MINGW64 ~/workspace/magentoce
    $ winpty docker exec -it web bash
    application@a66bb905d1de:/$ cd app
    application@a66bb905d1de:/app$ php bin/magento sampledata:deploy
    Bus error

  25. I got this error after the last step

    php bin/magento setup:install

    SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

    In InstallCommand.php line 264:

    Parameter validation failed

    could you please help

  26. Hi Shawn,

    Thank you for the tutorial.
    I have successfully installed Magento. But when I try to access it via browser I am getting 404 error.
    I tried multiple things, but still, it’s not working. Could you please help me with this issue

  27. Hi Shawn,
    Thanks for a great article. It works well and is very helpful for me.
    However, when creating a local installation on my laptop. If I run the command: “docker-compose stop” and then “docker-compose start” –> the “web” container keeps restarting. And I am not able to exec to it.
    The logs is as below: (I run the command: “docker logs –tail 50 –follow –timestamps web”)
    “2020-06-12T11:18:37.624889000Z [SYSLOG] postfix/postfix-script[17224]: waiting for the Postfix mail system to terminate
    2020-06-12T11:18:37.687507700Z [SYSLOG] postfix/master[267]: terminating on signal 15
    2020-06-12T11:18:37.700250900Z 2020-06-12 11:18:37,697 INFO reaped unknown pid 267
    2020-06-12T11:18:37.700304700Z 2020-06-12 11:18:37,697 INFO reaped unknown pid 269
    2020-06-12T11:18:37.700348000Z 2020-06-12 11:18:37,697 INFO reaped unknown pid 15039
    2020-06-12T11:18:38.727851500Z 2020-06-12 11:18:38,726 INFO stopped: postfixd (exit status 0)
    2020-06-12T11:18:38.735450300Z 2020-06-12 11:18:38,734 INFO stopped: crond (terminated by SIGTERM)
    2020-06-12T11:18:39.847587900Z [Fri Jun 12 11:18:39.846989 2020] [mpm_event:notice] [pid 76:tid 140520706552960] AH00491: caught SIGTERM, shutting down
    2020-06-12T11:18:40.033634200Z 2020-06-12 11:18:40,033 INFO stopped: apached (exit status 0)
    2020-06-12T11:18:40.045627500Z [12-Jun-2020 11:18:40] NOTICE: Terminating …
    2020-06-12T11:18:40.055873300Z [12-Jun-2020 11:18:40] NOTICE: exiting, bye-bye!
    2020-06-12T11:18:41.066367700Z 2020-06-12 11:18:41,058 INFO waiting for php-fpmd, syslogd to die
    2020-06-12T11:18:41.640533400Z 2020-06-12 11:18:41,639 INFO stopped: php-fpmd (exit status 0)
    2020-06-12T11:18:42.704469700Z [SYSLOG] syslog-ng[74]: syslog-ng shutting down; version=’3.19.1′
    2020-06-12T11:18:42.955485100Z 2020-06-12 11:18:42,954 INFO stopped: syslogd (exit status 0)
    2020-06-13T02:14:49.494617200Z error: failed switching to “root”: operation not permitted
    2020-06-13T02:14:51.278653200Z error: failed switching to “root”: operation not permitted
    2020-06-13T02:14:52.553370300Z error: failed switching to “root”: operation not permitted
    2020-06-13T02:14:54.049607300Z error: failed switching to “root”: operation not permitted
    2020-06-13T02:14:56.146541700Z error: failed switching to “root”: operation not permitted
    2020-06-13T02:14:58.785260400Z error: failed switching to “root”: operation not permitted
    2020-06-13T02:15:02.954164800Z error: failed switching to “root”: operation not permitted
    2020-06-13T02:15:10.228003200Z error: failed switching to “root”: operation not permitted
    2020-06-13T02:15:23.753969000Z error: failed switching to “root”: operation not permitted….”
    So please take a look at this and help me.
    Thank you in advance.

  28. Hi,

    I am getting below error while running #4
    SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.

    In InstallCommand.php line 264:

    Parameter validation failed

    I am running this command in my magento folder directly on windows 10, Not from web container

    Could you please help.

    1. Hi Heena, the aliases for the various services, mysql, redis, etc are set up to work within docker so you’d need to run your commands inside of the docker containers.

      However, you may be able to make them work if you run from your local CLI.

      Add this line to your /etc/hosts file: mysql redis

  29. Thanks a lot Shawn for a very simple tutorial. I managed to install Magento 2.3.5 with sample data on my laptop after few errors.
    Did following steps to overcome the errors
    1) Uncommented the php.ini extensions to proceed, and saw your reply later “Try adding the –ignore-platform-reqs flag”. This command would have been easy.
    2) Changed the image: webdevops/php-apache-dev:ubuntu-18.04 as the 2.3.5 requires PHP.7.1 or above and threw error “Magento supports PHP 7.1.3 or later.”

    Although I have a small issue. Without tearing down “docker-compose down”, if I restart my laptop, the docker container services “phpmyadim” and “MySQL” start successfully, but my “web” container status shows “restarting” and shows “error: failed switching to “root”: operation not permitted”.

    If I tear down, restart laptop and spin up, then everything works fine and no history is lost.
    Am I doing something wrong? or this is the way it is suppose to be because of the docker-compose.yml config.

    1. Hi Deepak,

      For 2.3.5, I would recommend using the image webdevops/php-apache-dev:7.3, that’s one I use.

      I regards to the web container restarting constantly after you restart your computer, that seems to be a bug of the image itself. Its been occurring for years. However, if you have everything configured properly you should be able to just docker-compose down && docker-compose up -d and problem solved.

      1. Thanks Shawn for your reply. I will reinstall with webdevops/php-apache-dev:7.3 as you recommended and after restarting computer, it does work with docker-compose down && docker-compose up -d.

  30. Thanks a lot Shawn. Got it working on WSL 2 in Windows 10.
    For those who develop on Windows 10 WSL 2 and use a browser like Chrome installed in Windows rather than WSL 2, the hosts file (Step:6 – “Download Magento 2”) is located at C:\Windows\System32\Drivers\etc\
    Just add this line in that file:
    Or else you will get ERR_NAME_NOT_RESOLVED error in browser. All the other instructions are the same for WSL 2

    Thanks again.

  31. Hello mr. @ShawnAbramson
    For some reasons, i need to change permission for files & folders in app/ . In app/, i run “chown -R application:application ./ or chmod -R 777 ./”, i recieved noctice : “chown: changing ownership of ‘./pub’: Operation not permitted”.
    How to fix it?

  32. Hello, I am new to magento2 & docker and your tutorial is very helpful. I faced few issues however almost i got solution from other queries.

    During last step i.e. setup:install i am facing an issue. Specifically related to “Dotdigitalgroup_Email”. Below is the detailed error:
    Module ‘Dotdigitalgroup_Email’: Installing data… Upgrading data… In Mysql.php line 110: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘imported’ in ‘where clause’, query was: UPDATE email_catal og SET processed = ? WHERE (imported) AND (modified IS NULL OR modified = 0) In Mysql.php line 91: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘imported’ in ‘where clause’

    I tried to disable & remove module before starting next time but failed with the fact that installation is pending.
    What is recommended solution in such cases when specific module schema or setup has an issue which cases entire setup to stop?
    Can we suppress such errors when modules are optional?

    PHP 7.3.21 (host)
    magento 2.3.5

    Feel free for more details & many thanks in advance.

    1. Hi Monil, this is completely unrelated to Docker. Since you’re only on the install step, try deleting the row from the setup_module table that contains “Dotdigitalgroup_Email” and then run the script again.

  33. Thanks a lot Shawn for this tutorial. I have followed all the steps and it works fine with magento installation.
    Can you please share a steps or a article for how to integrate docker with existing magento project, it will be very helpful, i am sure there are many developers who need to integrate docker with existing project.

    Thanks in advance.

    1. Thanks Nayan. That’s not a bad idea. In the meantime, all you really need to do is take the docker-compose.yml file and copy it to the root of your existing project. Open the file and change the domain name inside of it and also the mount path should be updated to point to your project. You could actually just change the volume mount path to be “./:/app:delegated”

  34. –no-install is needed when using composer to download magento, at least for magento 2.4. Otherwise it will attempt to install it and running composer on a Mac with the php bundled with macOS, it will ask for php-intl. Not necessary since you execute the install later in the tutorial with the environment of the docker image with all the necessary php modules.

  35. Hello

    I need to add elasticsearch in same config for magento 2.4, can you please help

    version: ‘3’
    image: webdevops/php-apache-dev:ubuntu-16.04
    container_name: web
    restart: always
    user: application
    – WEB_DOCUMENT_ROOT=/app/pub
    – /path/to/magento:/app:cached
    – “80:80”
    – “443:443”
    – “32823:22”
    – mysql
    image: mariadb:10
    container_name: mysql
    restart: always
    – “3306:3306”
    – MYSQL_DATABASE=magento
    – db-data:/var/lib/mysql
    container_name: phpmyadmin
    restart: always
    image: phpmyadmin/phpmyadmin:latest
    – PMA_USER=root
    – PMA_PASSWORD=root
    – “8080:80”
    – mysql:db
    – mysql
    external: false

  36. Hi Shawn,

    Thanks for the detailed article. I followed along and was able to install m2 locally on my iMac at work eventually. Now that I know that works what would be your suggestion to work with a m2 repo I need to pull down from bitbucket?

    I’d like to use the repo with docker if possible. Or should I just dump the db from the repo and use that with my fresh install? A bit lost what direction to start in.

    1. If you take a look at the web service, look at the volumes section. You probably see “/path/to/project:/app:delegated”. Clone your repo some where else, copy the docker-compose.yml file to the root of that project, and then replace “/path/to/project” with “./”. It would look like this “./:/app:delegated”.

      Import your copy of the database to into the database container. Then update your app/etc/env.php file. Specifically, you will be changing the host for the database to “mysql” and the host for redis to “redis”.

      After that, run php bin/magento app:config:import and then php bin/magento cache:flush config. After that, you should be good.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.