We earn commission when you buy through affiliate links.

This does not influence our reviews or recommendations.Learn more.

With Dockerfile you might create custom Docker images.

dockerfile workflow

Hence, knowing about Dockerfile is essential.

What is Dockerfile?

It is a simple text file with a set of commands or instructions.

These commands/instructions are executed successively to perform actions on the base image to create a new docker image.

Comments Syntax

Commands + Arguments Example

Below is what your workflow will look like.

Now lets look at basic commands.

How to Create a Docker Image with a Dockerfile?

Firstly, lets create a Dockerfile.

Put the below commands/instructions in it and save it.

In this Dockerfile, ubuntu is set as the base image.

Then necessary commands and arguments are mentioned to install MongoDB.

Running a Dockerfile

The following command will create a docker image calledgeekflare_mongodbafter successful execution.

Let us verify if the docker image got created with the namegeekflare_mongodb.

initiate the docker imagegeekflare_mongodbinside a containermongo_container.

Open a new terminal and find out if mongo_container is running.

As you’re free to see, the container created fromgeekflare_mongodbimage is up and running.

I hope this gives you an idea about Dockerfile and its benefits.

You may also check out this documentation onDockerfile best practicesto learn more.