Last active
October 26, 2020 04:52
-
-
Save jainxy/5b68352173611b0f776407d3943b4f81 to your computer and use it in GitHub Desktop.
Description of various commands available for usage in the dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
References - | |
1. https://www.howtoforge.com/tutorial/how-to-create-docker-images-with-dockerfile/ | |
2. https://takacsmark.com/dockerfile-tutorial-by-example-dockerfile-best-practices-2018/ | |
3. https://docs.docker.com/engine/reference/builder/ | |
Notes - | |
- A script or receipe having collection of commands and instructions, which will be executed in sequence, to build a new docker image. | |
- Below are some Dockerfile commands and their usage. | |
1. FROM | |
- Base docker image to build new image on top. This is 1st command in the Dockerfile. E.g. dockerized ubuntu image. | |
2. MAINTAINER | |
- Contains name, email of maintainer of the image. Name <email> | |
3. RUN | |
- To execute shell command during image building process. | |
- Runs in new layer and creates new image. Used mostly for installing packages. | |
4. ADD | |
- Copy files or directories from host machine to the docker image. | |
- A URL for file can be passed instead of Host path, which will be downloaded to destination directory. | |
- It also allows to exract local tar file into destination path. | |
5. ENV | |
- Define shell environment variable. TODO: are they visible only in entrypoint shell or persisted across the Image? | |
6. CMD | |
- Shell command to be executed when a new container is built from this image. | |
- It is generally the last command in the dockerfile. | |
- It can be overridden using command given in the docker-run. | |
7. ENTRYPOINT | |
- It configures the command to run container as executable. | |
- This along with corresponding parameters are not ignored when docker-run is given command line parameters. | |
- Default is '/bin/sh -c' | |
8. WORKDIR | |
- It sets the working directory for RUN, CMD, ENTRYPOINT, COPY, ADD instructions. | |
9. USER | |
- Set the default user or UID for the container created with the image. | |
10. VOLUME | |
- Add acess/linked directory between the container and the host machine. | |
11. EXPOSE | |
- Tells docker that container listens on specified network ports at runtime and with which protocol. | |
- Default protocol is TCP. | |
- It doesn't actually publish the ports, but tells which ports are intended to be run. | |
- Ports are actually published with '-p <>:<>' in the docker-run command. | |
12. COPY | |
- Similar to ADD, except that remote file URLs are not allowed. | |
- Best practices recommend to use COPY instead of ADD. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment