Subscribe to PHP Freaks RSS

How to setup PHP, PHP-FPM and NGINX on Docker in Windows 10 [Tutorial Part 1]

syndicated from planet-php.net on July 8, 2018

You probably heard from the new kid around the block called "Docker"? You are a PHP developer and would like to get into that, but you didn't have the time to look into it, yet? Then this tutorial is for you! By the end of it, you should know:

  • how to setup Docker "natively" on a Windows 10 machine
  • how to build and run containers from the command line
  • how to log into containers and explore them for information
  • what a Dockerfile is and how to use it
  • how containers can talk to each other
  • how docker-compose can be used to fit everything nicely together

Note: I will not only walk on the happy path during this tutorial. That means I'll deep-dive into some things that are not completely related to docker (e.g. how to find out where the configuration files for php-fpm are located), but that are imho important to understand, because they enable you to solve problems later on your own.

But if you are short on time, you might also jump directly to the tl;dr.

This is the first part of a (probably) multi-part series on Docker. The next part will explain how to set up PHP in Docker containers in order to work nicely with PHPStorm when using XDebug.

Table of contents

Introduction

Preconditions

I'm assuming that you have installed Git bash for Windows. If not, please do that before, see Setting up the software: Git and Git Bash.

Why use Docker?

I won't go into too much detail what Docker is and why you should use it, because others have already talked about this extensively.

As for me, my main reasons were

  • Symlinks in vagrant didn't work the way they should
  • VMs become bloated and hard to manage over time
  • Setup in the team involved a lot of work
  • I wanted to learn Docker for quite some time because you hear a lot about it

In general, Docker is kind of like a virtual machine, so it allows us to develop in an OS of our choice (e.g. Windows) but run the code in the same environment as it will in production (e.g. on a linux server). Thanks to its core principles, it makes the separation of services really easy (e.g. having a dedicated server for your database) which - again - is something that should happen on production anyway.

Transition from Vagrant

On Windows, you can either use the Docker Toolbox (which is essentially a VM with Docker setup on it) or the Hyper-V based Docker for Windows. This tutorial will only look at the latter.

A word of caution: Unfortunately, we cannot have other Gods besides Docker (on Windows). The native Docker client requires Hyper-V to be activated which in turn will cause Virtualbox to not work any longer. Thus, we will not be able to use Vagrant and Docker alongside each other. This was actually the main reason it took me so long to start working with Docker.

Setup Docker

First,

Truncated by Planet PHP, read more at the original (another 59213 bytes)