Wrote out dockerfile cheat sheet

This commit is contained in:
Michael Scalzetti 2023-01-09 17:12:36 -05:00
parent acc1814034
commit 631c7c9fae

View File

@ -1,5 +1,10 @@
# Dockerfile Cheat Sheet
"Docker can build images automatically by reading the instructions from a `Dockerfile`. A `Dockerfile` is a text document that contains all the commands a user could call on the command line to assemble an image. This page describes the commands you can use in a `Dockerfile`." - Docker Docs
This is meant to be a quick and dirty reference to help you get started. Reference the docker docs if you need more information, they're linked in the sources below.
## Starting Point
Arguments that dictate what to use as a starting point for the dockerfile
@ -23,25 +28,78 @@ Notes:
Arguments that don't affect how the image builds or container runs, but give information about the image
### MAINTAINER
### MAINTAINER (DEPRECATED)
Allows you to specify an author
Allows you to specify an author - REPLACED with `LABEL Author="foo"`
Usage:
```
MAINTAINER <name>
LABEL Author="<name>"
# MAINTAINER <name>
```
### LABEL
Adds metadata to an image
Usage:
```
LABEL "com.example.vendor"="ACME Incorporated"
LABEL com.example.label-with-value="foo"
LABEL version="1.0"
LABEL description="This text illustrates \
that label-values can span multiple lines."
```
## Setup
### ENV
Specifies environment variables
Usage:
```
ENV <env_var_name> <value>
```
### ADD
Copies files or directories to container's file system
Usage:
```
# ADD <host_src> <container_dest>
COPY <host_src> <container_dest>
```
Notes:
- ADD can be buggy, use COPY where you can
### COPY
Copies files or directories to container's file system
Usage:
```
COPY <host_src> <container_dest>
```
### VOLUME
Create mount point, marks as holding external mounted items
Usage:
```
VOLUME ["<DIR_PATH1>", "<DIR_PATH2>", ...]
```
### WORKDIR
Set the current working directory
Usage:
```
WORKDIR <DIR_PATH>
```
### SHELL
Command to change the shell that RUN uses
@ -72,8 +130,6 @@ Notes:
### CMD
###
@ -81,5 +137,45 @@ Notes:
### EXPOSE
A way of communicating/documenting which image ports should be forwarded when ran as a container
```
EXPOSE 80
# ^ notes that tcp port 80 should be opened
EXPOSE 53/udp
# ^ Specifies udp on port 53
EXPOSE 53/tcp
EXPOSE 53/udp
# ^ Specifies both udp and tcp
```
Notes:
- Doesn't actually open the port, you'll need to add that to the docker-compose file or docker run (-p) command
### CMD
Marks the command to be run automatically when a container starts if none is manually marked at runtime
Usage:
```
CMD ["<executable>", "<arg1>", "<arg2>"]
CMD ["<arg1>", "<arg2>"]
CMD <command> <arg1> <arg2>
```
Notes:
- If you are also using ENTRYPOINT, you can use CMD to specify arguments only
### ENTRYPOINT
Marks the command to be run automatically when a container is run interactively, overrides CMD
Usage:
```
ENTRYPOINT ["<executable>", "<arg1>", "<arg2>"]
ENTRYPOINT <command> <arg1> <arg2>
```
# Sources
- [docs.docker.com](https://docs.docker.com/engine/reference/builder/)
- [kapeli.com](https://kapeli.com/cheat_sheets/Dockerfile.docset/Contents/Resources/Documents/index)
- [dockerlaps.collabnix.com](https://dockerlabs.collabnix.com/docker/cheatsheet/)