Skip to content


landing into docker multistage build

When you browse through official docs of docker or few of the videos on youtube. You will find, a single answers from all, multistage will all reduce the complexity and reduce the docker image size. Yes, that is true. Today, I will be talking about what made me utilize the docker multi stage in my Dockerfile.

How many of you have gone through this? The script or codes that were working last time suddenly crashes the next day. I had a Dockerfile build with alpine as base image. It was working like a charm. After running the same Dockerfile now, It was throwing errors on installing the composer. I know, installing the composer is just one line to add but every effort I put on was into vein. The only option left for me was to add composer separately or use already successfully running composer.

I tried it and was working like a charm again. So initially I deleted the line which was to add composer in my Dockerfile: which was a main culprit. Than added the composer in the first line of the Dockerfile as shown bellow.

FROM composer:1.5.1 AS my_composer

This line will simply add the docker image with composer. I added this because this had the composer installed in alpine os.

Now time to add my real alpine image that I was using and that had the trouble.

FROM alpine:3.8

So now we have a Two FROM here, which is why we call it multistage docker.

Now time to add the composer from first image to the second. Which can be easily done as bellow.

COPY --from=my_composer /usr/bin/composer  /usr/bin/composer

This will copy the /usr/bin/composer from first composer image to the second alpine image. We use –from to specify from where to copy. The first argument is the source and second being the destination.

So I build the image again. It worked flawless. But most of you might have the issue like php not found. This is because the php path is not set in the second image so need to set it. I just added a symlink for the solution as follow.

RUN ls -s /usr/bin/php7  /usr/bin/php

Though, this article does not describe about how to use multistage docker. I hope, putting my real experience might have even helped better to realize when do we really need it. In future I will try to put on some easy materials too, regarding how to add or write multi stage docker file.

Creating a wordpress development environment using docker -compose in 1 minute

Yes it takes no more than 1 minute to setup WordPress  development environment in docker  container. Here we will be using the docker-compose.yml file which can be easily found even in the docker officials  documentations. And we will run the simple docker-compose command to run the service and run the WordPress.

Prerequisites :

Basic knowledge and understanding of  docker and docker-compose.

Here is the link to from where I got the contents for docker-compose file . I  have added few descriptions to these docker-compose for someone who might be unfamiliar with it.

docker compose file for wordpress

We are  using two  images here

  1. WordPress image : Behind the scene its maintaining php and web servers required. And using these image you don’t even have to bother about it.
  2. MYSQL image: The mysql image is used for the database.

What is done with docker-compose can also be done by creating your own Dockerfile or by running both service and than linking them but that is more time consuming and becomes frustrating when the number of containers to run grows .With docker-compose everything becomes easy . The best part I like being linking the multiple container together with ease.

How is the 2 containers linked here:

As the service  WordPress is dependent on database service db. You can see a line with  depends_on and with the service name allocated ,which is responsible for linking the two services  we have  together.

Command used to start containers:

As it has the docker compose  file we  will be using the docker-compose command to start the services.

docker compose up -d 

These command will run the two service and -d for running it in the background.

Here is the short video on how I ran the services