From 631c7c9fae009650634cdd8e816162b58c5c5521 Mon Sep 17 00:00:00 2001 From: Michael Scalzetti Date: Mon, 9 Jan 2023 17:12:36 -0500 Subject: [PATCH] Wrote out dockerfile cheat sheet --- blog/src/docker/dockerfile.md | 106 ++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 5 deletions(-) diff --git a/blog/src/docker/dockerfile.md b/blog/src/docker/dockerfile.md index 2d94a0b..92c0aae 100644 --- a/blog/src/docker/dockerfile.md +++ b/blog/src/docker/dockerfile.md @@ -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 +LABEL Author="" +# MAINTAINER +``` + +### 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 +``` ### ADD +Copies files or directories to container's file system + +Usage: +``` +# ADD +COPY +``` +Notes: +- ADD can be buggy, use COPY where you can + +### COPY + +Copies files or directories to container's file system + +Usage: +``` +COPY +``` + +### VOLUME + +Create mount point, marks as holding external mounted items +Usage: +``` +VOLUME ["", "", ...] +``` + ### WORKDIR +Set the current working directory + +Usage: +``` +WORKDIR +``` + ### 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 ["", "", ""] +CMD ["", ""] +CMD +``` +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 ["", "", ""] +ENTRYPOINT +``` +# 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/) +