A warm Hello to all the readers!

This is yet another article to understand a new concept of Docker. There is a special file called as Dockerfile.

What is Dockerfile?

Dockerfile is a file that contains instructions to build an image. Instructions are a series of commands that you will otherwise run in running container and then commit it as an image.

Generally dockerfile is kept in a directory that is your current working directory. This directory should contain the files or directories that are to be copied to Docker image when we build it. Though, a dockerfile can reside at any other location as well.

There is defined list of instructions supported by Dockerfile. Following is the entire list.

  • FROM
  • RUN
  • CMD
  • COPY
  • ADD
  • LABEL
  • EXPOSE
  • ENV
  • ENTRYPOINT
  • VOLUME
  • USER
  • WORKDIR
  • ARG
  • ONBUILD
  • STOPSIGNAL
  • HEALTHCHECK
  • SHELL

Example of Dockerfile

Let us write one dockerfile with some routine operations. This will help us to understand meaning of some instructions listed above.

Any dockerfile should begin with FROM instruction. This will initialize our new image from a base image selected with FROM.

FROM ubuntu:bionic

Let us copy one file “hosts” file from current working directory to “/root/hosts” inside Docker.

FROM ubuntu:bionic
COPY hosts /root/hosts

Similar Posts

Error: GraphComment couldn't be load because your settings are invalid. Please visit your admin panel and go to the GraphComment section and enter a valid website URL/ID.