Your first php application inside a Docker container in 15 Minutes (Part 1)

Part 1. Introduction

I had been wanting to try dry docker out for quite a while now, and had started working on it and abandoned the idea a few times, mainly because of all the bits and pieces of information out there leading many times to conflicting ideas.

Well, last weekend was one of the stormiest weekends we had in years, so I hunkered down and decided to dockerise an existing running project to see how it will work out. This means that the below is not meant to be followed as best practice, but merely to whet your appetite on the technology, and get perhaps get you on your way to adopting it in one or more of your projects, if it fits your needs.

Before we start, let’s take a quick look at what exactly is a docker container. Quoting verbatim from the docker website :

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.”

You might be tempted to think of it as virtual machine, but it really is not. Docker containers share the machine’s OS system kernel and do not actually require an OS to be installed. This also helps with licensing costs. According to the docker website too, “Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry

I will not delve further on what are dockers, since it is beyond the scope of this writeup, besides there are hundreds if not thousands of blog posts out there dealing with this topic. Our main aim is to learn about docker by getting our hands dirty. By the end of this post, we will have a working container, hosting a php application, its database, and an ssh daemon for us to be able to “login” to the container and tinker with stuff.

If you have come this far, I am assuming you are familiar with how php web pages and / or applications work. I am also assuming you are also familiar about how php applications connect and talk to a MySQL database.

Normally when I write a PHP application, I develop it on my laptop using PhpStorm, test it on my local environment, using MAMP PRO and later deploy it onto a Time4VPS linux VPS.

Whilst this setup works quite well after some months of tweaking here and there, once in a while I will come across an issue, which did not show up on the local environment. Most of the time this will be due either to different versions of php / mysql / apache running on the local environment and the server, or due to some quirk specific to one particular environment. Docker will eliminate these issues, because the versions of the components you will be using on the local environments, will be the exact same as they are on the production environment.

That’s really enough blabber, in Part 2 of this blog post, we will create our first working “lamp” container with integrated ssh and dockerise an existing php application.

Leave a reply:

Your email address will not be published.

Site Footer