What are Dockerfile Directives
In our previous tutorial, you learned how to build images with Dockerfile. This tutorial will help you to understand the basic Dockerfile directives and their uses.
FROM
The from directive is used to set the base image for the subsequent instructions. A Dockerfile must have FROM directive with a valid image name as the first instruction.
Examples:
LABEL
Using labels you can organize images in a proper way. this is useful to set maintainer address, vendor name, version of image, release date, etc. The line must begin with the keyword “LABEL”.
You can add multiple labels in a single line with space-separated, or you can define in multiple lines as follows.
RUN
Using RUN directing, you can run any command to image during build time. For example, you can install required packages during the build of the image.
As a more formatted syntax, you can use it as follows.
COPY
The COPY directive is used for copying files and directories from the host system to the image during the build. For example, the first commands will copy all the files from hosts html/ directory /var/www/html image directory. Second command will copy all files with extension .conf to /etc/apache2/sites-available/ directory.
WORKDIR
The WORKDIR directive is used to set the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD commands during the build.
CMD
The CMD directive is used to run the service or software contained by your image, along with any arguments during the launching of the container. CMD uses the following basic syntax
For example, to start Apache service during the launch of the container, Use the following command.
EXPOSE
The EXPOSE directive indicates the ports on which a container will listen for the connections. After that, you can bind the host system port with the container and use them.
ENV
The ENV directive is used to set environment variables for specific services of the container.
VOLUME
The VOLUME directive creates a mount point with the specified name and marks it as holding externally mounted volumes from the native host or other containers.
0 Comments
CAN FEEDBACK
Emoji