Create your first simple docker image

Spread the love

In our previous article, we installed nginx in a docker container. That was quite easy. In this article, we are going to increase our skill and build a docker image. We can create a docker image in two ways. We are going to take a look briefly at both ways.

  1. Creating an docker image from Dockerfile (Recommended)
  2. Creating an docker image from existing container

1. Creating an docker image from Dockerfile (Recommended)

A Dockerfile can be use to create a docker image. Dockerfile is a set of instruction that a user could have run inside a container. Remember how we used set of commands to install nginx and php-fpm in our previous post? We can write step-by-step commands in Dockerfile then run docker build command to build an image. Let’s install nginx and create our new image.

– Create a new folder and inside it create a file and call it Dockerfile

– Insert following in the Dockerfile

That’s all, save and quit. Enter following command to see the magic

Here, -t is name and optionally a tag in the ‘name:tag’ format. Since we have not provided any tag, it will automatically set latest tag.

Check the image we have just build.

2. Creating an docker image from existing container

If you have followed previous article, there, we have installed nginx and PHP in a container. We can create an image from the same container that we have made the changes. Here is how

Here, -m is Commit message. Check our newly create image

Awesome, we have successfully created image using two methods.


Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *