Dockerfile
is a text document containing all the commands that the docker images need to get built. A docker image gets built by running all the docker command-line instructions mentioned in Dockerfile.
The docker build
command is used to build an image from the Dockerfile
and a context. And, context set of files of any PATH
or URL
.
docker build
Syntax:
$ docker build .
Here, build is run by docker daemon, not by CLI. and (.
) refers to the current directory as build context.
You can also refer to Dockerfile
which is not in the project root directory as:
$ docker build -f /path/to/a/Dockerfile .
You can also use tag -t
for a new image to be tagged, to do so run the following:
$ docker build -t sagar/demoapp .
Format of Dockerfile
:
# Your comment here
INSTRUCTION arguments
Note: Dockerfile
must begin with a FROM
instruction.
FROM Image_Name
# Comment line starts with hash(#) sign
RUN echo 'Hello World'
RUN echo "Hello \\
World"
Here, both RUN
command instructions’ output will be the same.
Output:
Hello World