Hi Readers, this document explains dockerfile commands.
Dockerfile is a file which has a set of instructions to build a Docker image. Dockerfile made the building of docker images automatically.


Here is the same set of commands which is commonly used in dockerfile.

FROM
MAINTAINER
COPY
ADD
ENV
EXPOSE
USER
WORKDIR
VOLUME
CMD
ENTRYPOINT

Let’s explain all the commands mentioned above.

FROM
FROM refers which base image to use for your docker image.

here is the example,

FROM ubuntu

this downloads the ubuntu image from the docker hub for your docker image.

FROM ubuntu:16

this refers ubuntu image of tag 16 will be used for docker image.

MAINTAINER
This sets the author for the generated image.

Ex:

MAINTAINER techrunnr

COPY
It copies the file or folder from source to the destination of docker image. If the path doesn’t exist it creates all it’s missing directories.

Ex:

COPY main.js /tmp/main.js
COPY sourcecode /root/code

ADD
It copies the file or folder from source to the destination of docker image. If the path doesn’t exist it creates all it’s missing directories.

Ex:

ADD main.js /tmp/main.js
ADD sourcecode /root/code

ENV
It sets environment variable inside the docker image. Environment variable will be available when the docker image is running.

Ex:

ENV backupfolder=/data
ENV backupfolder=/data datafolder=/backupdata

WORKDIR
It sets the working directory in docker image.

Ex:

WORKDIR /tmp
CMD pwd

this will returns the working directory /tmp

EXPOSE
It defines the docker container to listen on the port specified during runtime.

Ex:

EXPOSE 8080
EXPOSE 8081 10025

VOLUME
It defines the folder to mount with docker container during runtime

Ex:

VOLUME /opt/:/usr/src/app

ENTRY POINT

ENTRYPOINT command and parameters will not be overwritten from the command line. Instead, all command line arguments will be added after ENTRYPOINT parameters.

Ex:

ENTRYPOINT ["/bin/echo", "Hello,"]

It will print the following output once the container starts up.

Hello,

CMD

CMD sets default command and/or parameters, which can be overwritten from the command line when docker container runs.

Ex:

CMD node /tmp/main.js

this runs node application once the container starts up.

USER
It instructs the user to use for the next set of commands such as CMD, ENTRYPOINT

Ex:

USER app
CMD node /tmp/main.js

that’s it now you have completed with dockerfile commands!!

Check this link for more understand how I have a build a Docker image using docker file

© 2018, Techrunnr. All rights reserved.

#1
#2
#3
Questions Answered
Articles Written
Overall Points
Categories: devopsdocker

Prabhin Prabharkaran

He is Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!!

0 Comments

Leave a Reply

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.