Local Development Environment with Docker for PHP
Setting Docker, Portainer, Nginx, PHP and Composer
If you work with different language, tools or technology its really hard some time to manage all these different environments in local machine. Docker is a great tool which give us isolated environment to build our application with required tools and libraries without messing with the host machine. You can package up an application with all of the parts it needs, such as libraries and other dependencies, and run it on any machine which have docker installed without installing a single piece of software. You can use different version of any tools separately without any hassle. So let’s see how can we use docker to setup our development environment to build application with Laravel.
I’m using antergos which is arch-linux based os, so installation instructions step below are for arch-linux distro. If you are on Mac or Windows or any other linux distro visit here for installation instruction.
$ sudo pacman -S docker
To start the docker service (for any linux OS that use systemctl)
$ sudo systemctl start docker.service
To start on system boot
$ sudo systemctl enable docker.service
Portainer is a container which gives a nice ui dashboard to use docker easily. We’ll create and run the portainer container like below
$ sudo docker run -d --name portainer -p 80:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
Above will create a container from portainer image and then run it in background ( -d flag make the container run in background). The command will search for the portainer image in local machine and if it doesn’t find the image then it will pull the image from docker image registry. We’ll run the container in port 9000 so port 9000 should be available, but if you want to use any other port than specify it via the -p flag ( -p 8080:9000 ). Also notice that we have named our container portainer with — name flag. You can name your container whatever you want. When the download is complete we can check that the container is running by $ docker ps command. It’ll show a list of all the running container