<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by diakingdev on Medium]]></title>
        <description><![CDATA[Stories by diakingdev on Medium]]></description>
        <link>https://medium.com/@diakingdev?source=rss-f7d7bb3c7789------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*92mgcBW6iE6Y8WMM.</url>
            <title>Stories by diakingdev on Medium</title>
            <link>https://medium.com/@diakingdev?source=rss-f7d7bb3c7789------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 20:45:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@diakingdev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Dockerfile reference]]></title>
            <link>https://diakingdev.medium.com/dockerfile-reference-da3fd7540b72?source=rss-f7d7bb3c7789------2</link>
            <guid isPermaLink="false">https://medium.com/p/da3fd7540b72</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[diakingdev]]></dc:creator>
            <pubDate>Thu, 03 Aug 2023 07:51:17 GMT</pubDate>
            <atom:updated>2023-08-03T07:51:17.658Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MDI4O4VBJOmBuuYNBEVqcQ.png" /></figure><h3>Dockerfile reference</h3><p>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.</p><h3>Format</h3><p>Here is the format of the Dockerfile:</p><pre># Comment<br>INSTRUCTION arguments</pre><p>The instruction is not case-sensitive. However, convention is for them to be UPPERCASE to distinguish them from arguments more easily.</p><p>Docker runs instructions in a Dockerfile in order. A Dockerfile <strong>must begin with a </strong><strong>FROM instruction</strong>. This may be after <a href="https://docs.docker.com/engine/reference/builder/#parser-directives">parser directives</a>, <a href="https://docs.docker.com/engine/reference/builder/#format">comments</a>, and globally scoped <a href="https://docs.docker.com/engine/reference/builder/#arg">ARGs</a>. The FROM instruction specifies the <a href="https://docs.docker.com/glossary/#parent-image"><em>Parent Image</em></a> from which you are building. FROM may only be preceded by one or more ARG instructions, which declare arguments that are used in FROM lines in the Dockerfile.</p><p>Docker treats lines that <em>begin</em> with # as a comment, unless the line is a valid <a href="https://docs.docker.com/engine/reference/builder/#parser-directives">parser directive</a>. A # marker anywhere else in a line is treated as an argument. This allows statements like:</p><pre># Comment<br>RUN echo &#39;we are running some # of cool things&#39;</pre><p>Comment lines are removed before the Dockerfile instructions are executed, which means that the comment in the following example is not handled by the shell executing the echo command, and both examples below are equivalent:</p><pre>RUN echo hello \<br># comment<br>world</pre><pre>RUN echo hello \<br>world</pre><p>Line continuation characters are not supported in comments.</p><blockquote><strong><em>Note on whitespace</em></strong></blockquote><blockquote><em>For backward compatibility, leading whitespace before comments (</em><em>#) and instructions (such as </em><em>RUN) are ignored, but discouraged. Leading whitespace is not preserved in these cases, and the following examples are therefore equivalent:</em></blockquote><blockquote><em># this is a comment-line RUN echo hello RUN echo world</em></blockquote><blockquote><em># this is a comment-line RUN echo hello RUN echo world</em></blockquote><blockquote><em>Note however, that whitespace in instruction </em>arguments<em>, such as the commands following </em><em>RUN, are preserved, so the following example prints ` hello world` with leading whitespace as specified:</em></blockquote><blockquote><em>RUN echo &quot;\ hello\ world&quot;</em></blockquote><h3>Parser directives</h3><p>Parser directives are optional, and affect the way in which subsequent lines in a Dockerfile are handled. Parser directives do not add layers to the build, and will not be shown as a build step. Parser directives are written as a special type of comment in the form # directive=value. A single directive may only be used once.</p><p>Once a comment, empty line or builder instruction has been processed, Docker no longer looks for parser directives. Instead it treats anything formatted as a parser directive as a comment and does not attempt to validate if it might be a parser directive. Therefore, all parser directives must be at the very top of a Dockerfile.</p><p>Parser directives are not case-sensitive. However, convention is for them to be lowercase. Convention is also to include a blank line following any parser directives. Line continuation characters are not supported in parser directives.</p><p>Due to these rules, the following examples are all invalid:</p><p>Invalid due to line continuation:</p><pre># direc \<br>tive=value</pre><p>Invalid due to appearing twice:</p><pre># directive=value1<br># directive=value2</pre><pre>FROM ImageName</pre><p>Treated as a comment due to appearing after a builder instruction:</p><pre>FROM ImageName<br># directive=value</pre><p>Treated as a comment due to appearing after a comment which is not a parser directive:</p><pre># About my dockerfile<br># directive=value<br>FROM ImageName</pre><p>The unknown directive is treated as a comment due to not being recognized. In addition, the known directive is treated as a comment due to appearing after a comment which is not a parser directive.</p><pre># unknowndirective=value<br># knowndirective=value</pre><p>Non line-breaking whitespace is permitted in a parser directive. Hence, the following lines are all treated identically:</p><pre>#directive=value<br># directive =value<br>#	directive= value<br># directive = value<br>#	  dIrEcTiVe=value</pre><p>The following parser directives are supported:</p><ul><li>syntax</li><li>escape</li></ul><h3>syntax</h3><p>This feature is only available when using the <a href="https://docs.docker.com/build/buildkit/">BuildKit</a> backend, and is ignored when using the classic builder backend.</p><p>See <a href="https://docs.docker.com/build/buildkit/dockerfile-frontend/">Custom Dockerfile syntax</a> page for more information.</p><h3>escape</h3><pre># escape=\ (backslash)</pre><p>Or</p><pre># escape=` (backtick)</pre><p>The escape directive sets the character used to escape characters in a Dockerfile. If not specified, the default escape character is \.</p><p>The escape character is used both to escape characters in a line, and to escape a newline. This allows a Dockerfile instruction to span multiple lines. Note that regardless of whether the escape parser directive is included in a Dockerfile, <em>escaping is not performed in a </em><em>RUN command, except at the end of a line.</em></p><p>Setting the escape character to ` is especially useful on Windows, where \ is the directory path separator. ` is consistent with <a href="https://technet.microsoft.com/en-us/library/hh847755.aspx">Windows PowerShell</a>.</p><p>Consider the following example which would fail in a non-obvious way on Windows. The second \ at the end of the second line would be interpreted as an escape for the newline, instead of a target of the escape from the first \. Similarly, the \ at the end of the third line would, assuming it was actually handled as an instruction, cause it be treated as a line continuation. The result of this dockerfile is that second and third lines are considered a single instruction:</p><pre>FROM microsoft/nanoserver<br>COPY testfile.txt c:\\<br>RUN dir c:\</pre><p>Results in:</p><pre>PS E:\myproject&gt; docker build -t cmd .</pre><pre>Sending build context to Docker daemon 3.072 kB<br>Step 1/2 : FROM microsoft/nanoserver<br> ---&gt; 22738ff49c6d<br>Step 2/2 : COPY testfile.txt c:\RUN dir c:<br>GetFileAttributesEx c:RUN: The system cannot find the file specified.<br>PS E:\myproject&gt;</pre><p>One solution to the above would be to use / as the target of both the COPY instruction, and dir. However, this syntax is, at best, confusing as it is not natural for paths on Windows, and at worst, error prone as not all commands on Windows support / as the path separator.</p><p>By adding the escape parser directive, the following Dockerfile succeeds as expected with the use of natural platform semantics for file paths on Windows:</p><pre># escape=`</pre><pre>FROM microsoft/nanoserver<br>COPY testfile.txt c:\<br>RUN dir c:\</pre><p>Results in:</p><pre>PS E:\myproject&gt; docker build -t succeeds --no-cache=true .</pre><pre>Sending build context to Docker daemon 3.072 kB<br>Step 1/3 : FROM microsoft/nanoserver<br> ---&gt; 22738ff49c6d<br>Step 2/3 : COPY testfile.txt c:\<br> ---&gt; 96655de338de<br>Removing intermediate container 4db9acbb1682<br>Step 3/3 : RUN dir c:\<br> ---&gt; Running in a2c157f842f5<br> Volume in drive C has no label.<br> Volume Serial Number is 7E6D-E0F7</pre><pre> Directory of c:\</pre><pre>10/05/2016  05:04 PM             1,894 License.txt<br>10/05/2016  02:22 PM    &lt;DIR&gt;          Program Files<br>10/05/2016  02:14 PM    &lt;DIR&gt;          Program Files (x86)<br>10/28/2016  11:18 AM                62 testfile.txt<br>10/28/2016  11:20 AM    &lt;DIR&gt;          Users<br>10/28/2016  11:20 AM    &lt;DIR&gt;          Windows<br>           2 File(s)          1,956 bytes<br>           4 Dir(s)  21,259,096,064 bytes free<br> ---&gt; 01c7f3bef04f<br>Removing intermediate container a2c157f842f5<br>Successfully built 01c7f3bef04f<br>PS E:\myproject&gt;</pre><h3>Environment replacement</h3><p>Environment variables (declared with <a href="https://docs.docker.com/engine/reference/builder/#env">the </a><a href="https://docs.docker.com/engine/reference/builder/#env">ENV statement</a>) can also be used in certain instructions as variables to be interpreted by the Dockerfile. Escapes are also handled for including variable-like syntax into a statement literally.</p><p>Environment variables are notated in the Dockerfile either with $variable_name or ${variable_name}. They are treated equivalently and the brace syntax is typically used to address issues with variable names with no whitespace, like ${foo}_bar.</p><p>The ${variable_name} syntax also supports a few of the standard bash modifiers as specified below:</p><ul><li>${variable:-word} indicates that if variable is set then the result will be that value. If variable is not set then word will be the result.</li><li>${variable:+word} indicates that if variable is set then word will be the result, otherwise the result is the empty string.</li></ul><p>In all cases, word can be any string, including additional environment variables.</p><p>Escaping is possible by adding a \ before the variable: \$foo or \${foo}, for example, will translate to $foo and ${foo} literals respectively.</p><p>Example (parsed representation is displayed after the #):</p><pre>FROM busybox<br>ENV FOO=/bar<br>WORKDIR ${FOO}   # WORKDIR /bar<br>ADD . $FOO       # ADD . /bar<br>COPY \$FOO /quux # COPY $FOO /quux</pre><p>Environment variables are supported by the following list of instructions in the Dockerfile:</p><ul><li>ADD</li><li>COPY</li><li>ENV</li><li>EXPOSE</li><li>FROM</li><li>LABEL</li><li>STOPSIGNAL</li><li>USER</li><li>VOLUME</li><li>WORKDIR</li><li>ONBUILD (when combined with one of the supported instructions above)</li></ul><p>Environment variable substitution will use the same value for each variable throughout the entire instruction. In other words, in this example:</p><pre>ENV abc=hello<br>ENV abc=bye def=$abc<br>ENV ghi=$abc</pre><p>will result in def having a value of hello, not bye. However, ghi will have a value of bye because it is not part of the same instruction that set abc to bye.</p><h3>.dockerignore file</h3><p>Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context. If this file exists, the CLI modifies the context to exclude files and directories that match patterns in it. This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon and potentially adding them to images using ADD or COPY.</p><p>The CLI interprets the .dockerignore file as a newline-separated list of patterns similar to the file globs of Unix shells. For the purposes of matching, the root of the context is considered to be both the working and the root directory. For example, the patterns /foo/bar and foo/bar both exclude a file or directory named bar in the foo subdirectory of PATH or in the root of the git repository located at URL. Neither excludes anything else.</p><p>If a line in .dockerignore file starts with # in column 1, then this line is considered as a comment and is ignored before interpreted by the CLI.</p><p>Here is an example .dockerignore file:</p><pre># comment<br>*/temp*<br>*/*/temp*<br>temp?</pre><p>This file causes the following build behavior:</p><p>RuleBehavior# commentIgnored.*/temp*Exclude files and directories whose names start with temp in any immediate subdirectory of the root. For example, the plain file /somedir/temporary.txt is excluded, as is the directory /somedir/temp.*/*/temp*Exclude files and directories starting with temp from any subdirectory that is two levels below the root. For example, /somedir/subdir/temporary.txt is excluded.temp?Exclude files and directories in the root directory whose names are a one-character extension of temp. For example, /tempa and /tempb are excluded.</p><p>Matching is done using Go’s <a href="https://golang.org/pkg/path/filepath#Match">filepath.Match</a> rules. A preprocessing step removes leading and trailing whitespace and eliminates . and .. elements using Go’s <a href="https://golang.org/pkg/path/filepath/#Clean">filepath.Clean</a>. Lines that are blank after preprocessing are ignored.</p><p>Beyond Go’s filepath.Match rules, Docker also supports a special wildcard string ** that matches any number of directories (including zero). For example, **/*.go will exclude all files that end with .go that are found in all directories, including the root of the build context.</p><p>Lines starting with ! (exclamation mark) can be used to make exceptions to exclusions. The following is an example .dockerignore file that uses this mechanism:</p><pre>*.md<br>!README.md</pre><p>All markdown files <em>except</em> README.md are excluded from the context.</p><p>The placement of ! exception rules influences the behavior: the last line of the .dockerignore that matches a particular file determines whether it is included or excluded. Consider the following example:</p><pre>*.md<br>!README*.md<br>README-secret.md</pre><p>No markdown files are included in the context except README files other than README-secret.md.</p><p>Now consider this example:</p><pre>*.md<br>README-secret.md<br>!README*.md</pre><p>All of the README files are included. The middle line has no effect because !README*.md matches README-secret.md and comes last.</p><p>You can even use the .dockerignore file to exclude the Dockerfile and .dockerignore files. These files are still sent to the daemon because it needs them to do its job. But the ADD and COPY instructions do not copy them to the image.</p><p>Finally, you may want to specify which files to include in the context, rather than which to exclude. To achieve this, specify * as the first pattern, followed by one or more ! exception patterns.</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>For historical reasons, the pattern </em><em>. is ignored.</em></blockquote><h3>FROM</h3><pre>FROM [--platform=&lt;platform&gt;] &lt;image&gt; [AS &lt;name&gt;]</pre><p>Or</p><pre>FROM [--platform=&lt;platform&gt;] &lt;image&gt;[:&lt;tag&gt;] [AS &lt;name&gt;]</pre><p>Or</p><pre>FROM [--platform=&lt;platform&gt;] &lt;image&gt;[@&lt;digest&gt;] [AS &lt;name&gt;]</pre><p>The FROM instruction initializes a new build stage and sets the <a href="https://docs.docker.com/glossary/#base-image"><em>Base Image</em></a> for subsequent instructions. As such, a valid Dockerfile must start with a FROM instruction. The image can be any valid image – it is especially easy to start by <strong>pulling an image</strong> from the <a href="https://docs.docker.com/docker-hub/repos/"><em>Public Repositories</em></a>.</p><ul><li>ARG is the only instruction that may precede FROM in the Dockerfile. See <a href="https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact">Understand how ARG and FROM interact</a>.</li><li>FROM can appear multiple times within a single Dockerfile to create multiple images or use one build stage as a dependency for another. Simply make a note of the last image ID output by the commit before each new FROM instruction. Each FROM instruction clears any state created by previous instructions.</li><li>Optionally a name can be given to a new build stage by adding AS name to the FROM instruction. The name can be used in subsequent FROM and COPY --from=&lt;name&gt; instructions to refer to the image built in this stage.</li><li>The tag or digest values are optional. If you omit either of them, the builder assumes a latest tag by default. The builder returns an error if it cannot find the tag value.</li></ul><p>The optional --platform flag can be used to specify the platform of the image in case FROM references a multi-platform image. For example, linux/amd64, linux/arm64, or windows/amd64. By default, the target platform of the build request is used. Global build arguments can be used in the value of this flag, for example <a href="https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope">automatic platform ARGs</a> allow you to force a stage to native build platform (--platform=$BUILDPLATFORM), and use it to cross-compile to the target platform inside the stage.</p><h3>Understand how ARG and FROM interact</h3><p>FROM instructions support variables that are declared by any ARG instructions that occur before the first FROM.</p><pre>ARG  CODE_VERSION=latest<br>FROM base:${CODE_VERSION}<br>CMD  /code/run-app</pre><pre>FROM extras:${CODE_VERSION}<br>CMD  /code/run-extras</pre><p>An ARG declared before a FROM is outside of a build stage, so it can’t be used in any instruction after a FROM. To use the default value of an ARG declared before the first FROM use an ARG instruction without a value inside of a build stage:</p><pre>ARG VERSION=latest<br>FROM busybox:$VERSION<br>ARG VERSION<br>RUN echo $VERSION &gt; image_version</pre><h3>RUN</h3><p>RUN has 2 forms:</p><ul><li>RUN &lt;command&gt; (<em>shell</em> form, the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)</li><li>RUN [&quot;executable&quot;, &quot;param1&quot;, &quot;param2&quot;] (<em>exec</em> form)</li></ul><p>The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.</p><p>Layering RUN instructions and generating commits conforms to the core concepts of Docker where commits are cheap and containers can be created from any point in an image’s history, much like source control.</p><p>The <em>exec</em> form makes it possible to avoid shell string munging, and to RUN commands using a base image that does not contain the specified shell executable.</p><p>The default shell for the <em>shell</em> form can be changed using the SHELL command.</p><p>In the <em>shell</em> form you can use a \ (backslash) to continue a single RUN instruction onto the next line. For example, consider these two lines:</p><pre>RUN /bin/bash -c &#39;source $HOME/.bashrc &amp;&amp; \<br>echo $HOME&#39;</pre><p>Together they are equivalent to this single line:</p><pre>RUN /bin/bash -c &#39;source $HOME/.bashrc &amp;&amp; echo $HOME&#39;</pre><p>To use a different shell, other than ‘/bin/sh’, use the <em>exec</em> form passing in the desired shell. For example:</p><pre>RUN [&quot;/bin/bash&quot;, &quot;-c&quot;, &quot;echo hello&quot;]</pre><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>The </em>exec<em> form is parsed as a JSON array, which means that you must use double-quotes (“) around words not single-quotes (‘).</em></blockquote><p>Unlike the <em>shell</em> form, the <em>exec</em> form does not invoke a command shell. This means that normal shell processing does not happen. For example, RUN [ &quot;echo&quot;, &quot;$HOME&quot; ] will not do variable substitution on $HOME. If you want shell processing then either use the <em>shell</em> form or execute a shell directly, for example: RUN [ &quot;sh&quot;, &quot;-c&quot;, &quot;echo $HOME&quot; ]. When using the exec form and executing a shell directly, as in the case for the shell form, it is the shell that is doing the environment variable expansion, not docker.</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>In the </em>JSON<em> form, it is necessary to escape backslashes. This is particularly relevant on Windows where the backslash is the path separator. The following line would otherwise be treated as </em>shell<em> form due to not being valid JSON, and fail in an unexpected way:</em></blockquote><blockquote><em>RUN [&quot;c:\windows\system32\tasklist.exe&quot;]</em></blockquote><blockquote><em>The correct syntax for this example is:</em></blockquote><blockquote><em>RUN [&quot;c:\\windows\\system32\\tasklist.exe&quot;]</em></blockquote><p>The cache for RUN instructions isn’t invalidated automatically during the next build. The cache for an instruction like RUN apt-get dist-upgrade -y will be reused during the next build. The cache for RUN instructions can be invalidated by using the --no-cache flag, for example docker build --no-cache.</p><p>See the <a href="https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/">Dockerfile Best Practices guide</a> for more information.</p><p>The cache for RUN instructions can be invalidated by <a href="https://docs.docker.com/engine/reference/builder/#add">ADD</a> and <a href="https://docs.docker.com/engine/reference/builder/#copy">COPY</a> instructions.</p><h3>RUN — mount</h3><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>Added in </em><a href="https://docs.docker.com/engine/reference/builder/#syntax"><em>docker/dockerfile:1.2</em></a></blockquote><p>RUN --mount allows you to create filesystem mounts that the build can access. This can be used to:</p><ul><li>Create bind mount to the host filesystem or other build stages</li><li>Access build secrets or ssh-agent sockets</li><li>Use a persistent package management cache to speed up your build</li></ul><p>Syntax: --mount=[type=&lt;TYPE&gt;][,option=&lt;value&gt;[,option=&lt;value&gt;]...]</p><h3>Mount types</h3><p>TypeDescription<a href="https://docs.docker.com/engine/reference/builder/#run---mounttypebind">bind</a> (default)Bind-mount context directories (read-only).<a href="https://docs.docker.com/engine/reference/builder/#run---mounttypecache">cache</a>Mount a temporary directory to cache directories for compilers and package managers.<a href="https://docs.docker.com/engine/reference/builder/#run---mounttypesecret">secret</a>Allow the build container to access secure files such as private keys without baking them into the image.<a href="https://docs.docker.com/engine/reference/builder/#run---mounttypessh">ssh</a>Allow the build container to access SSH keys via SSH agents, with support for passphrases.</p><h3>RUN — mount=type=bind</h3><p>This mount type allows binding files or directories to the build container. A bind mount is read-only by default.</p><p>OptionDescriptiontarget<a href="https://docs.docker.com/engine/reference/builder/#fn:1">1</a>Mount path.sourceSource path in the from. Defaults to the root of the from.fromBuild stage or image name for the root of the source. Defaults to the build context.rw,readwriteAllow writes on the mount. Written data will be discarded.</p><h3>RUN — mount=type=cache</h3><p>This mount type allows the build container to cache directories for compilers and package managers.</p><p>OptionDescriptionidOptional ID to identify separate/different caches. Defaults to value of target.target<a href="https://docs.docker.com/engine/reference/builder/#fn:1">1</a>Mount path.ro,readonlyRead-only if set.sharingOne of shared, private, or locked. Defaults to shared. A shared cache mount can be used concurrently by multiple writers. private creates a new mount if there are multiple writers. locked pauses the second writer until the first one releases the mount.fromBuild stage to use as a base of the cache mount. Defaults to empty directory.sourceSubpath in the from to mount. Defaults to the root of the from.modeFile mode for new cache directory in octal. Default 0755.uidUser ID for new cache directory. Default 0.gidGroup ID for new cache directory. Default 0.</p><p>Contents of the cache directories persists between builder invocations without invalidating the instruction cache. Cache mounts should only be used for better performance. Your build should work with any contents of the cache directory as another build may overwrite the files or GC may clean it if more storage space is needed.</p><h4>Example: cache Go packages</h4><pre># syntax=docker/dockerfile:1<br>FROM golang<br>RUN --mount=type=cache,target=/root/.cache/go-build \<br>  go build ...</pre><h4>Example: cache apt packages</h4><pre># syntax=docker/dockerfile:1<br>FROM ubuntu<br>RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo &#39;Binary::apt::APT::Keep-Downloaded-Packages &quot;true&quot;;&#39; &gt; /etc/apt/apt.conf.d/keep-cache<br>RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \<br>  --mount=type=cache,target=/var/lib/apt,sharing=locked \<br>  apt update &amp;&amp; apt-get --no-install-recommends install -y gcc</pre><p>Apt needs exclusive access to its data, so the caches use the option sharing=locked, which will make sure multiple parallel builds using the same cache mount will wait for each other and not access the same cache files at the same time. You could also use sharing=private if you prefer to have each build create another cache directory in this case.</p><h3>RUN — mount=type=tmpfs</h3><p>This mount type allows mounting tmpfs in the build container.</p><p>OptionDescriptiontarget<a href="https://docs.docker.com/engine/reference/builder/#fn:1">1</a>Mount path.sizeSpecify an upper limit on the size of the filesystem.</p><h3>RUN — mount=type=secret</h3><p>This mount type allows the build container to access secure files such as private keys without baking them into the image.</p><p>OptionDescriptionidID of the secret. Defaults to basename of the target path.targetMount path. Defaults to /run/secrets/ + id.requiredIf set to true, the instruction errors out when the secret is unavailable. Defaults to false.modeFile mode for secret file in octal. Default 0400.uidUser ID for secret file. Default 0.gidGroup ID for secret file. Default 0.</p><h4>Example: access to S3</h4><pre># syntax=docker/dockerfile:1<br>FROM python:3<br>RUN pip install awscli<br>RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \<br>  aws s3 cp s3://... ...</pre><pre>$ docker buildx build --secret id=aws,src=$HOME/.aws/credentials .</pre><h3>RUN — mount=type=ssh</h3><p>This mount type allows the build container to access SSH keys via SSH agents, with support for passphrases.</p><p>OptionDescriptionidID of SSH agent socket or key. Defaults to “default”.targetSSH agent socket path. Defaults to /run/buildkit/ssh_agent.${N}.requiredIf set to true, the instruction errors out when the key is unavailable. Defaults to false.modeFile mode for socket in octal. Default 0600.uidUser ID for socket. Default 0.gidGroup ID for socket. Default 0.</p><h4>Example: access to Gitlab</h4><pre># syntax=docker/dockerfile:1<br>FROM alpine<br>RUN apk add --no-cache openssh-client<br>RUN mkdir -p -m 0700 ~/.ssh &amp;&amp; ssh-keyscan gitlab.com &gt;&gt; ~/.ssh/known_hosts<br>RUN --mount=type=ssh \<br>  ssh -q -T git@gitlab.com 2&gt;&amp;1 | tee /hello<br># &quot;Welcome to GitLab, @GITLAB_USERNAME_ASSOCIATED_WITH_SSHKEY&quot; should be printed here<br># with the type of build progress is defined as `plain`.</pre><pre>$ eval $(ssh-agent)<br>$ ssh-add ~/.ssh/id_rsa<br>(Input your passphrase here)<br>$ docker buildx build --ssh default=$SSH_AUTH_SOCK .</pre><p>You can also specify a path to *.pem file on the host directly instead of $SSH_AUTH_SOCK. However, pem files with passphrases are not supported.</p><h3>RUN — network</h3><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>Added in </em><a href="https://docs.docker.com/engine/reference/builder/#syntax"><em>docker/dockerfile:1.1</em></a></blockquote><p>RUN --network allows control over which networking environment the command is run in.</p><p>Syntax: --network=&lt;TYPE&gt;</p><h3>Network types</h3><p>TypeDescription<a href="https://docs.docker.com/engine/reference/builder/#run---networkdefault">default</a> (default)Run in the default network.<a href="https://docs.docker.com/engine/reference/builder/#run---networknone">none</a>Run with no network access.<a href="https://docs.docker.com/engine/reference/builder/#run---networkhost">host</a>Run in the host’s network environment.</p><h3>RUN — network=default</h3><p>Equivalent to not supplying a flag at all, the command is run in the default network for the build.</p><h3>RUN — network=none</h3><p>The command is run with no network access (lo is still available, but is isolated to this process)</p><h4>Example: isolating external effects</h4><pre># syntax=docker/dockerfile:1<br>FROM python:3.6<br>ADD mypackage.tgz wheels/<br>RUN --network=none pip install --find-links wheels mypackage</pre><p>pip will only be able to install the packages provided in the tarfile, which can be controlled by an earlier build stage.</p><h3>RUN — network=host</h3><p>The command is run in the host’s network environment (similar to docker build --network=host, but on a per-instruction basis)</p><blockquote><strong><em>Warning</em></strong></blockquote><blockquote><em>The use of </em><em>--network=host is protected by the </em><em>network.host entitlement, which needs to be enabled when starting the buildkitd daemon with </em><em>--allow-insecure-entitlement network.host flag or in </em><a href="https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md"><em>buildkitd config</em></a><em>, and for a build request with </em><a href="https://docs.docker.com/engine/reference/commandline/buildx_build/#allow"><em>--allow network.host flag</em></a><em>.</em></blockquote><h3>RUN — security</h3><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>Not yet available in stable syntax, use </em><a href="https://docs.docker.com/engine/reference/builder/#syntax"><em>docker/dockerfile:1-labs</em></a><em> version.</em></blockquote><h3>RUN — security=insecure</h3><p>With --security=insecure, builder runs the command without sandbox in insecure mode, which allows to run flows requiring elevated privileges (e.g. containerd). This is equivalent to running docker run --privileged.</p><blockquote><strong><em>Warning</em></strong></blockquote><blockquote><em>In order to access this feature, entitlement </em><em>security.insecure should be enabled when starting the buildkitd daemon with </em><em>--allow-insecure-entitlement security.insecure flag or in </em><a href="https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md"><em>buildkitd config</em></a><em>, and for a build request with </em><a href="https://docs.docker.com/engine/reference/commandline/buildx_build/#allow"><em>--allow security.insecure flag</em></a><em>.</em></blockquote><h4>Example: check entitlements</h4><pre># syntax=docker/dockerfile:1-labs<br>FROM ubuntu<br>RUN --security=insecure cat /proc/self/status | grep CapEff</pre><pre>#84 0.093 CapEff:	0000003fffffffff</pre><h3>RUN — security=sandbox</h3><p>Default sandbox mode can be activated via --security=sandbox, but that is no-op.</p><h3>CMD</h3><p>The CMD instruction has three forms:</p><ul><li>CMD [&quot;executable&quot;,&quot;param1&quot;,&quot;param2&quot;] (<em>exec</em> form, this is the preferred form)</li><li>CMD [&quot;param1&quot;,&quot;param2&quot;] (as <em>default parameters to ENTRYPOINT</em>)</li><li>CMD command param1 param2 (<em>shell</em> form)</li></ul><p>There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.</p><p><strong>The main purpose of a </strong><strong>CMD is to provide defaults for an executing container.</strong> These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.</p><p>If CMD is used to provide default arguments for the ENTRYPOINT instruction, both the CMD and ENTRYPOINT instructions should be specified with the JSON array format.</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>The </em>exec<em> form is parsed as a JSON array, which means that you must use double-quotes (“) around words not single-quotes (‘).</em></blockquote><p>Unlike the <em>shell</em> form, the <em>exec</em> form does not invoke a command shell. This means that normal shell processing does not happen. For example, CMD [ &quot;echo&quot;, &quot;$HOME&quot; ] will not do variable substitution on $HOME. If you want shell processing then either use the <em>shell</em> form or execute a shell directly, for example: CMD [ &quot;sh&quot;, &quot;-c&quot;, &quot;echo $HOME&quot; ]. When using the exec form and executing a shell directly, as in the case for the shell form, it is the shell that is doing the environment variable expansion, not docker.</p><p>When used in the shell or exec formats, the CMD instruction sets the command to be executed when running the image.</p><p>If you use the <em>shell</em> form of the CMD, then the &lt;command&gt; will execute in /bin/sh -c:</p><pre>FROM ubuntu<br>CMD echo &quot;This is a test.&quot; | wc -</pre><p>If you want to <strong>run your</strong> &lt;command&gt; <strong>without a shell</strong> then you must express the command as a JSON array and give the full path to the executable. <strong>This array form is the preferred format of </strong><strong>CMD.</strong> Any additional parameters must be individually expressed as strings in the array:</p><pre>FROM ubuntu<br>CMD [&quot;/usr/bin/wc&quot;,&quot;--help&quot;]</pre><p>If you would like your container to run the same executable every time, then you should consider using ENTRYPOINT in combination with CMD. See <a href="https://docs.docker.com/engine/reference/builder/#entrypoint"><em>ENTRYPOINT</em></a>.</p><p>If the user specifies arguments to docker run then they will override the default specified in CMD.</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>Do not confuse </em><em>RUN with </em><em>CMD. </em><em>RUN actually runs a command and commits the result; </em><em>CMD does not execute anything at build time, but specifies the intended command for the image.</em></blockquote><h3>LABEL</h3><pre>LABEL &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; ...</pre><p>The LABEL instruction adds metadata to an image. A LABEL is a key-value pair. To include spaces within a LABEL value, use quotes and backslashes as you would in command-line parsing. A few usage examples:</p><pre>LABEL &quot;com.example.vendor&quot;=&quot;ACME Incorporated&quot;<br>LABEL com.example.label-with-value=&quot;foo&quot;<br>LABEL version=&quot;1.0&quot;<br>LABEL description=&quot;This text illustrates \<br>that label-values can span multiple lines.&quot;</pre><p>An image can have more than one label. You can specify multiple labels on a single line. Prior to Docker 1.10, this decreased the size of the final image, but this is no longer the case. You may still choose to specify multiple labels in a single instruction, in one of the following two ways:</p><pre>LABEL multi.label1=&quot;value1&quot; multi.label2=&quot;value2&quot; other=&quot;value3&quot;</pre><pre>LABEL multi.label1=&quot;value1&quot; \<br>      multi.label2=&quot;value2&quot; \<br>      other=&quot;value3&quot;</pre><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>Be sure to use double quotes and not single quotes. Particularly when you are using string interpolation (e.g. </em><em>LABEL example=&quot;foo-$ENV_VAR&quot;), single quotes will take the string as is without unpacking the variable’s value.</em></blockquote><p>Labels included in base or parent images (images in the FROM line) are inherited by your image. If a label already exists but with a different value, the most-recently-applied value overrides any previously-set value.</p><p>To view an image’s labels, use the docker image inspect command. You can use the --format option to show just the labels;</p><pre>$ docker image inspect --format=&#39;{{json .Config.Labels}}&#39; myimage</pre><pre>{<br>  &quot;com.example.vendor&quot;: &quot;ACME Incorporated&quot;,<br>  &quot;com.example.label-with-value&quot;: &quot;foo&quot;,<br>  &quot;version&quot;: &quot;1.0&quot;,<br>  &quot;description&quot;: &quot;This text illustrates that label-values can span multiple lines.&quot;,<br>  &quot;multi.label1&quot;: &quot;value1&quot;,<br>  &quot;multi.label2&quot;: &quot;value2&quot;,<br>  &quot;other&quot;: &quot;value3&quot;<br>}</pre><h3>MAINTAINER (deprecated)</h3><pre>MAINTAINER &lt;name&gt;</pre><p>The MAINTAINER instruction sets the <em>Author</em> field of the generated images. The LABEL instruction is a much more flexible version of this and you should use it instead, as it enables setting any metadata you require, and can be viewed easily, for example with docker inspect. To set a label corresponding to the MAINTAINER field you could use:</p><pre>LABEL org.opencontainers.image.authors=&quot;SvenDowideit@home.org.au&quot;</pre><p>This will then be visible from docker inspect with the other labels.</p><h3>EXPOSE</h3><pre>EXPOSE &lt;port&gt; [&lt;port&gt;/&lt;protocol&gt;...]</pre><p>The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. You can specify whether the port listens on TCP or UDP, and the default is TCP if the protocol is not specified.</p><p>The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.</p><p>By default, EXPOSE assumes TCP. You can also specify UDP:</p><pre>EXPOSE 80/udp</pre><p>To expose on both TCP and UDP, include two lines:</p><pre>EXPOSE 80/tcp<br>EXPOSE 80/udp</pre><p>In this case, if you use -P with docker run, the port will be exposed once for TCP and once for UDP. Remember that -P uses an ephemeral high-ordered host port on the host, so the port will not be the same for TCP and UDP.</p><p>Regardless of the EXPOSE settings, you can override them at runtime by using the -p flag. For example</p><pre>$ docker run -p 80:80/tcp -p 80:80/udp ...</pre><p>To set up port redirection on the host system, see <a href="https://docs.docker.com/engine/reference/run/#expose-incoming-ports">using the -P flag</a>. The docker network command supports creating networks for communication among containers without the need to expose or publish specific ports, because the containers connected to the network can communicate with each other over any port. For detailed information, see the <a href="https://docs.docker.com/engine/userguide/networking/">overview of this feature</a>.</p><h3>ENV</h3><pre>ENV &lt;key&gt;=&lt;value&gt; ...</pre><p>The ENV instruction sets the environment variable &lt;key&gt; to the value &lt;value&gt;. This value will be in the environment for all subsequent instructions in the build stage and can be <a href="https://docs.docker.com/engine/reference/builder/#environment-replacement">replaced inline</a> in many as well. The value will be interpreted for other environment variables, so quote characters will be removed if they are not escaped. Like command line parsing, quotes and backslashes can be used to include spaces within values.</p><p>Example:</p><pre>ENV MY_NAME=&quot;John Doe&quot;<br>ENV MY_DOG=Rex\ The\ Dog<br>ENV MY_CAT=fluffy</pre><p>The ENV instruction allows for multiple &lt;key&gt;=&lt;value&gt; ... variables to be set at one time, and the example below will yield the same net results in the final image:</p><pre>ENV MY_NAME=&quot;John Doe&quot; MY_DOG=Rex\ The\ Dog \<br>    MY_CAT=fluffy</pre><p>The environment variables set using ENV will persist when a container is run from the resulting image. You can view the values using docker inspect, and change them using docker run --env &lt;key&gt;=&lt;value&gt;.</p><p>A stage inherits any environment variables that were set using ENV by its parent stage or any ancestor. Refer <a href="https://docs.docker.com/build/building/multi-stage/">here</a> for more on multi-staged builds.</p><p>Environment variable persistence can cause unexpected side effects. For example, setting ENV DEBIAN_FRONTEND=noninteractive changes the behavior of apt-get, and may confuse users of your image.</p><p>If an environment variable is only needed during build, and not in the final image, consider setting a value for a single command instead:</p><pre>RUN DEBIAN_FRONTEND=noninteractive apt-get update &amp;&amp; apt-get install -y ...</pre><p>Or using <a href="https://docs.docker.com/engine/reference/builder/#arg">ARG</a>, which is not persisted in the final image:</p><pre>ARG DEBIAN_FRONTEND=noninteractive<br>RUN apt-get update &amp;&amp; apt-get install -y ...</pre><blockquote><strong><em>Alternative syntax</em></strong></blockquote><blockquote><em>The </em><em>ENV instruction also allows an alternative syntax </em><em>ENV &lt;key&gt; &lt;value&gt;, omitting the </em><em>=. For example:</em></blockquote><blockquote><em>ENV MY_VAR my-value</em></blockquote><blockquote><em>This syntax does not allow for multiple environment-variables to be set in a single </em><em>ENV instruction, and can be confusing. For example, the following sets a single environment variable (</em><em>ONE) with value </em><em>&quot;TWO= THREE=world&quot;:</em></blockquote><blockquote><em>ENV ONE TWO= THREE=world</em></blockquote><blockquote><em>The alternative syntax is supported for backward compatibility, but discouraged for the reasons outlined above, and may be removed in a future release.</em></blockquote><h3>ADD</h3><p>ADD has two forms:</p><pre>ADD [--chown=&lt;user&gt;:&lt;group&gt;] [--chmod=&lt;perms&gt;] [--checksum=&lt;checksum&gt;] &lt;src&gt;... &lt;dest&gt;<br>ADD [--chown=&lt;user&gt;:&lt;group&gt;] [--chmod=&lt;perms&gt;] [&quot;&lt;src&gt;&quot;,... &quot;&lt;dest&gt;&quot;]</pre><p>The latter form is required for paths containing whitespace.</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>The </em><em>--chown and </em><em>--chmod features are only supported on Dockerfiles used to build Linux containers, and will not work on Windows containers. Since user and group ownership concepts do not translate between Linux and Windows, the use of </em><em>/etc/passwd and </em><em>/etc/group for translating user and group names to IDs restricts this feature to only be viable for Linux OS-based containers.</em></blockquote><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>--chmod is supported since </em><a href="https://docs.docker.com/build/buildkit/dockerfile-frontend/"><em>Dockerfile 1.3</em></a><em>. Only octal notation is currently supported. Non-octal support is tracked in </em><a href="https://github.com/moby/buildkit/issues/1951"><em>moby/buildkit#1951</em></a><em>.</em></blockquote><p>The ADD instruction copies new files, directories or remote file URLs from &lt;src&gt; and adds them to the filesystem of the image at the path &lt;dest&gt;.</p><p>Multiple &lt;src&gt; resources may be specified but if they are files or directories, their paths are interpreted as relative to the source of the context of the build.</p><p>Each &lt;src&gt; may contain wildcards and matching will be done using Go’s <a href="https://golang.org/pkg/path/filepath#Match">filepath.Match</a> rules. For example:</p><p>To add all files starting with “hom”:</p><pre>ADD hom* /mydir/</pre><p>In the example below, ? is replaced with any single character, e.g., “home.txt”.</p><pre>ADD hom?.txt /mydir/</pre><p>The &lt;dest&gt; is an absolute path, or a path relative to WORKDIR, into which the source will be copied inside the destination container.</p><p>The example below uses a relative path, and adds “test.txt” to &lt;WORKDIR&gt;/relativeDir/:</p><pre>ADD test.txt relativeDir/</pre><p>Whereas this example uses an absolute path, and adds “test.txt” to /absoluteDir/</p><pre>ADD test.txt /absoluteDir/</pre><p>When adding files or directories that contain special characters (such as [ and ]), you need to escape those paths following the Golang rules to prevent them from being treated as a matching pattern. For example, to add a file named arr[0].txt, use the following;</p><pre>ADD arr[[]0].txt /mydir/</pre><p>All new files and directories are created with a UID and GID of 0, unless the optional --chown flag specifies a given username, groupname, or UID/GID combination to request specific ownership of the content added. The format of the --chown flag allows for either username and groupname strings or direct integer UID and GID in any combination. Providing a username without groupname or a UID without GID will use the same numeric UID as the GID. If a username or groupname is provided, the container’s root filesystem /etc/passwd and /etc/group files will be used to perform the translation from name to integer UID or GID respectively. The following examples show valid definitions for the --chown flag:</p><pre>ADD --chown=55:mygroup files* /somedir/<br>ADD --chown=bin files* /somedir/<br>ADD --chown=1 files* /somedir/<br>ADD --chown=10:11 files* /somedir/<br>ADD --chown=myuser:mygroup --chmod=655 files* /somedir/</pre><p>If the container root filesystem does not contain either /etc/passwd or /etc/group files and either user or group names are used in the --chown flag, the build will fail on the ADD operation. Using numeric IDs requires no lookup and will not depend on container root filesystem content.</p><p>In the case where &lt;src&gt; is a remote file URL, the destination will have permissions of 600. If the remote file being retrieved has an HTTP Last-Modified header, the timestamp from that header will be used to set the mtime on the destination file. However, like any other file processed during an ADD, mtime will not be included in the determination of whether or not the file has changed and the cache should be updated.</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>If you build by passing a </em><em>Dockerfile through STDIN (</em><em>docker build - &lt; somefile), there is no build context, so the </em><em>Dockerfile can only contain a URL based </em><em>ADD instruction. You can also pass a compressed archive through STDIN: (</em><em>docker build - &lt; archive.tar.gz), the </em><em>Dockerfile at the root of the archive and the rest of the archive will be used as the context of the build.</em></blockquote><p>If your URL files are protected using authentication, you need to use RUN wget, RUN curl or use another tool from within the container as the ADD instruction does not support authentication.</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>The first encountered </em><em>ADD instruction will invalidate the cache for all following instructions from the Dockerfile if the contents of </em><em>&lt;src&gt; have changed. This includes invalidating the cache for </em><em>RUN instructions. See the </em><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache"><em>Dockerfile Best Practices guide – Leverage build cache</em></a><em> for more information.</em></blockquote><p>ADD obeys the following rules:</p><ul><li>The &lt;src&gt; path must be inside the <em>context</em> of the build; you cannot ADD ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.</li><li>If &lt;src&gt; is a URL and &lt;dest&gt; does not end with a trailing slash, then a file is downloaded from the URL and copied to &lt;dest&gt;.</li><li>If &lt;src&gt; is a URL and &lt;dest&gt; does end with a trailing slash, then the filename is inferred from the URL and the file is downloaded to &lt;dest&gt;/&lt;filename&gt;. For instance, ADD http://example.com/foobar / would create the file /foobar. The URL must have a nontrivial path so that an appropriate filename can be discovered in this case (http://example.com will not work).</li><li>If &lt;src&gt; is a directory, the entire contents of the directory are copied, including filesystem metadata.</li></ul><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>The directory itself is not copied, just its contents.</em></blockquote><ul><li>If &lt;src&gt; is a <em>local</em> tar archive in a recognized compression format (identity, gzip, bzip2 or xz) then it is unpacked as a directory. Resources from <em>remote</em> URLs are <strong>not</strong> decompressed. When a directory is copied or unpacked, it has the same behavior as tar -x, the result is the union of:</li></ul><ol><li>Whatever existed at the destination path and</li><li>The contents of the source tree, with conflicts resolved in favor of “2.” on a file-by-file basis.</li></ol><ul><li><strong>Note</strong></li><li>Whether a file is identified as a recognized compression format or not is done solely based on the contents of the file, not the name of the file. For example, if an empty file happens to end with .tar.gz this will not be recognized as a compressed file and <strong>will not</strong> generate any kind of decompression error message, rather the file will simply be copied to the destination.</li><li>If &lt;src&gt; is any other kind of file, it is copied individually along with its metadata. In this case, if &lt;dest&gt; ends with a trailing slash /, it will be considered a directory and the contents of &lt;src&gt; will be written at &lt;dest&gt;/base(&lt;src&gt;).</li><li>If multiple &lt;src&gt; resources are specified, either directly or due to the use of a wildcard, then &lt;dest&gt; must be a directory, and it must end with a slash /.</li><li>If &lt;dest&gt; does not end with a trailing slash, it will be considered a regular file and the contents of &lt;src&gt; will be written at &lt;dest&gt;.</li><li>If &lt;dest&gt; doesn’t exist, it is created along with all missing directories in its path.</li></ul><h3>Verifying a remote file checksum ADD --checksum=&lt;checksum&gt; &lt;http src&gt; &lt;dest&gt;</h3><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>Not yet available in stable syntax, use </em><a href="https://docs.docker.com/engine/reference/builder/#syntax"><em>docker/dockerfile:1-labs</em></a><em> version (</em><em>1.5-labs or newer). Planned to be included in </em><em>docker/dockerfile:1.6.</em></blockquote><p>The checksum of a remote file can be verified with the --checksum flag:</p><pre>ADD --checksum=sha256:24454f830cdb571e2c4ad15481119c43b3cafd48dd869a9b2945d1036d1dc68d https://mirrors.edge.kernel.org/pub/linux/kernel/Historic/linux-0.01.tar.gz /</pre><p>The --checksum flag only supports HTTP sources currently.</p><h3>Adding a git repository ADD &lt;git ref&gt; &lt;dir&gt;</h3><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>Not yet available in stable syntax, use </em><a href="https://docs.docker.com/engine/reference/builder/#syntax"><em>docker/dockerfile:1-labs</em></a><em> version (</em><em>1.5-labs or newer). Planned to be included in </em><em>docker/dockerfile:1.6.</em></blockquote><p>This form allows adding a git repository to an image directly, without using the git command inside the image:</p><pre>ADD [--keep-git-dir=&lt;boolean&gt;] &lt;git ref&gt; &lt;dir&gt;</pre><pre># syntax=docker/dockerfile:1-labs<br>FROM alpine<br>ADD --keep-git-dir=true https://github.com/moby/buildkit.git#v0.10.1 /buildkit</pre><p>The --keep-git-dir=true flag adds the .git directory. This flag defaults to false.</p><h3>Adding a private git repository</h3><p>To add a private repo via SSH, create a Dockerfile with the following form:</p><pre># syntax=docker/dockerfile:1-labs<br>FROM alpine<br>ADD git@git.example.com:foo/bar.git /bar</pre><p>This Dockerfile can be built with docker build --ssh or buildctl build --ssh, e.g.,</p><pre>$ docker build --ssh default</pre><pre>$ buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --ssh default</pre><h3>ADD — link</h3><p>See <a href="https://docs.docker.com/engine/reference/builder/#copy---link">COPY --link</a>.</p><h3>COPY</h3><p>COPY has two forms:</p><pre>COPY [--chown=&lt;user&gt;:&lt;group&gt;] [--chmod=&lt;perms&gt;] &lt;src&gt;... &lt;dest&gt;<br>COPY [--chown=&lt;user&gt;:&lt;group&gt;] [--chmod=&lt;perms&gt;] [&quot;&lt;src&gt;&quot;,... &quot;&lt;dest&gt;&quot;]</pre><p>This latter form is required for paths containing whitespace</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>The </em><em>--chown and </em><em>--chmod features are only supported on Dockerfiles used to build Linux containers, and will not work on Windows containers. Since user and group ownership concepts do not translate between Linux and Windows, the use of </em><em>/etc/passwd and </em><em>/etc/group for translating user and group names to IDs restricts this feature to only be viable for Linux OS-based containers.</em></blockquote><p>The COPY instruction copies new files or directories from &lt;src&gt; and adds them to the filesystem of the container at the path &lt;dest&gt;.</p><p>Multiple &lt;src&gt; resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build.</p><p>Each &lt;src&gt; may contain wildcards and matching will be done using Go’s <a href="https://golang.org/pkg/path/filepath#Match">filepath.Match</a> rules. For example:</p><p>To add all files starting with “hom”:</p><pre>COPY hom* /mydir/</pre><p>In the example below, ? is replaced with any single character, e.g., “home.txt”.</p><pre>COPY hom?.txt /mydir/</pre><p>The &lt;dest&gt; is an absolute path, or a path relative to WORKDIR, into which the source will be copied inside the destination container.</p><p>The example below uses a relative path, and adds “test.txt” to &lt;WORKDIR&gt;/relativeDir/:</p><pre>COPY test.txt relativeDir/</pre><p>Whereas this example uses an absolute path, and adds “test.txt” to /absoluteDir/</p><pre>COPY test.txt /absoluteDir/</pre><p>When copying files or directories that contain special characters (such as [ and ]), you need to escape those paths following the Golang rules to prevent them from being treated as a matching pattern. For example, to copy a file named arr[0].txt, use the following;</p><pre>COPY arr[[]0].txt /mydir/</pre><p>All new files and directories are created with a UID and GID of 0, unless the optional --chown flag specifies a given username, groupname, or UID/GID combination to request specific ownership of the copied content. The format of the --chown flag allows for either username and groupname strings or direct integer UID and GID in any combination. Providing a username without groupname or a UID without GID will use the same numeric UID as the GID. If a username or groupname is provided, the container’s root filesystem /etc/passwd and /etc/group files will be used to perform the translation from name to integer UID or GID respectively. The following examples show valid definitions for the --chown flag:</p><pre>COPY --chown=55:mygroup files* /somedir/<br>COPY --chown=bin files* /somedir/<br>COPY --chown=1 files* /somedir/<br>COPY --chown=10:11 files* /somedir/<br>COPY --chown=myuser:mygroup --chmod=644 files* /somedir/</pre><p>If the container root filesystem does not contain either /etc/passwd or /etc/group files and either user or group names are used in the --chown flag, the build will fail on the COPY operation. Using numeric IDs requires no lookup and does not depend on container root filesystem content.</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>If you build using STDIN (</em><em>docker build - &lt; somefile), there is no build context, so </em><em>COPY can’t be used.</em></blockquote><p>Optionally COPY accepts a flag --from=&lt;name&gt; that can be used to set the source location to a previous build stage (created with FROM .. AS &lt;name&gt;) that will be used instead of a build context sent by the user. In case a build stage with a specified name can’t be found an image with the same name is attempted to be used instead.</p><p>COPY obeys the following rules:</p><ul><li>The &lt;src&gt; path must be inside the <em>context</em> of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.</li><li>If &lt;src&gt; is a directory, the entire contents of the directory are copied, including filesystem metadata.</li></ul><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>The directory itself is not copied, just its contents.</em></blockquote><ul><li>If &lt;src&gt; is any other kind of file, it is copied individually along with its metadata. In this case, if &lt;dest&gt; ends with a trailing slash /, it will be considered a directory and the contents of &lt;src&gt; will be written at &lt;dest&gt;/base(&lt;src&gt;).</li><li>If multiple &lt;src&gt; resources are specified, either directly or due to the use of a wildcard, then &lt;dest&gt; must be a directory, and it must end with a slash /.</li><li>If &lt;dest&gt; does not end with a trailing slash, it will be considered a regular file and the contents of &lt;src&gt; will be written at &lt;dest&gt;.</li><li>If &lt;dest&gt; doesn’t exist, it is created along with all missing directories in its path.</li></ul><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>The first encountered </em><em>COPY instruction will invalidate the cache for all following instructions from the Dockerfile if the contents of </em><em>&lt;src&gt; have changed. This includes invalidating the cache for </em><em>RUN instructions. See the </em><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache"><em>Dockerfile Best Practices guide – Leverage build cache</em></a><em> for more information.</em></blockquote><h3>COPY — link</h3><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>Added in </em><a href="https://docs.docker.com/engine/reference/builder/#syntax"><em>docker/dockerfile:1.4</em></a></blockquote><p>Enabling this flag in COPY or ADD commands allows you to copy files with enhanced semantics where your files remain independent on their own layer and don’t get invalidated when commands on previous layers are changed.</p><p>When --link is used your source files are copied into an empty destination directory. That directory is turned into a layer that is linked on top of your previous state.</p><pre># syntax=docker/dockerfile:1<br>FROM alpine<br>COPY --link /foo /bar</pre><p>Is equivalent of doing two builds:</p><pre>FROM alpine</pre><p>and</p><pre>FROM scratch<br>COPY /foo /bar</pre><p>and merging all the layers of both images together.</p><h3>Benefits of using --link</h3><p>Use --link to reuse already built layers in subsequent builds with --cache-from even if the previous layers have changed. This is especially important for multi-stage builds where a COPY --from statement would previously get invalidated if any previous commands in the same stage changed, causing the need to rebuild the intermediate stages again. With --link the layer the previous build generated is reused and merged on top of the new layers. This also means you can easily rebase your images when the base images receive updates, without having to execute the whole build again. In backends that support it, BuildKit can do this rebase action without the need to push or pull any layers between the client and the registry. BuildKit will detect this case and only create new image manifest that contains the new layers and old layers in correct order.</p><p>The same behavior where BuildKit can avoid pulling down the base image can also happen when using --link and no other commands that would require access to the files in the base image. In that case BuildKit will only build the layers for the COPY commands and push them to the registry directly on top of the layers of the base image.</p><h3>Incompatibilities with --link=false</h3><p>When using --link the COPY/ADD commands are not allowed to read any files from the previous state. This means that if in previous state the destination directory was a path that contained a symlink, COPY/ADD can not follow it. In the final image the destination path created with --link will always be a path containing only directories.</p><p>If you don’t rely on the behavior of following symlinks in the destination path, using --link is always recommended. The performance of --link is equivalent or better than the default behavior and, it creates much better conditions for cache reuse.</p><h3>ENTRYPOINT</h3><p>ENTRYPOINT has two forms:</p><p>The <em>exec</em> form, which is the preferred form:</p><pre>ENTRYPOINT [&quot;executable&quot;, &quot;param1&quot;, &quot;param2&quot;]</pre><p>The <em>shell</em> form:</p><pre>ENTRYPOINT command param1 param2</pre><p>An ENTRYPOINT allows you to configure a container that will run as an executable.</p><p>For example, the following starts nginx with its default content, listening on port 80:</p><pre>$ docker run -i -t --rm -p 80:80 nginx</pre><p>Command line arguments to docker run &lt;image&gt; will be appended after all elements in an <em>exec</em> form ENTRYPOINT, and will override all elements specified using CMD. This allows arguments to be passed to the entry point, i.e., docker run &lt;image&gt; -d will pass the -d argument to the entry point. You can override the ENTRYPOINT instruction using the docker run --entrypoint flag.</p><p>The <em>shell</em> form prevents any CMD or run command line arguments from being used, but has the disadvantage that your ENTRYPOINT will be started as a subcommand of /bin/sh -c, which does not pass signals. This means that the executable will not be the container’s PID 1 - and will <em>not</em> receive Unix signals - so your executable will not receive a SIGTERM from docker stop &lt;container&gt;.</p><p>Only the last ENTRYPOINT instruction in the Dockerfile will have an effect.</p><h3>Exec form ENTRYPOINT example</h3><p>You can use the <em>exec</em> form of ENTRYPOINT to set fairly stable default commands and arguments and then use either form of CMD to set additional defaults that are more likely to be changed.</p><pre>FROM ubuntu<br>ENTRYPOINT [&quot;top&quot;, &quot;-b&quot;]<br>CMD [&quot;-c&quot;]</pre><p>When you run the container, you can see that top is the only process:</p><pre>$ docker run -it --rm --name test  top -H</pre><pre>top - 08:25:00 up  7:27,  0 users,  load average: 0.00, 0.01, 0.05<br>Threads:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie<br>%Cpu(s):  0.1 us,  0.1 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st<br>KiB Mem:   2056668 total,  1616832 used,   439836 free,    99352 buffers<br>KiB Swap:  1441840 total,        0 used,  1441840 free.  1324440 cached Mem</pre><pre>  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND<br>    1 root      20   0   19744   2336   2080 R  0.0  0.1   0:00.04 top</pre><p>To examine the result further, you can use docker exec:</p><pre>$ docker exec -it test ps aux</pre><pre>USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND<br>root         1  2.6  0.1  19752  2352 ?        Ss+  08:24   0:00 top -b -H<br>root         7  0.0  0.1  15572  2164 ?        R+   08:25   0:00 ps aux</pre><p>And you can gracefully request top to shut down using docker stop test.</p><p>The following Dockerfile shows using the ENTRYPOINT to run Apache in the foreground (i.e., as PID 1):</p><pre>FROM debian:stable<br>RUN apt-get update &amp;&amp; apt-get install -y --force-yes apache2<br>EXPOSE 80 443<br>VOLUME [&quot;/var/www&quot;, &quot;/var/log/apache2&quot;, &quot;/etc/apache2&quot;]<br>ENTRYPOINT [&quot;/usr/sbin/apache2ctl&quot;, &quot;-D&quot;, &quot;FOREGROUND&quot;]</pre><p>If you need to write a starter script for a single executable, you can ensure that the final executable receives the Unix signals by using exec and gosu commands:</p><pre>#!/usr/bin/env bash<br>set -e</pre><pre>if [ &quot;$1&quot; = &#39;postgres&#39; ]; then<br>    chown -R postgres &quot;$PGDATA&quot;</pre><pre>    if [ -z &quot;$(ls -A &quot;$PGDATA&quot;)&quot; ]; then<br>        gosu postgres initdb<br>    fi</pre><pre>    exec gosu postgres &quot;$@&quot;<br>fi</pre><pre>exec &quot;$@&quot;</pre><p>Lastly, if you need to do some extra cleanup (or communicate with other containers) on shutdown, or are co-ordinating more than one executable, you may need to ensure that the ENTRYPOINT script receives the Unix signals, passes them on, and then does some more work:</p><pre>#!/bin/sh<br># Note: I&#39;ve written this using sh so it works in the busybox container too</pre><pre># USE the trap if you need to also do manual cleanup after the service is stopped,<br>#     or need to start multiple services in the one container<br>trap &quot;echo TRAPed signal&quot; HUP INT QUIT TERM</pre><pre># start service in background here<br>/usr/sbin/apachectl start</pre><pre>echo &quot;[hit enter key to exit] or run &#39;docker stop &lt;container&gt;&#39;&quot;<br>read</pre><pre># stop service and clean up here<br>echo &quot;stopping apache&quot;<br>/usr/sbin/apachectl stop</pre><pre>echo &quot;exited $0&quot;</pre><p>If you run this image with docker run -it --rm -p 80:80 --name test apache, you can then examine the container’s processes with docker exec, or docker top, and then ask the script to stop Apache:</p><pre>$ docker exec -it test ps aux</pre><pre>USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND<br>root         1  0.1  0.0   4448   692 ?        Ss+  00:42   0:00 /bin/sh /run.sh 123 cmd cmd2<br>root        19  0.0  0.2  71304  4440 ?        Ss   00:42   0:00 /usr/sbin/apache2 -k start<br>www-data    20  0.2  0.2 360468  6004 ?        Sl   00:42   0:00 /usr/sbin/apache2 -k start<br>www-data    21  0.2  0.2 360468  6000 ?        Sl   00:42   0:00 /usr/sbin/apache2 -k start<br>root        81  0.0  0.1  15572  2140 ?        R+   00:44   0:00 ps aux</pre><pre>$ docker top test</pre><pre>PID                 USER                COMMAND<br>10035               root                {run.sh} /bin/sh /run.sh 123 cmd cmd2<br>10054               root                /usr/sbin/apache2 -k start<br>10055               33                  /usr/sbin/apache2 -k start<br>10056               33                  /usr/sbin/apache2 -k start</pre><pre>$ /usr/bin/time docker stop test</pre><pre>test<br>real	0m 0.27s<br>user	0m 0.03s<br>sys	0m 0.03s</pre><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>You can override the </em><em>ENTRYPOINT setting using </em><em>--entrypoint, but this can only set the binary to </em>exec<em> (no </em><em>sh -c will be used).</em></blockquote><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>The </em>exec<em> form is parsed as a JSON array, which means that you must use double-quotes (“) around words not single-quotes (‘).</em></blockquote><p>Unlike the <em>shell</em> form, the <em>exec</em> form does not invoke a command shell. This means that normal shell processing does not happen. For example, ENTRYPOINT [ &quot;echo&quot;, &quot;$HOME&quot; ] will not do variable substitution on $HOME. If you want shell processing then either use the <em>shell</em> form or execute a shell directly, for example: ENTRYPOINT [ &quot;sh&quot;, &quot;-c&quot;, &quot;echo $HOME&quot; ]. When using the exec form and executing a shell directly, as in the case for the shell form, it is the shell that is doing the environment variable expansion, not docker.</p><h3>Shell form ENTRYPOINT example</h3><p>You can specify a plain string for the ENTRYPOINT and it will execute in /bin/sh -c. This form will use shell processing to substitute shell environment variables, and will ignore any CMD or docker run command line arguments. To ensure that docker stop will signal any long running ENTRYPOINT executable correctly, you need to remember to start it with exec:</p><pre>FROM ubuntu<br>ENTRYPOINT exec top -b</pre><p>When you run this image, you’ll see the single PID 1 process:</p><pre>$ docker run -it --rm --name test top</pre><pre>Mem: 1704520K used, 352148K free, 0K shrd, 0K buff, 140368121167873K cached<br>CPU:   5% usr   0% sys   0% nic  94% idle   0% io   0% irq   0% sirq<br>Load average: 0.08 0.03 0.05 2/98 6<br>  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND<br>    1     0 root     R     3164   0%   0% top -b</pre><p>Which exits cleanly on docker stop:</p><pre>$ /usr/bin/time docker stop test</pre><pre>test<br>real	0m 0.20s<br>user	0m 0.02s<br>sys	0m 0.04s</pre><p>If you forget to add exec to the beginning of your ENTRYPOINT:</p><pre>FROM ubuntu<br>ENTRYPOINT top -b<br>CMD -- --ignored-param1</pre><p>You can then run it (giving it a name for the next step):</p><pre>$ docker run -it --name test top --ignored-param2</pre><pre>top - 13:58:24 up 17 min,  0 users,  load average: 0.00, 0.00, 0.00<br>Tasks:   2 total,   1 running,   1 sleeping,   0 stopped,   0 zombie<br>%Cpu(s): 16.7 us, 33.3 sy,  0.0 ni, 50.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st<br>MiB Mem :   1990.8 total,   1354.6 free,    231.4 used,    404.7 buff/cache<br>MiB Swap:   1024.0 total,   1024.0 free,      0.0 used.   1639.8 avail Mem</pre><pre>  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND<br>    1 root      20   0    2612    604    536 S   0.0   0.0   0:00.02 sh<br>    6 root      20   0    5956   3188   2768 R   0.0   0.2   0:00.00 top</pre><p>You can see from the output of top that the specified ENTRYPOINT is not PID 1.</p><p>If you then run docker stop test, the container will not exit cleanly - the stop command will be forced to send a SIGKILL after the timeout:</p><pre>$ docker exec -it test ps waux</pre><pre>USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND<br>root         1  0.4  0.0   2612   604 pts/0    Ss+  13:58   0:00 /bin/sh -c top -b --ignored-param2<br>root         6  0.0  0.1   5956  3188 pts/0    S+   13:58   0:00 top -b<br>root         7  0.0  0.1   5884  2816 pts/1    Rs+  13:58   0:00 ps waux</pre><pre>$ /usr/bin/time docker stop test</pre><pre>test<br>real	0m 10.19s<br>user	0m 0.04s<br>sys	0m 0.03s</pre><h3>Understand how CMD and ENTRYPOINT interact</h3><p>Both CMD and ENTRYPOINT instructions define what command gets executed when running a container. There are few rules that describe their co-operation.</p><ol><li>Dockerfile should specify at least one of CMD or ENTRYPOINT commands.</li><li>ENTRYPOINT should be defined when using the container as an executable.</li><li>CMD should be used as a way of defining default arguments for an ENTRYPOINT command or for executing an ad-hoc command in a container.</li><li>CMD will be overridden when running the container with alternative arguments.</li></ol><p>The table below shows what command is executed for different ENTRYPOINT / CMD combinations:</p><p>No ENTRYPOINTENTRYPOINT exec_entry p1_entryENTRYPOINT [“exec_entry”, “p1_entry”]<strong>No CMD</strong><em>error, not allowed</em>/bin/sh -c exec_entry p1_entryexec_entry p1_entry<strong>CMD [“exec_cmd”, “p1_cmd”]</strong>exec_cmd p1_cmd/bin/sh -c exec_entry p1_entryexec_entry p1_entry exec_cmd p1_cmd<strong>CMD exec_cmd p1_cmd</strong>/bin/sh -c exec_cmd p1_cmd/bin/sh -c exec_entry p1_entryexec_entry p1_entry /bin/sh -c exec_cmd p1_cmd</p><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>If </em><em>CMD is defined from the base image, setting </em><em>ENTRYPOINT will reset </em><em>CMD to an empty value. In this scenario, </em><em>CMD must be defined in the current image to have a value.</em></blockquote><h3>VOLUME</h3><pre>VOLUME [&quot;/data&quot;]</pre><p>The VOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers. The value can be a JSON array, VOLUME [&quot;/var/log/&quot;], or a plain string with multiple arguments, such as VOLUME /var/log or VOLUME /var/log /var/db. For more information/examples and mounting instructions via the Docker client, refer to <a href="https://docs.docker.com/storage/volumes/"><em>Share Directories via Volumes</em></a> documentation.</p><p>The docker run command initializes the newly created volume with any data that exists at the specified location within the base image. For example, consider the following Dockerfile snippet:</p><pre>FROM ubuntu<br>RUN mkdir /myvol<br>RUN echo &quot;hello world&quot; &gt; /myvol/greeting<br>VOLUME /myvol</pre><p>This Dockerfile results in an image that causes docker run to create a new mount point at /myvol and copy the greeting file into the newly created volume.</p><h3>Notes about specifying volumes</h3><p>Keep the following things in mind about volumes in the Dockerfile.</p><ul><li><strong>Volumes on Windows-based containers</strong>: When using Windows-based containers, the destination of a volume inside the container must be one of:</li><li>a non-existing or empty directory</li><li>a drive other than C:</li><li><strong>Changing the volume from within the Dockerfile</strong>: If any build steps change the data within the volume after it has been declared, those changes will be discarded.</li><li><strong>JSON formatting</strong>: The list is parsed as a JSON array. You must enclose words with double quotes (&quot;) rather than single quotes (&#39;).</li><li><strong>The host directory is declared at container run-time</strong>: The host directory (the mountpoint) is, by its nature, host-dependent. This is to preserve image portability, since a given host directory can’t be guaranteed to be available on all hosts. For this reason, you can’t mount a host directory from within the Dockerfile. The VOLUME instruction does not support specifying a host-dir parameter. You must specify the mountpoint when you create or run the container.</li></ul><h3>USER</h3><pre>USER &lt;user&gt;[:&lt;group&gt;]</pre><p>or</p><pre>USER &lt;UID&gt;[:&lt;GID&gt;]</pre><p>The USER instruction sets the user name (or UID) and optionally the user group (or GID) to use as the default user and group for the remainder of the current stage. The specified user is used for RUN instructions and at runtime, runs the relevant ENTRYPOINT and CMD commands.</p><blockquote><em>Note that when specifying a group for the user, the user will have </em>only<em> the specified group membership. Any other configured group memberships will be ignored.</em></blockquote><blockquote><strong><em>Warning</em></strong></blockquote><blockquote><em>When the user doesn’t have a primary group then the image (or the next instructions) will be run with the </em><em>root group.</em></blockquote><blockquote><em>On Windows, the user must be created first if it’s not a built-in account. This can be done with the </em><em>net user command called as part of a Dockerfile.</em></blockquote><pre>FROM microsoft/windowsservercore<br># Create Windows user in the container<br>RUN net user /add patrick<br># Set it for subsequent commands<br>USER patrick</pre><h3>WORKDIR</h3><pre>WORKDIR /path/to/workdir</pre><p>The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn’t exist, it will be created even if it’s not used in any subsequent Dockerfile instruction.</p><p>The WORKDIR instruction can be used multiple times in a Dockerfile. If a relative path is provided, it will be relative to the path of the previous WORKDIR instruction. For example:</p><pre>WORKDIR /a<br>WORKDIR b<br>WORKDIR c<br>RUN pwd</pre><p>The output of the final pwd command in this Dockerfile would be /a/b/c.</p><p>The WORKDIR instruction can resolve environment variables previously set using ENV. You can only use environment variables explicitly set in the Dockerfile. For example:</p><pre>ENV DIRPATH=/path<br>WORKDIR $DIRPATH/$DIRNAME<br>RUN pwd</pre><p>The output of the final pwd command in this Dockerfile would be /path/$DIRNAME</p><p>If not specified, the default working directory is /. In practice, if you aren’t building a Dockerfile from scratch (FROM scratch), the WORKDIR may likely be set by the base image you’re using.</p><p>Therefore, to avoid unintended operations in unknown directories, it is best practice to set your WORKDIR explicitly.</p><h3>ARG</h3><pre>ARG &lt;name&gt;[=&lt;default value&gt;]</pre><p>The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg &lt;varname&gt;=&lt;value&gt; flag. If a user specifies a build argument that was not defined in the Dockerfile, the build outputs a warning.</p><pre>[Warning] One or more build-args [foo] were not consumed.</pre><p>A Dockerfile may include one or more ARG instructions. For example, the following is a valid Dockerfile:</p><pre>FROM busybox<br>ARG user1<br>ARG buildno<br># ...</pre><blockquote><strong><em>Warning:</em></strong></blockquote><blockquote><em>It is not recommended to use build-time variables for passing secrets like GitHub keys, user credentials etc. Build-time variable values are visible to any user of the image with the </em><em>docker history command.</em></blockquote><blockquote><em>Refer to the </em><a href="https://docs.docker.com/engine/reference/builder/#run---mounttypesecret"><em>RUN --mount=type=secret</em></a><em> section to learn about secure ways to use secrets when building images.</em></blockquote><h3>Default values</h3><p>An ARG instruction can optionally include a default value:</p><pre>FROM busybox<br>ARG user1=someuser<br>ARG buildno=1<br># ...</pre><p>If an ARG instruction has a default value and if there is no value passed at build-time, the builder uses the default.</p><h3>Scope</h3><p>An ARG variable definition comes into effect from the line on which it is defined in the Dockerfile not from the argument’s use on the command-line or elsewhere. For example, consider this Dockerfile:</p><pre>FROM busybox<br>USER ${username:-some_user}<br>ARG username<br>USER $username<br># ...</pre><p>A user builds this file by calling:</p><pre>$ docker build --build-arg username=what_user .</pre><p>The USER at line 2 evaluates to some_user as the username variable is defined on the subsequent line 3. The USER at line 4 evaluates to what_user, as the username argument is defined and the what_user value was passed on the command line. Prior to its definition by an ARG instruction, any use of a variable results in an empty string.</p><p>An ARG instruction goes out of scope at the end of the build stage where it was defined. To use an argument in multiple stages, each stage must include the ARG instruction.</p><pre>FROM busybox<br>ARG SETTINGS<br>RUN ./run/setup $SETTINGS</pre><pre>FROM busybox<br>ARG SETTINGS<br>RUN ./run/other $SETTINGS</pre><h3>Using ARG variables</h3><p>You can use an ARG or an ENV instruction to specify variables that are available to the RUN instruction. Environment variables defined using the ENV instruction always override an ARG instruction of the same name. Consider this Dockerfile with an ENV and ARG instruction.</p><pre>FROM ubuntu<br>ARG CONT_IMG_VER<br>ENV CONT_IMG_VER=v1.0.0<br>RUN echo $CONT_IMG_VER</pre><p>Then, assume this image is built with this command:</p><pre>$ docker build --build-arg CONT_IMG_VER=v2.0.1 .</pre><p>In this case, the RUN instruction uses v1.0.0 instead of the ARG setting passed by the user:v2.0.1 This behavior is similar to a shell script where a locally scoped variable overrides the variables passed as arguments or inherited from environment, from its point of definition.</p><p>Using the example above but a different ENV specification you can create more useful interactions between ARG and ENV instructions:</p><pre>FROM ubuntu<br>ARG CONT_IMG_VER<br>ENV CONT_IMG_VER=${CONT_IMG_VER:-v1.0.0}<br>RUN echo $CONT_IMG_VER</pre><p>Unlike an ARG instruction, ENV values are always persisted in the built image. Consider a docker build without the --build-arg flag:</p><pre>$ docker build .</pre><p>Using this Dockerfile example, CONT_IMG_VER is still persisted in the image but its value would be v1.0.0 as it is the default set in line 3 by the ENV instruction.</p><p>The variable expansion technique in this example allows you to pass arguments from the command line and persist them in the final image by leveraging the ENV instruction. Variable expansion is only supported for <a href="https://docs.docker.com/engine/reference/builder/#environment-replacement">a limited set of Dockerfile instructions.</a></p><h3>Predefined ARGs</h3><p>Docker has a set of predefined ARG variables that you can use without a corresponding ARG instruction in the Dockerfile.</p><ul><li>HTTP_PROXY</li><li>http_proxy</li><li>HTTPS_PROXY</li><li>https_proxy</li><li>FTP_PROXY</li><li>ftp_proxy</li><li>NO_PROXY</li><li>no_proxy</li><li>ALL_PROXY</li><li>all_proxy</li></ul><p>To use these, pass them on the command line using the --build-arg flag, for example:</p><pre>$ docker build --build-arg HTTPS_PROXY=https://my-proxy.example.com .</pre><p>By default, these pre-defined variables are excluded from the output of docker history. Excluding them reduces the risk of accidentally leaking sensitive authentication information in an HTTP_PROXY variable.</p><p>For example, consider building the following Dockerfile using --build-arg HTTP_PROXY=http://user:pass@proxy.lon.example.com</p><pre>FROM ubuntu<br>RUN echo &quot;Hello World&quot;</pre><p>In this case, the value of the HTTP_PROXY variable is not available in the docker history and is not cached. If you were to change location, and your proxy server changed to http://user:pass@proxy.sfo.example.com, a subsequent build does not result in a cache miss.</p><p>If you need to override this behaviour then you may do so by adding an ARG statement in the Dockerfile as follows:</p><pre>FROM ubuntu<br>ARG HTTP_PROXY<br>RUN echo &quot;Hello World&quot;</pre><p>When building this Dockerfile, the HTTP_PROXY is preserved in the docker history, and changing its value invalidates the build cache.</p><h3>Automatic platform ARGs in the global scope</h3><p>This feature is only available when using the <a href="https://docs.docker.com/build/buildkit/">BuildKit</a> backend.</p><p>Docker predefines a set of ARG variables with information on the platform of the node performing the build (build platform) and on the platform of the resulting image (target platform). The target platform can be specified with the --platform flag on docker build.</p><p>The following ARG variables are set automatically:</p><ul><li>TARGETPLATFORM - platform of the build result. Eg linux/amd64, linux/arm/v7, windows/amd64.</li><li>TARGETOS - OS component of TARGETPLATFORM</li><li>TARGETARCH - architecture component of TARGETPLATFORM</li><li>TARGETVARIANT - variant component of TARGETPLATFORM</li><li>BUILDPLATFORM - platform of the node performing the build.</li><li>BUILDOS - OS component of BUILDPLATFORM</li><li>BUILDARCH - architecture component of BUILDPLATFORM</li><li>BUILDVARIANT - variant component of BUILDPLATFORM</li></ul><p>These arguments are defined in the global scope so are not automatically available inside build stages or for your RUN commands. To expose one of these arguments inside the build stage redefine it without value.</p><p>For example:</p><pre>FROM alpine<br>ARG TARGETPLATFORM<br>RUN echo &quot;I&#39;m building for $TARGETPLATFORM&quot;</pre><h3>BuildKit built-in build args</h3><p>ArgTypeDescriptionBUILDKIT_CACHE_MOUNT_NSStringSet optional cache ID namespace.BUILDKIT_CONTEXT_KEEP_GIT_DIRBoolTrigger git context to keep the .git directory.BUILDKIT_INLINE_CACHE<a href="https://docs.docker.com/engine/reference/builder/#fn:2">2</a>BoolInline cache metadata to image config or not.BUILDKIT_MULTI_PLATFORMBoolOpt into determnistic output regardless of multi-platform output or not.BUILDKIT_SANDBOX_HOSTNAMEStringSet the hostname (default buildkitsandbox)BUILDKIT_SYNTAXStringSet frontend imageSOURCE_DATE_EPOCHIntSet the UNIX timestamp for created image and layers. More info from <a href="https://reproducible-builds.org/docs/source-date-epoch/">reproducible builds</a>. Supported since Dockerfile 1.5, BuildKit 0.11</p><h4>Example: keep .git dir</h4><p>When using a Git context, .git dir is not kept on git checkouts. It can be useful to keep it around if you want to retrieve git information during your build:</p><pre># syntax=docker/dockerfile:1<br>FROM alpine<br>WORKDIR /src<br>RUN --mount=target=. \<br>  make REVISION=$(git rev-parse HEAD) build</pre><pre>$ docker build --build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 https://github.com/user/repo.git#main</pre><h3>Impact on build caching</h3><p>ARG variables are not persisted into the built image as ENV variables are. However, ARG variables do impact the build cache in similar ways. If a Dockerfile defines an ARG variable whose value is different from a previous build, then a “cache miss” occurs upon its first usage, not its definition. In particular, all RUN instructions following an ARG instruction use the ARG variable implicitly (as an environment variable), thus can cause a cache miss. All predefined ARG variables are exempt from caching unless there is a matching ARG statement in the Dockerfile.</p><p>For example, consider these two Dockerfile:</p><pre>FROM ubuntu<br>ARG CONT_IMG_VER<br>RUN echo $CONT_IMG_VER</pre><pre>FROM ubuntu<br>ARG CONT_IMG_VER<br>RUN echo hello</pre><p>If you specify --build-arg CONT_IMG_VER=&lt;value&gt; on the command line, in both cases, the specification on line 2 does not cause a cache miss; line 3 does cause a cache miss.ARG CONT_IMG_VER causes the RUN line to be identified as the same as running CONT_IMG_VER=&lt;value&gt; echo hello, so if the &lt;value&gt; changes, we get a cache miss.</p><p>Consider another example under the same command line:</p><pre>FROM ubuntu<br>ARG CONT_IMG_VER<br>ENV CONT_IMG_VER=$CONT_IMG_VER<br>RUN echo $CONT_IMG_VER</pre><p>In this example, the cache miss occurs on line 3. The miss happens because the variable’s value in the ENV references the ARG variable and that variable is changed through the command line. In this example, the ENV command causes the image to include the value.</p><p>If an ENV instruction overrides an ARG instruction of the same name, like this Dockerfile:</p><pre>FROM ubuntu<br>ARG CONT_IMG_VER<br>ENV CONT_IMG_VER=hello<br>RUN echo $CONT_IMG_VER</pre><p>Line 3 does not cause a cache miss because the value of CONT_IMG_VER is a constant (hello). As a result, the environment variables and values used on the RUN (line 4) doesn’t change between builds.</p><h3>ONBUILD</h3><pre>ONBUILD &lt;INSTRUCTION&gt;</pre><p>The ONBUILD instruction adds to the image a <em>trigger</em> instruction to be executed at a later time, when the image is used as the base for another build. The trigger will be executed in the context of the downstream build, as if it had been inserted immediately after the FROM instruction in the downstream Dockerfile.</p><p>Any build instruction can be registered as a trigger.</p><p>This is useful if you are building an image which will be used as a base to build other images, for example an application build environment or a daemon which may be customized with user-specific configuration.</p><p>For example, if your image is a reusable Python application builder, it will require application source code to be added in a particular directory, and it might require a build script to be called <em>after</em> that. You can’t just call ADD and RUN now, because you don’t yet have access to the application source code, and it will be different for each application build. You could simply provide application developers with a boilerplate Dockerfile to copy-paste into their application, but that is inefficient, error-prone and difficult to update because it mixes with application-specific code.</p><p>The solution is to use ONBUILD to register advance instructions to run later, during the next build stage.</p><p>Here’s how it works:</p><ol><li>When it encounters an ONBUILD instruction, the builder adds a trigger to the metadata of the image being built. The instruction does not otherwise affect the current build.</li><li>At the end of the build, a list of all triggers is stored in the image manifest, under the key OnBuild. They can be inspected with the docker inspect command.</li><li>Later the image may be used as a base for a new build, using the FROM instruction. As part of processing the FROM instruction, the downstream builder looks for ONBUILD triggers, and executes them in the same order they were registered. If any of the triggers fail, the FROM instruction is aborted which in turn causes the build to fail. If all triggers succeed, the FROM instruction completes and the build continues as usual.</li><li>Triggers are cleared from the final image after being executed. In other words they are not inherited by “grand-children” builds.</li></ol><p>For example you might add something like this:</p><pre>ONBUILD ADD . /app/src<br>ONBUILD RUN /usr/local/bin/python-build --dir /app/src</pre><blockquote><strong><em>Warning</em></strong></blockquote><blockquote><em>Chaining </em><em>ONBUILD instructions using </em><em>ONBUILD ONBUILD isn’t allowed.</em></blockquote><blockquote><strong><em>Warning</em></strong></blockquote><blockquote><em>The </em><em>ONBUILD instruction may not trigger </em><em>FROM or </em><em>MAINTAINER instructions.</em></blockquote><h3>STOPSIGNAL</h3><pre>STOPSIGNAL signal</pre><p>The STOPSIGNAL instruction sets the system call signal that will be sent to the container to exit. This signal can be a signal name in the format SIG&lt;NAME&gt;, for instance SIGKILL, or an unsigned number that matches a position in the kernel’s syscall table, for instance 9. The default is SIGTERM if not defined.</p><p>The image’s default stopsignal can be overridden per container, using the --stop-signal flag on docker run and docker create.</p><h3>HEALTHCHECK</h3><p>The HEALTHCHECK instruction has two forms:</p><ul><li>HEALTHCHECK [OPTIONS] CMD command (check container health by running a command inside the container)</li><li>HEALTHCHECK NONE (disable any healthcheck inherited from the base image)</li></ul><p>The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working. This can detect cases such as a web server that is stuck in an infinite loop and unable to handle new connections, even though the server process is still running.</p><p>When a container has a healthcheck specified, it has a <em>health status</em> in addition to its normal status. This status is initially starting. Whenever a health check passes, it becomes healthy (whatever state it was previously in). After a certain number of consecutive failures, it becomes unhealthy.</p><p>The options that can appear before CMD are:</p><ul><li>--interval=DURATION (default: 30s)</li><li>--timeout=DURATION (default: 30s)</li><li>--start-period=DURATION (default: 0s)</li><li>--start-interval=DURATION (default: 5s)</li><li>--retries=N (default: 3)</li></ul><p>The health check will first run <strong>interval</strong> seconds after the container is started, and then again <strong>interval</strong> seconds after each previous check completes.</p><p>If a single run of the check takes longer than <strong>timeout</strong> seconds then the check is considered to have failed.</p><p>It takes <strong>retries</strong> consecutive failures of the health check for the container to be considered unhealthy.</p><p><strong>start period</strong> provides initialization time for containers that need time to bootstrap. Probe failure during that period will not be counted towards the maximum number of retries. However, if a health check succeeds during the start period, the container is considered started and all consecutive failures will be counted towards the maximum number of retries.</p><p><strong>start interval</strong> is the time between health checks during the start period.</p><p>There can only be one HEALTHCHECK instruction in a Dockerfile. If you list more than one then only the last HEALTHCHECK will take effect.</p><p>The command after the CMD keyword can be either a shell command (e.g. HEALTHCHECK CMD /bin/check-running) or an <em>exec</em> array (as with other Dockerfile commands; see e.g. ENTRYPOINT for details).</p><p>The command’s exit status indicates the health status of the container. The possible values are:</p><ul><li>0: success — the container is healthy and ready for use</li><li>1: unhealthy — the container is not working correctly</li><li>2: reserved — do not use this exit code</li></ul><p>For example, to check every five minutes or so that a web-server is able to serve the site’s main page within three seconds:</p><pre>HEALTHCHECK --interval=5m --timeout=3s \<br>  CMD curl -f http://localhost/ || exit 1</pre><p>To help debug failing probes, any output text (UTF-8 encoded) that the command writes on stdout or stderr will be stored in the health status and can be queried with docker inspect. Such output should be kept short (only the first 4096 bytes are stored currently).</p><p>When the health status of a container changes, a health_status event is generated with the new status.</p><h3>SHELL</h3><pre>SHELL [&quot;executable&quot;, &quot;parameters&quot;]</pre><p>The SHELL instruction allows the default shell used for the <em>shell</em> form of commands to be overridden. The default shell on Linux is [&quot;/bin/sh&quot;, &quot;-c&quot;], and on Windows is [&quot;cmd&quot;, &quot;/S&quot;, &quot;/C&quot;]. The SHELL instruction <em>must</em> be written in JSON form in a Dockerfile.</p><p>The SHELL instruction is particularly useful on Windows where there are two commonly used and quite different native shells: cmd and powershell, as well as alternate shells available including sh.</p><p>The SHELL instruction can appear multiple times. Each SHELL instruction overrides all previous SHELL instructions, and affects all subsequent instructions. For example:</p><pre>FROM microsoft/windowsservercore</pre><pre># Executed as cmd /S /C echo default<br>RUN echo default</pre><pre># Executed as cmd /S /C powershell -command Write-Host default<br>RUN powershell -command Write-Host default</pre><pre># Executed as powershell -command Write-Host hello<br>SHELL [&quot;powershell&quot;, &quot;-command&quot;]<br>RUN Write-Host hello</pre><pre># Executed as cmd /S /C echo hello<br>SHELL [&quot;cmd&quot;, &quot;/S&quot;, &quot;/C&quot;]<br>RUN echo hello</pre><p>The following instructions can be affected by the SHELL instruction when the <em>shell</em> form of them is used in a Dockerfile: RUN, CMD and ENTRYPOINT.</p><p>The following example is a common pattern found on Windows which can be streamlined by using the SHELL instruction:</p><pre>RUN powershell -command Execute-MyCmdlet -param1 &quot;c:\foo.txt&quot;</pre><p>The command invoked by docker will be:</p><pre>cmd /S /C powershell -command Execute-MyCmdlet -param1 &quot;c:\foo.txt&quot;</pre><p>This is inefficient for two reasons. First, there is an un-necessary cmd.exe command processor (aka shell) being invoked. Second, each RUN instruction in the <em>shell</em> form requires an extra powershell -command prefixing the command.</p><p>To make this more efficient, one of two mechanisms can be employed. One is to use the JSON form of the RUN command such as:</p><pre>RUN [&quot;powershell&quot;, &quot;-command&quot;, &quot;Execute-MyCmdlet&quot;, &quot;-param1 \&quot;c:\\foo.txt\&quot;&quot;]</pre><p>While the JSON form is unambiguous and does not use the un-necessary cmd.exe, it does require more verbosity through double-quoting and escaping. The alternate mechanism is to use the SHELL instruction and the <em>shell</em> form, making a more natural syntax for Windows users, especially when combined with the escape parser directive:</p><pre># escape=`</pre><pre>FROM microsoft/nanoserver<br>SHELL [&quot;powershell&quot;,&quot;-command&quot;]<br>RUN New-Item -ItemType Directory C:\Example<br>ADD Execute-MyCmdlet.ps1 c:\example\<br>RUN c:\example\Execute-MyCmdlet -sample &#39;hello world&#39;</pre><p>Resulting in:</p><pre>PS E:\myproject&gt; docker build -t shell .</pre><pre>Sending build context to Docker daemon 4.096 kB<br>Step 1/5 : FROM microsoft/nanoserver<br> ---&gt; 22738ff49c6d<br>Step 2/5 : SHELL powershell -command<br> ---&gt; Running in 6fcdb6855ae2<br> ---&gt; 6331462d4300<br>Removing intermediate container 6fcdb6855ae2<br>Step 3/5 : RUN New-Item -ItemType Directory C:\Example<br> ---&gt; Running in d0eef8386e97<br></pre><pre>    Directory: C:\<br></pre><pre>Mode         LastWriteTime              Length Name<br>----         -------------              ------ ----<br>d-----       10/28/2016  11:26 AM              Example<br></pre><pre> ---&gt; 3f2fbf1395d9<br>Removing intermediate container d0eef8386e97<br>Step 4/5 : ADD Execute-MyCmdlet.ps1 c:\example\<br> ---&gt; a955b2621c31<br>Removing intermediate container b825593d39fc<br>Step 5/5 : RUN c:\example\Execute-MyCmdlet &#39;hello world&#39;<br> ---&gt; Running in be6d8e63fe75<br>hello world<br> ---&gt; 8e559e9bf424<br>Removing intermediate container be6d8e63fe75<br>Successfully built 8e559e9bf424<br>PS E:\myproject&gt;</pre><p>The SHELL instruction could also be used to modify the way in which a shell operates. For example, using SHELL cmd /S /C /V:ON|OFF on Windows, delayed environment variable expansion semantics could be modified.</p><p>The SHELL instruction can also be used on Linux should an alternate shell be required such as zsh, csh, tcsh and others.</p><h3>Here-Documents</h3><blockquote><strong><em>Note</em></strong></blockquote><blockquote><em>Added in </em><a href="https://docs.docker.com/engine/reference/builder/#syntax"><em>docker/dockerfile:1.4</em></a></blockquote><p>Here-documents allow redirection of subsequent Dockerfile lines to the input of RUN or COPY commands. If such command contains a <a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04">here-document</a> the Dockerfile considers the next lines until the line only containing a here-doc delimiter as part of the same command.</p><h3>Example: Running a multi-line script</h3><pre># syntax=docker/dockerfile:1<br>FROM debian<br>RUN &lt;&lt;EOT bash<br>  set -ex<br>  apt-get update<br>  apt-get install -y vim<br>EOT</pre><p>If the command only contains a here-document, its contents is evaluated with the default shell.</p><pre># syntax=docker/dockerfile:1<br>FROM debian<br>RUN &lt;&lt;EOT<br>  mkdir -p foo/bar<br>EOT</pre><p>Alternatively, shebang header can be used to define an interpreter.</p><pre># syntax=docker/dockerfile:1<br>FROM python:3.6<br>RUN &lt;&lt;EOT<br>#!/usr/bin/env python<br>print(&quot;hello world&quot;)<br>EOT</pre><p>More complex examples may use multiple here-documents.</p><pre># syntax=docker/dockerfile:1<br>FROM alpine<br>RUN &lt;&lt;FILE1 cat &gt; file1 &amp;&amp; &lt;&lt;FILE2 cat &gt; file2<br>I am<br>first<br>FILE1<br>I am<br>second<br>FILE2</pre><h3>Example: Creating inline files</h3><p>In COPY commands source parameters can be replaced with here-doc indicators. Regular here-doc <a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04">variable expansion and tab stripping rules</a> apply.</p><pre># syntax=docker/dockerfile:1<br>FROM alpine<br>ARG FOO=bar<br>COPY &lt;&lt;-EOT /app/foo<br>	hello ${FOO}<br>EOT</pre><pre># syntax=docker/dockerfile:1<br>FROM alpine<br>COPY &lt;&lt;-&quot;EOT&quot; /app/script.sh<br>	echo hello ${FOO}<br>EOT<br>RUN FOO=abc ash /app/script.sh</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da3fd7540b72" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Command Line Interface (CLI) for Entity Framework Core]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://diakingdev.medium.com/the-command-line-interface-cli-for-entity-framework-core-24548eb2f3a3?source=rss-f7d7bb3c7789------2"><img src="https://cdn-images-1.medium.com/max/674/1*iw0KTS30W8Wylp-HSdAOzg.png" width="674"></a></p><p class="medium-feed-snippet">command cli entity framework core</p><p class="medium-feed-link"><a href="https://diakingdev.medium.com/the-command-line-interface-cli-for-entity-framework-core-24548eb2f3a3?source=rss-f7d7bb3c7789------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://diakingdev.medium.com/the-command-line-interface-cli-for-entity-framework-core-24548eb2f3a3?source=rss-f7d7bb3c7789------2</link>
            <guid isPermaLink="false">https://medium.com/p/24548eb2f3a3</guid>
            <category><![CDATA[entity-framework]]></category>
            <category><![CDATA[entity-framework-core]]></category>
            <category><![CDATA[ef-core]]></category>
            <dc:creator><![CDATA[diakingdev]]></dc:creator>
            <pubDate>Fri, 24 Feb 2023 10:34:57 GMT</pubDate>
            <atom:updated>2023-02-24T10:35:46.043Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Choosing Between IEnumerable and List in C#]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://diakingdev.medium.com/choosing-between-ienumerable-and-list-in-c-95f3ad6832fc?source=rss-f7d7bb3c7789------2"><img src="https://cdn-images-1.medium.com/max/753/1*lk5radO1Zry-Z19dlzIp1Q.png" width="753"></a></p><p class="medium-feed-snippet">When to Use Each IEnumerable and List</p><p class="medium-feed-link"><a href="https://diakingdev.medium.com/choosing-between-ienumerable-and-list-in-c-95f3ad6832fc?source=rss-f7d7bb3c7789------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://diakingdev.medium.com/choosing-between-ienumerable-and-list-in-c-95f3ad6832fc?source=rss-f7d7bb3c7789------2</link>
            <guid isPermaLink="false">https://medium.com/p/95f3ad6832fc</guid>
            <category><![CDATA[ienumerable]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[diakingdev]]></dc:creator>
            <pubDate>Wed, 22 Feb 2023 09:23:44 GMT</pubDate>
            <atom:updated>2023-02-22T09:23:44.149Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[What is a delegate in C# language?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">What is a delegate in C# language?</p><p class="medium-feed-link"><a href="https://diakingdev.medium.com/what-is-a-delegate-in-c-language-2c590801d663?source=rss-f7d7bb3c7789------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://diakingdev.medium.com/what-is-a-delegate-in-c-language-2c590801d663?source=rss-f7d7bb3c7789------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c590801d663</guid>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[diakingdev]]></dc:creator>
            <pubDate>Sun, 01 Jan 2023 15:01:17 GMT</pubDate>
            <atom:updated>2023-01-11T10:55:34.671Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[5 extensions VsCode for C# developer]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://diakingdev.medium.com/5-extensions-vscode-for-c-developer-eafef33a5c59?source=rss-f7d7bb3c7789------2"><img src="https://cdn-images-1.medium.com/max/1056/1*tTgnoiFGSTenqVfti_1GRg.gif" width="1056"></a></p><p class="medium-feed-snippet">5 extensions VsCode for C# developer</p><p class="medium-feed-link"><a href="https://diakingdev.medium.com/5-extensions-vscode-for-c-developer-eafef33a5c59?source=rss-f7d7bb3c7789------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://diakingdev.medium.com/5-extensions-vscode-for-c-developer-eafef33a5c59?source=rss-f7d7bb3c7789------2</link>
            <guid isPermaLink="false">https://medium.com/p/eafef33a5c59</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[visual-studio]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[vscode-extension]]></category>
            <dc:creator><![CDATA[diakingdev]]></dc:creator>
            <pubDate>Sun, 25 Dec 2022 15:54:12 GMT</pubDate>
            <atom:updated>2023-01-11T10:56:24.878Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Différence entre  et  en #]]></title>
            <link>https://diakingdev.medium.com/diff%C3%A9rence-entre-en-2e45117146db?source=rss-f7d7bb3c7789------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e45117146db</guid>
            <dc:creator><![CDATA[diakingdev]]></dc:creator>
            <pubDate>Thu, 22 Dec 2022 09:31:01 GMT</pubDate>
            <atom:updated>2022-12-22T15:40:28.606Z</atom:updated>
            <content:encoded><![CDATA[<h3>Différence entre 𝐒𝐭𝐫𝐢𝐧𝐠𝐁𝐮𝐢𝐥𝐝𝐞𝐫 et 𝐬𝐭𝐫𝐢𝐧𝐠 en 𝐂#</h3><p>Dans ce sujet, nous allons apprendre</p><ol><li>Quelle est la différence entre StringBuilder et String ?</li><li>Dans quelle situation devons-nous utiliser StringBuilder ?</li><li>Mutabilité et Immuabilité</li></ol><p><strong>StringBuilder </strong>est mutable (la valeur originale peut être changée) alors que string est immuable (la valeur originale ne changera pas).</p><p>Chaque fois que nous mettons à jour des données dans une chaîne, cela crée une nouvelle instance de l’objet. Ainsi, si vous mettez à jour la valeur 1000 fois, cela créera 1000 nouvelles instances. Alors que StringBuilder ne créera qu’un seul objet sur le tas et chaque fois qu’il sera mis à jour avec une nouvelle valeur.</p><p>Une bonne règle de base est d’utiliser les chaînes de caractères lorsque vous n’avez pas l’intention de les modifier et d’utiliser <strong>StringBuilder </strong>si vous avez l’intention de les modifier.</p><pre>// Create a new StringBuilder object.<br>StringBuilder builder = new StringBuilder();<br><br>// Append some strings to the StringBuilder.<br>builder.Append(&quot;Hello&quot;);<br>builder.Append(&quot; &quot;);<br>builder.Append(&quot;World&quot;);<br><br>// Get the final string.<br>string result = builder.ToString();</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e45117146db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Favorite Extensions in Visual Studio 2022]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://diakingdev.medium.com/my-favorite-extensions-in-visual-studio-2022-81aa802068a1?source=rss-f7d7bb3c7789------2"><img src="https://cdn-images-1.medium.com/max/1200/0*rGk0XETEKP4DX9CA" width="1200"></a></p><p class="medium-feed-snippet">Raise your productivity with this extensions</p><p class="medium-feed-link"><a href="https://diakingdev.medium.com/my-favorite-extensions-in-visual-studio-2022-81aa802068a1?source=rss-f7d7bb3c7789------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://diakingdev.medium.com/my-favorite-extensions-in-visual-studio-2022-81aa802068a1?source=rss-f7d7bb3c7789------2</link>
            <guid isPermaLink="false">https://medium.com/p/81aa802068a1</guid>
            <category><![CDATA[productivity-tools]]></category>
            <category><![CDATA[github-copilot]]></category>
            <category><![CDATA[codemaid]]></category>
            <category><![CDATA[visual-studio-2022]]></category>
            <dc:creator><![CDATA[diakingdev]]></dc:creator>
            <pubDate>Sat, 16 Apr 2022 18:10:09 GMT</pubDate>
            <atom:updated>2023-01-11T10:51:50.918Z</atom:updated>
        </item>
    </channel>
</rss>