Working with Dockerfile

Working with Dockerfile

 Working with Dockerfile


Dockerfile is a file used to build images by reading instructions from a file. The default name is used as Dockerfile . You can create dockerfile in the current directory with specific instructions and build a customized image as per your requirements.

Build Image with Dockerfile

As a best practice, the Dockerfile is called Dockerfile and is located in the root of the context. You can use the following command to build a docker image. This will read Dockerfile in the current directory.

$ docker build -t image_name .

You can also use the -f flag with the docker build command to point to a Dockerfile anywhere in your file system.

$ docker build  -t image_name -f /path/to/Dockerfile .

Create a Dockerfile

For this tutorial, I have created a sample project on Github. Just clone the repository using the following command.

$ git clone https://github.com/tecrahul/dockerfile
$ cd dockerfile

Now build the docker image with the name apache image.

$ docker build -t apacheimage .

After the build, You can view the image under the “docker images” command.

Launch Container with Image

Now the time is for creating the instance using the latest image created.

$ docker run -it -p 8080:80 apacheimage

The above command will launch a docker container using the image apache image. Here I have bound host system port 8080 with container port 80, so you can access the Apache running on a container.

Reactions

Post a Comment

0 Comments

close