<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hussain Sajib</title>
    <description>The latest articles on DEV Community by Hussain Sajib (@hussainislam).</description>
    <link>https://dev.to/hussainislam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F408507%2Fd9b535eb-dade-4daa-a6b6-d746d4d81bb8.jpeg</url>
      <title>DEV Community: Hussain Sajib</title>
      <link>https://dev.to/hussainislam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hussainislam"/>
    <language>en</language>
    <item>
      <title>Django Fixtures: seeding databases</title>
      <dc:creator>Hussain Sajib</dc:creator>
      <pubDate>Thu, 28 Jan 2021 15:46:08 +0000</pubDate>
      <link>https://dev.to/hussainislam/django-fixtures-seeding-databases-5ai</link>
      <guid>https://dev.to/hussainislam/django-fixtures-seeding-databases-5ai</guid>
      <description>&lt;p&gt;When we create an application or project in Django, we would need to test the features of the application. The best way to test is to use realistic data that would mean something to the developer. That way we would be able to better understand how the application is truly works. So, we would need data in our database; but if we are building an application from scratch the data may not be readily available and the database would be completely empty. Even if we have older databases, we might need to transfer our data to the newer one. That is when 'Fixtures' come into play.&lt;/p&gt;

&lt;p&gt;Fixtures are collections of data that can be read by Django and loaded into it's database. Fixtures can also be used or created to store existing data. So, in essence, fixtures are a way for Django to export and import data into the database. Although there are packages that can help with this, like &lt;a href="https://pypi.org/project/django-seed/" rel="noopener noreferrer"&gt;django-seed&lt;/a&gt;, I wanted to do it the manual way to actually understand how it works and to seed with data that is more relevant to my project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Supported Format and Data structures
&lt;/h2&gt;

&lt;p&gt;Django currently supports three formats:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;JSON&lt;/li&gt;
&lt;li&gt;XML&lt;/li&gt;
&lt;li&gt;YAML&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Django expects the fixtures to follow a specific pattern. Any pattern other than that would result in error. For JSON the pattern would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;This&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;is&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;official&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;documentation&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"myapp.person"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"pk"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"fields"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"first_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"last_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Lennon"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"myapp.person"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"pk"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"fields"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"first_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Paul"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"last_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"McCartney"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's have a look at what this means. First of all, with the angle brackets indicate that this is an array. Then the curly braces and the key-value pairs indicate the things inside the array are JSON objects. Then each of the objects has exactly three keys: model, pk, and fields. The model indicates the where the model is located scoped by the app name: &lt;code&gt;&amp;lt;app_name&amp;gt;.&amp;lt;model_name&amp;gt;&lt;/code&gt;. The pk indicates what the value of the primary key would be. I used UUID v4 as my primary key. So, I used &lt;a href="https://www.uuidgenerator.net/" rel="noopener noreferrer"&gt;this site&lt;/a&gt; to manually generate the UUIDs for me. There are many other sites that lets you generate bunch of UUIDs in one shot. Note that if you use UUID, it's value should be with in quotations. Finally, the fields property contains all the names of the fields and their respective values. That's it!!&lt;/p&gt;

&lt;p&gt;The same information can be put into a YAML and that would look like following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;myapp.person&lt;/span&gt;
  &lt;span class="na"&gt;pk&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
  &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;first_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;John&lt;/span&gt;
    &lt;span class="na"&gt;last_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Lennon&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;myapp.person&lt;/span&gt;
  &lt;span class="na"&gt;pk&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
  &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;first_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Paul&lt;/span&gt;
    &lt;span class="na"&gt;last_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;McCartney&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The XML fixture is little bit different compared to JSON and YML, apart from it being XML, it need to have some additional meta data. For example: version number with 'django-objects' and type of value in field. The same data that we have already seen would look like following in XML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;django-objects&lt;/span&gt; &lt;span class="na"&gt;version=&lt;/span&gt;&lt;span class="s"&gt;"1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;object&lt;/span&gt; &lt;span class="na"&gt;pk=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt; &lt;span class="na"&gt;model=&lt;/span&gt;&lt;span class="s"&gt;"myapp.person"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;field&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"CharField"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"first_name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;John&lt;span class="nt"&gt;&amp;lt;/field&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;field&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"CharField"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"last_name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lennon&lt;span class="nt"&gt;&amp;lt;/field&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/object&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;object&lt;/span&gt; &lt;span class="na"&gt;pk=&lt;/span&gt;&lt;span class="s"&gt;"2"&lt;/span&gt; &lt;span class="na"&gt;model=&lt;/span&gt;&lt;span class="s"&gt;"myap.person"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;field&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"CharField"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"first_name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Paul&lt;span class="nt"&gt;&amp;lt;/field&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;field&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"CharField"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"last_name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;McCartney&lt;span class="nt"&gt;&amp;lt;/field&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/object&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/django-objects&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Location of the fixtures
&lt;/h2&gt;

