i2tutorials

Docker – File

Docker File

 

As we’ve seen in earlier chapters, Docker hub provides a variety of image files including Centos that you can use to spin up containers.

When we run the Docker images command, we can view the existing images on our system. In the screenshot above, we can see one image: centos

Docker also lets you create your own Docker images using Docker Files. Docker Files are just simple text files with instructions on how to build your images.

How to create a Docker File is explained in the following steps.

Step 1 − Make a Docker File and edit it with vim.

$ vi dockerfile

Step 2 − Create your Docker file.

#This is a sample Image 
FROM ubuntu 
RUN apt-get update 
RUN apt-get install –y nginx 
CMD [“echo”,”Image created”] 

The above file has the following points to note:

Docker File

Step-3: Let’s build the dockerfile using this command

$ docker build . 

Here’s what the dockerfile looks like

We can see the Ubuntu image has been created in the name of none.

 

Exit mobile version