Dockerfile is the text file that builds Docker images. This text file contains particular instructions about the container. To build a Dockerfile, follow the steps below.
Step 1: Create a directory where the user can build the image.
mkdir ~/my_directory cd ~/my_directory touch Dockerfile
mkdircreates the directory and
cdchanges the current directory to
touchcommand in Docker creates the Dockerfile.
Step 2: Add comments in case they are needed. Comments can be added using the
Step 3: The very first line has to begin at the keyword
FROM as it lets Docker know which base image the current image should be based on. In this case, the image is created from the Ubuntu image.
Step 4: Add the command
LABEL to alert Docker to the person who is going to maintain the image. It adds metadata to an image.
LABEL maintainer = "email@example.com"="Abc person"
Step 5: Finally, use the
CMD/ENTRYPOINT commands. The
RUN command runs the specific instructions against the image while the
CMD launches the software required in a container.
RUN apt-get update RUN apt-get install –y nginx CMD ["echo","Image is successfully created"]
In this case, the Ubuntu system is updated and the nginx server is installed onto our Ubuntu image.