&lt;p&gt;There are three ways that Django can find fixtures in a project. Those are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;App Scoped&lt;/strong&gt;: By default, Django searches for fixtures directory inside an application. This is where it would look first. For this to work, we would need to create a new directory inside the app and call it 'fixtures'. Then we can store our fixtures specific to that app in that directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Project Scoped&lt;/strong&gt;: We can store all our fixtures in project-level as well. This would require us to create a directory called 'fixtures' in project root level. Then we need to add the &lt;code&gt;FIXTURE_DIRS&lt;/code&gt; settings in our &lt;code&gt;settings.py&lt;/code&gt; file to point to the locations where the fixtures are stored. Django will search the locations indicated with this setting in addition to the app-scoped directories. This would look like this:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;FIXTURE_DIRS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;fixtures&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the setting &lt;code&gt;FIXTURE_DIRS&lt;/code&gt; expects a list of locations.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Command Prompt&lt;/strong&gt;: We can also tell Django to search a particular location or file by adding an option to the command we would run to load the data. For example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python manage.py loaddata location/to/your/data.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Commands
&lt;/h2&gt;

&lt;p&gt;Thus far we have been talking mostly about loading data into database but we can also generate the fixtures automatically, if we already have some data in the database (the 'export' feature that we talked about. So, there are basically two commands to deal with the fixtures and they are:&lt;/p&gt;

&lt;h3&gt;
  
  
  Loading data
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;loaddata&lt;/code&gt; is used to load data into the database. There are few ways that we can do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# specify the file location, name, and extension&lt;/span&gt;
python manage.py loaddata location/to/the/file/data.json

&lt;span class="c"&gt;# specify the file name and extension&lt;/span&gt;
python manage.py loaddata data.json

&lt;span class="c"&gt;#specify just the file name&lt;/span&gt;
python manage.py loaddata data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I believe this would need little bit of explanation. In the first command we specified a pathname, filename, and extensioin. Django would look for this file in all the 'fixture' directories that we have defined before. So, if we have a 'fixtures' directory at the root of our project, with this command Django will look for the directory structure (&lt;code&gt;location/to/the/file/&lt;/code&gt;) and the filename inside that structure with appropriate extension. In the second command, there's no pathname; so, Django will look for the filename and extension in any of the locations specified. In the third command, Django will look for any file with filename inside the specified locations; the extensions wouldn't matter in this case. Just to note here, if we specify the extension of the fixture, Django will call the specific &lt;code&gt;serializer&lt;/code&gt; to deserialize the data first. If we don't specify the extension, then Django will look for the file first and call the &lt;code&gt;serializer&lt;/code&gt; based on the extension of the file found.&lt;/p&gt;

&lt;p&gt;There are options that we can add to our &lt;code&gt;loaddata&lt;/code&gt; command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--database &amp;lt;db_name&amp;gt;&lt;/code&gt;: specifies the database where the data will be loaded. By default, this will use the &lt;code&gt;default&lt;/code&gt; database specified in the &lt;code&gt;settings.py&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--app &amp;lt;app_name&amp;gt;&lt;/code&gt;: specifies the app where to look for the fixtures&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--format &amp;lt;format_name&amp;gt;&lt;/code&gt;: specifies the serialization format (json/xml/yaml)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--exclude &amp;lt;file_name&amp;gt;&lt;/code&gt;: specifies any file that should be excluded from loading&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Dumping data
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;dumpdata&lt;/code&gt; is used to generate fixtures. The command would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python manage.py dumpdata &amp;lt;app_label&amp;gt;.&amp;lt;model_name&amp;gt; &amp;lt;app_label&amp;gt;.&amp;lt;model_name&amp;gt; &lt;span class="nt"&gt;--format&lt;/span&gt; &amp;lt;format_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I guess the command if pretty self-explanatory. We need to call the &lt;code&gt;dumpdata&lt;/code&gt; command with the model name scoped to the app's label that has the model. We would also want to specify the format in which we want the data. There are some other options that we can add this command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--all&lt;/code&gt; or &lt;code&gt;-a&lt;/code&gt;: dumps all data using Django's default Model Manager.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--indent &amp;lt;indent_size&amp;gt;&lt;/code&gt;: specifies the size of the indent in integer format&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--exclude &amp;lt;file_name&amp;gt;&lt;/code&gt;: specifies any app or model that should be excluded from the dump&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--database &amp;lt;db_name&amp;gt;&lt;/code&gt;: specifies the name of the database&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--pks [list of primary keys]&lt;/code&gt;: specifies the primary keys that would be dumped; applicable for one model only.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--output &amp;lt;file_name&amp;gt;&lt;/code&gt;: specifies the file name where the data will be dumped.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  seed data for the whole project
&lt;/h2&gt;

&lt;p&gt;If we need to seed data from multiple fixtures, executing the command again and again is not efficient. We can deal with this running a command that loads all the fixtures, using the wild card characters.&lt;/p&gt;

&lt;p&gt;The command would look like following where it is loading all the json files inside the 'fixtures' directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py loaddata fixtures/*.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This solution is taken from &lt;a href="https://stackoverflow.com/a/2229073/10031472" rel="noopener noreferrer"&gt;this&lt;/a&gt; stackoverflow comment&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For further reading, refer to Django &lt;a href="https://docs.djangoproject.com/en/3.1/howto/initial-data/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Cover photo by &lt;a href="https://unsplash.com/@goumbik?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Lukas Blazek&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/data?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

</description>
      <category>django</category>
      <category>fixtures</category>
      <category>seeding</category>
      <category>database</category>
    </item>
    <item>
      <title>Dockerfile reference summary</title>
      <dc:creator>Hussain Sajib</dc:creator>
      <pubDate>Thu, 05 Nov 2020 19:48:03 +0000</pubDate>
      <link>https://dev.to/hussainislam/dockerfile-reference-summary-39e2</link>
      <guid>https://dev.to/hussainislam/dockerfile-reference-summary-39e2</guid>
      <description>&lt;h1&gt;
  
  
  Dockerfile Reference
&lt;/h1&gt;

&lt;p&gt;First of all, this is just the summary that I did from the original Dockerfile refernece found on Docker website. Then, let me admit that I am pretty new to Docker. I have been playing around with it for the last few days. One thing I must admit is that  the learning curve for Docker was pretty steep for me. There were a lot of concepts to learn. However, the prospective benefits of using it were far greater. One of the key benefits of Docker I found was ability to deploy applications in different types of platforms without worring much about it. This also gave me the opportunity to share my code with my friends who would be able to run the application with minimum effort. &lt;/p&gt;

&lt;p&gt;If you are not familiar to Docker and it's concepts, this might not be the article for you. This article summarizes the references required for writing the &lt;code&gt;Dockerfile&lt;/code&gt;. The official documentation can be found the Docker website. This is however my "go-to" document for quick reference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Purpose of Dockerfile
&lt;/h2&gt;

&lt;p&gt;Docker uses &lt;code&gt;Dockerfile&lt;/code&gt; to build images automatically. It is a text file without any extensions that contains all the commands that a user can call on the command line to build an image. The command &lt;code&gt;docker build&lt;/code&gt; builds an image from two things: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;Dockerfile&lt;/code&gt; and &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;context&lt;/code&gt;: it is processed recursively. The &lt;code&gt;context&lt;/code&gt; is a set of files at specified location. While building the image, entire &lt;code&gt;context&lt;/code&gt; is sent to the &lt;code&gt;Docker daemon&lt;/code&gt;. The &lt;code&gt;context&lt;/code&gt; can be either:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;PATH&lt;/code&gt;: a directory in the local filesystem. This can include subdirectories&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;URL&lt;/code&gt;: a Git repository location. This can include repository and submodules
To use a file in the build context, &lt;code&gt;Dockerfile&lt;/code&gt; refers to the file specified in an instruction (ie. &lt;code&gt;COPY&lt;/code&gt;). We can use a &lt;code&gt;.dockerignore&lt;/code&gt; file to improve the build performance by excluding some of the files or directories.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Convention: &lt;code&gt;Dockerfile&lt;/code&gt; is usually called &lt;code&gt;Dockerfile&lt;/code&gt; and located at the root of the context. However, &lt;code&gt;-f&lt;/code&gt; flag can be used with &lt;code&gt;docker build&lt;/code&gt; to specify another &lt;code&gt;Dockerfile&lt;/code&gt;. For example:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-f&lt;/span&gt; /path/to/a/Dockerfile &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each instruction in the &lt;code&gt;Dockerfile&lt;/code&gt; is run separately to create a new image. However, Docker will reuse intermediate images (cache) to accelerate build process, which is indicated by the &lt;code&gt;Using cache&lt;/code&gt; message in the output console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Format of Instructions
&lt;/h2&gt;

&lt;p&gt;Commands in &lt;code&gt;Dockerfile&lt;/code&gt; is written in instruction-arguments method. So, there will be an instruction and along with it will be some arguments. Instructions are NOT case-sensitive but convention is to use uppercase.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;must begin with a &lt;code&gt;FROM&lt;/code&gt; instruction&lt;/li&gt;
&lt;li&gt;Comments start with &lt;code&gt;#&lt;/code&gt; sign and are removed from the file before executing the commands&lt;/li&gt;
&lt;li&gt;leading whitespace are ignored but discouraged
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;        &lt;span class="c1"&gt;# this is a comment-line&lt;/span&gt;
    &lt;span class="s"&gt;RUN echo hello&lt;/span&gt;
&lt;span class="s"&gt;RUN echo world&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Parser directives must be at the top of the file; before the &lt;code&gt;FROM&lt;/code&gt; instruction&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Environment Replacement
&lt;/h2&gt;

&lt;p&gt;Environment Variables can be used in certain instructions as variables to be interpreted by &lt;code&gt;Dockerfile&lt;/code&gt;. Environment variable can be notated in &lt;code&gt;Dockerfile&lt;/code&gt; with &lt;code&gt;$variable_name&lt;/code&gt; or &lt;code&gt;${variable_name}&lt;/code&gt;. However, latter is applicable in case like: &lt;code&gt;${foo}_bar&lt;/code&gt;. Environment Variable is supported by: &lt;code&gt;ADD&lt;/code&gt;, &lt;code&gt;COPY&lt;/code&gt;, &lt;code&gt;ENV&lt;/code&gt;, &lt;code&gt;EXPOSE&lt;/code&gt;, &lt;code&gt;FROM&lt;/code&gt;, &lt;code&gt;LABEL&lt;/code&gt;,&lt;code&gt;STOPSIGNAL&lt;/code&gt;, &lt;code&gt;USER&lt;/code&gt;, &lt;code&gt;VOLUME&lt;/code&gt;, &lt;code&gt;WORKDIR&lt;/code&gt;, and &lt;code&gt;ONBUILD&lt;/code&gt;. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;FROM busybox&lt;/span&gt;
&lt;span class="s"&gt;ENV FOO=/bar&lt;/span&gt;
&lt;span class="s"&gt;WORKDIR ${FOO}&lt;/span&gt;   &lt;span class="c1"&gt;# WORKDIR /bar&lt;/span&gt;
&lt;span class="s"&gt;ADD . $FOO&lt;/span&gt;       &lt;span class="c1"&gt;# ADD . /bar&lt;/span&gt;
&lt;span class="s"&gt;COPY \$FOO /quux&lt;/span&gt; &lt;span class="c1"&gt;# COPY $FOO /quux&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;.dockerignore&lt;/code&gt; file
&lt;/h2&gt;

&lt;p&gt;Before sending context to docker daemon, docker CLI looks for &lt;code&gt;.dockerignore&lt;/code&gt; file in the root of context. If it exists, CLI excludes the files and directories. CLI interprets the file as newline-separated list of patterns. Rules of &lt;code&gt;.dockerignore&lt;/code&gt; file:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rule&lt;/th&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;#text&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This is considered comment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*/temp*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Excludes file and directories starting with 'temp' in immediate subdirectory of root&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*/*/temp*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Excludes file and directories starting with 'temp' in two levels below root&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;temp?&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Excludes files and directores starting with 'temp' that are in root&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*.md&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exclude all markdown files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;!README.md&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exclude all file except &lt;code&gt;README.md&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: if &lt;code&gt;Dockerfile&lt;/code&gt; and &lt;code&gt;.dockerignore&lt;/code&gt; are added to the &lt;code&gt;.dockerignore&lt;/code&gt; file, they NOT copied to the image but are still sent to the daemon.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;FROM&lt;/code&gt; Instruction
&lt;/h2&gt;

&lt;p&gt;This instruciton initializes a new build stage and sets the Base Image for the subsequent instructions. A valid &lt;code&gt;Dockerfile&lt;/code&gt; must start with a &lt;code&gt;FROM&lt;/code&gt; instruction. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ARG&lt;/code&gt; is the only instruction that may precede &lt;code&gt;FROM&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;FROM&lt;/code&gt; can appear multiple times in one &lt;code&gt;Dockerfile&lt;/code&gt; to create multiple images or use one build stage as dependency for another. Each &lt;code&gt;FROM&lt;/code&gt; instruction clears any state created by previous instructions&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt; can be used in subsequent &lt;code&gt;FROM&lt;/code&gt; or &lt;code&gt;COPY --from=&amp;lt;name&amp;gt;&lt;/code&gt; instructions&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tag&lt;/code&gt; or &lt;code&gt;digest&lt;/code&gt; values are optional. By default, builder assumes &lt;code&gt;latest&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Examples:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;FROM [--platform=&amp;lt;platform&amp;gt;] &amp;lt;image&amp;gt; [AS &amp;lt;name&amp;gt;]&lt;/span&gt;
&lt;span class="s"&gt;or&lt;/span&gt;
&lt;span class="s"&gt;FROM [--platform=&amp;lt;platform&amp;gt;] &amp;lt;image&amp;gt;[:&amp;lt;tag&amp;gt;] [AS &amp;lt;name&amp;gt;]&lt;/span&gt;
&lt;span class="s"&gt;or&lt;/span&gt;
&lt;span class="s"&gt;FROM [--platform=&amp;lt;platform&amp;gt;] &amp;lt;image&amp;gt;[@&amp;lt;digest&amp;gt;] [AS &amp;lt;name&amp;gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;ARG&lt;/code&gt; and &lt;code&gt;FROM&lt;/code&gt; working together
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;FROM&lt;/code&gt; supports variables that are declared by &lt;code&gt;ARG&lt;/code&gt; instruction preceding the &lt;code&gt;FROM&lt;/code&gt;. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ARG CODE_VERSION=latest
FROM base:${CODE_VERSION}
CMD /code/run-app

from extras:${CODE_VERSION}
CMD /code/run-extras
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ARG&lt;/code&gt; declared before &lt;code&gt;FROM&lt;/code&gt; is usually not available to instructions after the &lt;code&gt;FROM&lt;/code&gt;. To make it available, we need to add the &lt;code&gt;ARG&lt;/code&gt; instruction and variable name after the &lt;code&gt;FROM&lt;/code&gt; without a value. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ARG VERSION=latest
FROM busybox:$VERSION
ARG VERSION
RUN echo $VERSION &amp;gt; image_version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;RUN&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;This instruction runs the commands in a new layer on the current image and commits the results. It has two forms:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;RUN &amp;lt;command&amp;gt;&lt;/code&gt; (shell form): 

&lt;ul&gt;
&lt;li&gt;Backslash &lt;code&gt;\&lt;/code&gt; can be used to continue writing commands in the following line&lt;/li&gt;
&lt;li&gt;Default shell can be changed using the &lt;code&gt;SHELL&lt;/code&gt; command&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RUN ["executable", "param1", "param2"]&lt;/code&gt; (exec form): 

&lt;ul&gt;
&lt;li&gt;Double quotes must be used for commands passed as string&lt;/li&gt;
&lt;li&gt;To change the default shell pass the target shell in first command: &lt;code&gt;RUN ["/bin/bash", "-c", "echo hello"]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Variable substitution doesn't happen by default. For variable substitution: &lt;code&gt;RUN [ "sh", "-c", "echo $HOME" ]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;CMD&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;The main purpose for this instruction is the provide defaults for an execurint container. These defaults can include or exclude the executable. If it excludes, then must specify an &lt;code&gt;ENTRYPOINT&lt;/code&gt; instruction. There can be only one &lt;code&gt;CMD&lt;/code&gt; instruction in a &lt;code&gt;Dockerfile&lt;/code&gt;. If there are multiple &lt;code&gt;CMD&lt;/code&gt; instructions, the last one will take effect. This instruction has three forms:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;CMD command param1 param2&lt;/code&gt; (shell form):&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CMD ["executable","param1","param2"]&lt;/code&gt; (exec form): Similar to exec form of &lt;code&gt;RUN&lt;/code&gt;. This is the preferred format for &lt;code&gt;CMD&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CMD ["param1","param2"]&lt;/code&gt; (default parameters to ENTRYPOINT): If you would like your container to run the same executable every time, then you should consider using &lt;code&gt;ENTRYPOINT&lt;/code&gt; in combination with &lt;code&gt;CMD&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: &lt;code&gt;RUN&lt;/code&gt; vs &lt;code&gt;CMD&lt;/code&gt;. &lt;code&gt;RUN&lt;/code&gt; actually runs a command and commits the result; &lt;code&gt;CMD&lt;/code&gt; does not execute anything at build time, but specifies the intended command for the image.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;LABEL&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This instruction adds metadata to an image. The instruction adds a key-value pair to the image. Multiple labels can be added under one single instruction. Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LABEL multi.label1="value1" multi.label2="value2" other="value3"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;LABEL&lt;/code&gt;s in the parent images are inherited in the subsequent images. If a label exists with multiple values, the latest one override all previous values.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;EXPOSE&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This instruction informs that the container listens to a specific network port at runtime. &lt;/li&gt;
&lt;li&gt;TCP or UDP can be specified but TCP is default. &lt;/li&gt;
&lt;li&gt;Doesn't actually publish the port but works as a documentation between the person building image and person running container&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;-p&lt;/code&gt; flag on &lt;code&gt;docker run&lt;/code&gt; to publish and map one or more ports: &lt;code&gt;docker run -p 80:80/tcp -p 80:80/udp&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;-P&lt;/code&gt; flag to publish all exposed ports and map them to high-order ports&lt;/li&gt;
&lt;li&gt;Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EXPOSE 80/tcp
EXPOSE 80/udp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;docker network&lt;/code&gt; command supports creating networks for communication among containers without exposing ports&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;ENV&lt;/code&gt; instuction
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This instruction sets environment variable that will be available in all subsequent instuction in the build stage.&lt;/li&gt;
&lt;li&gt;Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ENV MY_NAME="John Doe"
ENV MY_DOG=Rex\ The\ Dog
ENV MY_CAT=fluffy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Allows multiple key-value variables to be set at one time:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ENV MY_NAME="John Doe" MY_DOG=Rex\ The\ Dog \
    MY_CAT=fluffy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Environment variables set using this instruction will persist when a container is run from the resulting image. Check the values using &lt;code&gt;docker inspect&lt;/code&gt;; change values using &lt;code&gt;docker run -env &amp;lt;key&amp;gt;=&amp;lt;value&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Environment variable persistence can lead to side effects&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If environment variable is needed only during build, use either of the following methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;set value of a single command: &lt;code&gt;RUN DEBIAN_FRONTEND=noninteractive apt-get update &amp;amp;&amp;amp; apt-get install -y ...&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;ARG&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y ...
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Alternative syntax (doesn't allow setting multiple variables in one line):&lt;br&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ENV MY_VAR my-value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;ADD&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This instruction copies new files/directories from source to the desination&lt;/li&gt;
&lt;li&gt;It has two forms:

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;ADD [--chown=&amp;lt;user&amp;gt;:&amp;lt;group&amp;gt;] &amp;lt;src&amp;gt;... &amp;lt;dest&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ADD [--chown=&amp;lt;user&amp;gt;:&amp;lt;group&amp;gt;] ["&amp;lt;src&amp;gt;",... "&amp;lt;dest&amp;gt;"]&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: &lt;code&gt;--chown&lt;/code&gt; is supported only for Linux containers.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;This instruction takes local files, URLs, and &lt;code&gt;tar&lt;/code&gt; files as source&lt;/li&gt;
&lt;li&gt;Multiple sources may be specified but there address will be interpreted as relative to the source of context of the build&lt;/li&gt;
&lt;li&gt;Sources may contain wildcards&lt;/li&gt;
&lt;li&gt;Destination is absolute path or path relative to &lt;code&gt;WORKDIR&lt;/code&gt; (where the sources will be copied)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ADD test.txt relativeDir/       # copies test.txt to &amp;lt;WORKDIR&amp;gt;/relativeDir/
ADD test.txt /absoluteDir/      # copies test.txt to /absoluteDir/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;All new files and directories are created with UID and GID of 0 (unless &lt;code&gt;--chown&lt;/code&gt; mentioned)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ADD --chown=55:mygroup files* /somedir/
ADD --chown=bin files* /somedir/
ADD --chown=1 files* /somedir/
ADD --chown=10:11 files* /somedir/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;source directory must be inside the context of the build; you cannot &lt;code&gt;ADD ../something /something&lt;/code&gt;, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.&lt;/li&gt;
&lt;li&gt;if source is a directory, the entire contents of the directory are copied including filesystem metadata (the directory itself is not copied).&lt;/li&gt;
&lt;li&gt;if source is a local tar archive in identity/gzip/bzip2/xy format then it is unpacked as a directory with &lt;code&gt;tar -x&lt;/code&gt; behavior. &lt;/li&gt;
&lt;li&gt;if multiple sources are specified, destination must be a directory and must end with forward slash &lt;code&gt;/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;if destination does not end with a trailing slash, it will be considered a regular file and the contents of source will be written at destination.&lt;/li&gt;
&lt;li&gt;if desitnaton doesn't exist, it is created along with all missing directories&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;COPY&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This is similar to &lt;code&gt;ADD&lt;/code&gt; instuction but takes only local files as source and copies to docker image.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nickjanetakis.com/blog/docker-tip-2-the-difference-between-copy-and-add-in-a-dockerile" rel="noopener noreferrer"&gt;&lt;code&gt;ADD&lt;/code&gt; vs &lt;code&gt;COPY&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;ENTRYPOINT&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This allows us to configure a container that will run as an executable.&lt;/li&gt;
&lt;li&gt;This has two forms:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. `ENTRYPOINT ["executable", "param1", "param2"]` (exec form): `docker run &amp;lt;image&amp;gt;` will be appended after all elements and override all elements specified using `CMD`. 
2. `ENTRYPOINT command param1 param2` (shell form): prevents `CMD` or `run` command line arguments to be passed. `ENTRYPOINT` will be started as a subcommand of `/bin/sh -c`, which doesn't pass signals. This means that the executable will be the container's `PID 1` and will not receive unix signals. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Only the last &lt;code&gt;ENTRYPOINT&lt;/code&gt; will have effect&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How &lt;code&gt;CMD&lt;/code&gt; and &lt;code&gt;ENTRYPOINT&lt;/code&gt; interact
&lt;/h3&gt;

&lt;p&gt;Both of these instructions define what command gets executed when running a container. The rules regarding interaction of these two are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Dockerfile&lt;/code&gt; should specify at least one of &lt;code&gt;CMD&lt;/code&gt; or &lt;code&gt;ENTRYPOINT&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ENTRYPOINT&lt;/code&gt; should be defined when using container as an executable&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CMD&lt;/code&gt; should be used to define default arguments for an &lt;code&gt;ENTRYPOINT&lt;/code&gt; or executing ad-hoc commands&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CMD&lt;/code&gt; will be overriden when container is run with alternative arguments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The combinations of &lt;code&gt;CMD&lt;/code&gt; and &lt;code&gt;ENTRYPOINT&lt;/code&gt; are following:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Combinations&lt;/th&gt;
&lt;th&gt;No &lt;code&gt;ENTRYPOINT&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;&lt;code&gt;ENTRYPOINT exec_entry p1_entry&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;ENTRYPOINT [“exec_entry”, “p1_entry”]&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No &lt;code&gt;CMD&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;error, not allowed&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/bin/sh -c exec_entry p1_entry&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;exec_entry p1_entry&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CMD [“exec_cmd”, “p1_cmd”]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;exec_cmd p1_cmd&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/bin/sh -c exec_entry p1_entry&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;exec_entry p1_entry exec_cmd p1_cmd&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CMD [“p1_cmd”, “p2_cmd”]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;p1_cmd p2_cmd&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;/&lt;code&gt;bin/sh -c exec_entry p1_entry&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;exec_entry p1_entry p1_cmd p2_cmd&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CMD exec_cmd p1_cmd&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/bin/sh -c exec_cmd p1_cmd&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/bin/sh -c exec_entry p1_entry&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;exec_entry p1_entry /bin/sh -c exec_cmd p1_cmd&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: If &lt;code&gt;CMD&lt;/code&gt; is defined in base image, setting &lt;code&gt;ENTRYPOINT&lt;/code&gt; will reset &lt;code&gt;CMD&lt;/code&gt; to empty. So, &lt;code&gt;CMD&lt;/code&gt; must be redefined in current image to have a value&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Resource: &lt;a href="https://phoenixnap.com/kb/docker-cmd-vs-entrypoint#:~:text=ENTRYPOINT%20is%20the%20other%20instruction,to%20the%20docker%20run%20command." rel="noopener noreferrer"&gt;Docker CMD Vs Entrypoint Commands: What's The Difference?&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;VOLUME&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;This creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The value of this instruction can be:

&lt;ol&gt;
&lt;li&gt;JSON array: &lt;code&gt;VOLUME ["/var/log/"]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Plain string: &lt;code&gt;VOLUME /var/log /var/db&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Windows based containers must have volumes that are non-exiting or empty directory and a drive other than &lt;code&gt;C:&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If any build steps change the data within the volume after it has been declared, those changes will be discarded&lt;/li&gt;
&lt;li&gt;The host directory is, by nature, host-dependent. This is to preserve image portability because a given host directory can't be guaranteed to be available on all hosts. That's why we can't mount host directory from within &lt;code&gt;Dockerfile&lt;/code&gt;. We must specify the mountpoint when we create or run the container.&lt;/li&gt;
&lt;li&gt;Resource: &lt;a href="https://docs.docker.com/storage/volumes/" rel="noopener noreferrer"&gt;Use Volumes&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;USER&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;This instruction sets the username or UID and optionally the user group (or GID) to use when running the image and for &lt;code&gt;RUN&lt;/code&gt;, &lt;code&gt;CMD&lt;/code&gt;, and &lt;code&gt;ENTRYPOINT&lt;/code&gt; instructions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instruction format:

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;USER &amp;lt;user&amp;gt;[:&amp;lt;groups&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;USER &amp;lt;UID&amp;gt;[:&amp;lt;GID&amp;gt;]&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;If group/GID is specified, other group/GID will ignored&lt;/li&gt;
&lt;li&gt;Default group is &lt;code&gt;root&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;On Windows, the user must be created first with &lt;code&gt;net user&lt;/code&gt; command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM microsoft/windowsservercore
# Create Windows user in the container
RUN net user /add patrick
# Set it for subsequent commands
USER patrick
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;WORKDIR&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;This sets the working directory for any &lt;code&gt;RUN&lt;/code&gt;, &lt;code&gt;CMD&lt;/code&gt;, &lt;code&gt;ENTRYPOINT&lt;/code&gt;, &lt;code&gt;COPY&lt;/code&gt;, and &lt;code&gt;ADD&lt;/code&gt; instructions. If it doesn't exist, it will be created even if it's not used in any subsequent &lt;code&gt;Dockerfile&lt;/code&gt; instruction.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can be declared multiple times. If relative path is provided, it will be relative to previous path provided&lt;/li&gt;
&lt;li&gt;This can resolve environment variables&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;ARG&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;This instruction defines a variable that users can pass at build-time to the builder with the &lt;code&gt;docker build&lt;/code&gt; command with &lt;code&gt;--build-arg &amp;lt;var&amp;gt;=&amp;lt;value&amp;gt;&lt;/code&gt; flag. A &lt;code&gt;Dockerfile&lt;/code&gt; may include one or more instructions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM busybox
ARG user1=someuser      # default value
ARG buildno             # without any value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;ARG&lt;/code&gt; variable is available fromt the line it is declared not from where it is used. An &lt;code&gt;ARG&lt;/code&gt; goes out of scope at the end of the build stage where it is defined.&lt;/li&gt;
&lt;li&gt;Useful interaction between &lt;code&gt;ARG&lt;/code&gt; and &lt;code&gt;ENV&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM ubuntu
ARG CONT_IMG_VER
ENV CONT_IMG_VER=${CONT_IMG_VER:-v1.0.0}
RUN echo $CONT_IMG_VER`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Predefined &lt;code&gt;ARGs&lt;/code&gt;: &lt;code&gt;HTTP_PROXY&lt;/code&gt;, &lt;code&gt;http_proxy&lt;/code&gt;, &lt;code&gt;HTTPS_PROXY&lt;/code&gt;, &lt;code&gt;https_proxy&lt;/code&gt;, &lt;code&gt;FTP_PROXY&lt;/code&gt;, &lt;code&gt;ftp_proxy&lt;/code&gt;, &lt;code&gt;NO_PROXY&lt;/code&gt;, and &lt;code&gt;no_proxy&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Automatic Platform &lt;code&gt;ARG&lt;/code&gt; (only available with BuildKit backend): These are not available inside build stage. To make these available add &lt;code&gt;ARG &amp;lt;arg_name&amp;gt;&lt;/code&gt; to &lt;code&gt;Dockerfile&lt;/code&gt;.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;TARGETPLATFORM&lt;/code&gt;: platform of the build result&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TARGETOS&lt;/code&gt;: OS component of &lt;code&gt;TARGETPLATFORM&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TARGETARCH&lt;/code&gt;: architecture component of &lt;code&gt;TARGETPLATFORM&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TARGETVARIANT&lt;/code&gt;: variant component of &lt;code&gt;TARGETPLATFORM&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BUILDPLATFORM&lt;/code&gt;: platform of the node performing build&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BUILDOS&lt;/code&gt;: OS component of &lt;code&gt;BUILDPLATFORM&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BUILDARCH&lt;/code&gt;: architecture component of &lt;code&gt;BUILDPLATFORM&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BUILDVARIANT&lt;/code&gt;: variant component of &lt;code&gt;BUILDPLATFORM&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;ONBUILD&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;This adds a trigger instruction to the image, which would be executed at a later time, when the image is used as the base for another build. Any build instruction can be registered as a trigger. Format of the instruction: &lt;code&gt;ONBUILD &amp;lt;instruction&amp;gt;&lt;/code&gt;. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ONBUILD ADD . /app/src
ONBUILD RUN /usr/local/bin/python-build --dir /app/src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The way it works:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;When encourted &lt;code&gt;ONBUILD&lt;/code&gt; instruction, the builder adds a trigger to the metadata of the image being built&lt;/li&gt;
&lt;li&gt;After the build, a list of all triggers are stored in image manifest under the key &lt;code&gt;OnBuild&lt;/code&gt; and can be inspected with &lt;code&gt;docker inspect&lt;/code&gt; command.&lt;/li&gt;
&lt;li&gt;The image can be used as base for another build using the &lt;code&gt;FROM&lt;/code&gt; instruction. As part of processing the &lt;code&gt;FROM&lt;/code&gt;, the downstream builder looks for &lt;code&gt;ONBUILD&lt;/code&gt; triggers and executes them in the same order they are registered. &lt;/li&gt;
&lt;li&gt;Triggers are cleared from final image after being executed (not inherited by "grand-children" builds)&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: Chaining &lt;code&gt;ONBUILD&lt;/code&gt; with &lt;code&gt;ONBUILD&lt;/code&gt; is not allowed: &lt;code&gt;ONBUILD ONBUILD&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: May not trigger &lt;code&gt;FROM&lt;/code&gt; and &lt;code&gt;MAINTAINER&lt;/code&gt; instructions&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;STOPSIGNAL&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;This sets the system call signal that will be sent to the container to exit. This can be valid unsigned number that matches a position in the kernel's syscall table (ex: 9) or signal name (ex: SIGKILL).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;HEALTHCHECK&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;This tells docker how to test a container to check that it is still working. This can be used in cases like web server in infinite loop. When &lt;code&gt;HEALTHCHECK&lt;/code&gt; is specified, it has a health status in addition to normal status. There can be only one &lt;code&gt;HEALTHCHECK&lt;/code&gt; instruction in a &lt;code&gt;Dockerfile&lt;/code&gt;. If multiple are mentioned, only the last one is taken into consideration. The health statuses can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;starting&lt;/code&gt; initial stage&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;healthy&lt;/code&gt; when health check passes&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;unhealthy&lt;/code&gt; after a certain number of consecutive failures&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The options that can appear before &lt;code&gt;CMD&lt;/code&gt; are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--interval=DURATION&lt;/code&gt; (default 30s) [frequency of running the checks]&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--timeout=DURATION&lt;/code&gt; (default 30s) [how much time to wait before a check is considered failed]&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--start-period=DURATION&lt;/code&gt; (default 0s) [initialization time for containers that need time to bootstrap]&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--retries=N&lt;/code&gt; (default 3) [consicutive failures to consider the container &lt;code&gt;unhealthy&lt;/code&gt;]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The command after the &lt;code&gt;CMD&lt;/code&gt; keyword can be either a shell command (&lt;code&gt;HEALTHCHECK CMD /bin/check-running&lt;/code&gt;) or an exec array (similar to &lt;code&gt;ENTRYPOINT&lt;/code&gt;). Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HEALTHCHECK --interval=5m --timeout=3s \
  CMD curl -f http://localhost/ || exit 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To debug failing probes, all output of the command are stored in health status and can be queried with &lt;code&gt;docker inspect&lt;/code&gt; command. When the health status changes, a &lt;code&gt;health_status&lt;/code&gt; event is triggered with new status.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;SHELL&lt;/code&gt; instruction
&lt;/h2&gt;

&lt;p&gt;This instruction allows the default shell to be overridden. The default shell on Linux is &lt;code&gt;["/bin/sh", "-c"]&lt;/code&gt; and on Windows is &lt;code&gt;["cmd", "/S", "/C"]&lt;/code&gt;. This command is particularly important for Windows because a user can choose between: &lt;code&gt;cmd&lt;/code&gt;, &lt;code&gt;powershell&lt;/code&gt; and sometimes &lt;code&gt;sh&lt;/code&gt;. This can appear multiple times and each time it overrides the previous ones. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SHELL ["/bin/sh", "-c"]
SHELL ["cmd", "/S", "/C"]
SHELL ["powershell", "-command"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  External Implementation and BuildKit
&lt;/h2&gt;

&lt;p&gt;Starting from 18.09, Docker supports a new backend for building images, which is provided by &lt;a href="https://github.com/moby/buildkit" rel="noopener noreferrer"&gt;moby/buildkit&lt;/a&gt;. There are some additional features that comes with this BuildKit. The documentation for this can be found &lt;a href="https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Official Dockerfile reference - &lt;a href="https://docs.docker.com/engine/reference/builder/" rel="noopener noreferrer"&gt;https://docs.docker.com/engine/reference/builder/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;BuildKit - &lt;a href="https://github.com/moby/buildkit" rel="noopener noreferrer"&gt;https://github.com/moby/buildkit&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>docker</category>
    </item>
  </channel>
</rss>
