This blog provides a short tutorial for absolute beginners
with minimal knowledge of Linux processes. Having recently nailed an
understanding of Docker concepts only as a result configuring various services on
a Virtual Machine and using the ps command which would be challenging for beginner developers who have been used to setting up a minimum stack for development.
An absolute beginner focused on web development may not
initially be aware of Linux processes and the networking.
The easiest method to install Docker if you’re using a
Windows or MAC is to install Docker for Windows or MAC respectively from
docker.com and follow the instructions at docs.docker.com.
Otherwise, if you wish to install on a Linux machine host or
guest (virtual machine) follow the corresponding instructions to download the
To set up a simple LAMP stack in Docker we separate each
component (service) into separate containers.
are run from images. We can think of these as Operating Systems as you can pull
an Ubuntu image. However, in Docker an image can include the services
themselves e.g. pulling a php image.
Data and configurations
can also be stored within an image by using a Dockerfile. That’s not a typo a
Docker configuration file is stored in your project folder for your images
named Dockerfile. As you would have several Dockerfiles each should be stored
in an appropriately named subdirectory of your project.
An image can be the
service but also the configurations can be included in the Dockerfile.
What makes Docker containers reusable is the fact that
configuration files are stored independently as volumes which point the directory
on the host machine to the Docker machine.
If you’re familiar
with Github the process of pulling images to produce containers is the same
from Docker registry (hub.docker.com). Instructions can be found on the pages
of key images. Similarly any customised images can be pushed to your personal
Docker push [dockerhubusername]/[repositoryname]
If the image doesn’t
match your useraccount use the docker tag command:
Docker tag [localname]/[imagename:tag] [dockerhubusername]/[repositoryname]
Note the repository
for the image on Dockerhub does not need to exist as the command will create it
for you on Dockerhub!
Before we look at Dockerfiles lets first introduce the basic
command to run a dockerhub image
Linux Ubuntu container
Docker run -it Ubuntu:16.10
The Docker run command
takes the arguments [repositoryname]:[tag] from registry.hub.docker.com
This command will make 2 steps which are later broken down
when creating your own images and containers.
It will pull the image of the Ubuntu (effectively the OS
image in a VM but on top of that)
Secondly it will run a container from the image using the
basic command the –t option will open a terminal in the container
A –v option identifies the path to files which would be
attached to the service e.g. for a MySQL image you would want to keep your
database files permanently and wouldn’t want to start it everytime you begin
working on your project i.e the separate configuration files and databases.
The most important
point to note is that containers are temporary (the services which you can
start and stop but with some additional commands and configuration thrown in!
Repeat for the rest of the stack by searching for the
appropriate image in the docker registry e.g.
Docker run httpd:2.4
However the PHP repository
on dockerhub includes images with Apache included referenced with apache in the
The next blog in this series will explain how to configure
the networking between containers to complete the set up of the environment.
A useful tutorial for setting up the LAMP stack which I have
used is below. However, if you’re like me you would only feel comfortable once
you understand how the components of a Docker environment interact: