Docker is a great tool and it is really useful for automating our workflows. I have been using Docker for many years, yet sometimes I find myself forgetting the basic commands.

The scope of these series is to give some really simple examples of how to use Docker. In this article we will dockerise a static website. For those not familiar with the Docker vocabulary, dockerise is when we put some app into a Docker container. Before we start, let’s download and install the docker CLI from the official website.

The static website

Here’s a dead simple website that we are going to dockerise.

    <title>Simple website</title>
    <h1>Hello there</h1>
      I am a simple website and I live inside a Docker container.

Let’s copy that code, open our terminal / code editor and paste it into an index.html file. Now let’s create a Dockerfile.

The Dockerfile

We can now create a new file with the name Dockerfile and add the following code into it.

FROM php:7.0-apache
COPY . /var/www/html/

What we’re doing here is we’re telling the container to install apache. Then the next step is to copy everything from the current directory and put it into /var/www/html/ which is the directory apache will look at for HTML (and not only) files. Now we have everything that we want in order to build our Docker image.

Building the Docker image

We have configured what the Docker image is going to contain so let’s build it.

docker build -t static-website .

The -t flag stands for tag and is a good practice that will simply make our lives so much easier when looking at long lists of Docker images.

The first time we run that command, it is going to take a few seconds or minutes depending on our internet connections. That is because Docker has to download the image we specified in the Dockerfile.

We can see all of the available images with the docker images command. Our command line should look like this.

➜  docker images
REPOSITORY           TAG          IMAGE ID       CREATED              SIZE
static-website       latest       3152d04a164f   About a minute ago   368MB
php                  7.0-apache   aa67a9c9814f   2 years ago          368MB

Now that we have a Docker image for our website, we can spin up some Docker containers.

Powered by Fruition