forked from docs/doc-exports
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com> Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Dong, Qiu Jian <qiujiandong1@huawei.com> Co-committed-by: Dong, Qiu Jian <qiujiandong1@huawei.com>
65 lines
9.2 KiB
HTML
65 lines
9.2 KiB
HTML
<a name="swr_01_0006"></a><a name="swr_01_0006"></a>
|
|
|
|
<h1 class="topictitle1">Basics of the Container Engine</h1>
|
|
<div id="body1557203854783"><p id="swr_01_0006__p37106298610">The container engine, namely, Docker, is an open-source engine which allows you to create a lightweight, portable, and self-sufficient container for any application. SWR is compatible with Docker, allowing you to use Docker CLI and APIs to manage your images.</p>
|
|
<div class="section" id="swr_01_0006__section941018533817"><h4 class="sectiontitle">Installing Docker</h4><p id="swr_01_0006__p2653181093620">Before installing Docker, get a basic understanding of what Docker is and how it works. For more information, see <a href="https://docs.docker.com" target="_blank" rel="noopener noreferrer">Docker Documentation</a>.</p>
|
|
<p id="swr_01_0006__p11607163684520">Docker is compatible with almost all operating systems. Select a Docker version that best suits your needs. If you are not sure which Docker community edition to use, see <a href="https://docs.docker.com/engine/install/" target="_blank" rel="noopener noreferrer">https://docs.docker.com/engine/install/</a>.</p>
|
|
<div class="note" id="swr_01_0006__note18891114211554"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="swr_01_0006__ul1950442910221"><li id="swr_01_0006__li1450417299229">Before using SWR to store container images, ensure that the Docker client used to push images to SWR is updated to 1.11.2 or later.</li><li id="swr_01_0006__li16295103410220">Bind an elastic IP address first if your server runs in a private network as the installation requires Internet connection.</li></ul>
|
|
</div></div>
|
|
<p id="swr_01_0006__p6962162323019">On a device running Linux, run the following commands to quickly install Docker: </p>
|
|
<pre class="screen" id="swr_01_0006__screen477817526362">curl -fsSL get.docker.com -o get-docker.sh
|
|
sh get-docker.sh
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl restart docker</pre>
|
|
</div>
|
|
<div class="section" id="swr_01_0006__section135321459915"><h4 class="sectiontitle">Building a Container Image</h4><p id="swr_01_0006__p867083019912">This section walks you through the steps of using a <span class="keyword" id="swr_01_0006__keyword411894219195">Dockerfile</span> to build a container image for a simple web application. Dockerfile is a text file that contains all the instructions a user can call on the command line to build an image. A container image is a stack consisting of multiple layers. Each instruction creates a layer.</p>
|
|
<p id="swr_01_0006__p42195371019">When using a browser to access a containerized application built from a <span class="keyword" id="swr_01_0006__keyword103721052182910">Nginx image</span>, you will see the default Nginx welcome page. In this section, you will build a new image based on the <span class="keyword" id="swr_01_0006__keyword193731052182919">Nginx image</span> to change the welcome message to <span class="uicontrol" id="swr_01_0006__uicontrol14374552192919"><b>Hello, SWR!</b></span></p>
|
|
<ol id="swr_01_0006__ol3533771992"><li id="swr_01_0006__li1533177394"><span>Log in to the device running Docker as a root user.</span></li><li id="swr_01_0006__li1272171916914"><span>Run the following commands to create an empty file named <strong id="swr_01_0006__b107945020303">Dockerfile</strong>:</span><p><p id="swr_01_0006__p6230184771112"><strong id="swr_01_0006__b9326101362011">mkdir mynginx</strong></p>
|
|
<p id="swr_01_0006__p15225454121112"><strong id="swr_01_0006__b5329151315205">cd mynginx</strong></p>
|
|
<p id="swr_01_0006__p17695741899"><strong id="swr_01_0006__b733161318209">touch Dockerfile</strong></p>
|
|
</p></li><li id="swr_01_0006__li99941029598"><span><span class="keyword" id="swr_01_0006__keyword1360213715309">Edit Dockerfile</span>.</span><p><p id="swr_01_0006__p12344162812121"><strong id="swr_01_0006__b38641698207">vim Dockerfile</strong></p>
|
|
<p id="swr_01_0006__p105480330129">Add the following instructions to the Dockerfile:</p>
|
|
<pre class="screen" id="swr_01_0006__screen638115311124">FROM nginx
|
|
RUN echo '<h1>Hello,SWR!</h1>' > /usr/share/nginx/html/index.html</pre>
|
|
<p id="swr_01_0006__p18409771">In the preceding instructions:</p>
|
|
<ul id="swr_01_0006__ul31470215"><li id="swr_01_0006__li14796483"><strong id="swr_01_0006__b1154218154309">FROM</strong>: creates a layer from the base image. A valid Dockerfile must start with a <strong id="swr_01_0006__b10543915173014">FROM</strong> instruction. In this example, the <strong id="swr_01_0006__b175431715103012">Nginx</strong> image is used as the base image.</li><li id="swr_01_0006__li66059488"><strong id="swr_01_0006__b16171021123015">RUN</strong>: executes a command to create a new layer. One of its syntax forms is RUN <command>. In this example, the <strong id="swr_01_0006__b219421103020">echo</strong> command is executed to display <span class="uicontrol" id="swr_01_0006__uicontrol1220182183016"><b>Hello, SWR!</b></span></li></ul>
|
|
<p id="swr_01_0006__p5718163414418">Save the changes and exit.</p>
|
|
</p></li><li id="swr_01_0006__li13537715151216"><span>Run <strong id="swr_01_0006__b1720474218338">docker build</strong> [<em id="swr_01_0006__i13232142254917">option</em>] <<em id="swr_01_0006__i17956127184914">context path</em>> to build an image.</span><p><p id="swr_01_0006__p136952232010"><strong id="swr_01_0006__b38309612013">docker build -t nginx:v1 .</strong></p>
|
|
<ul id="swr_01_0006__ul1058016118434"><li id="swr_01_0006__li458020174318"><strong id="swr_01_0006__b12302115204">-t nginx:v1</strong>: specifies the image name and tag.</li><li id="swr_01_0006__li832914364312"><strong id="swr_01_0006__b21841314142018">.</strong>: indicates the path where the Dockerfile is located. All contents in this path are packed and sent to the Docker to build an image.</li></ul>
|
|
</p></li><li id="swr_01_0006__li459642612342"><span>Run the following command to check the created image. The command output shows that the nginx image has been created with a tag of v1.</span><p><p id="swr_01_0006__p1568995516343"><strong id="swr_01_0006__b18896105763419">docker images</strong></p>
|
|
</p></li></ol>
|
|
</div>
|
|
<div class="section" id="swr_01_0006__section3433103111126"><h4 class="sectiontitle">Creating an Image Package</h4><p id="swr_01_0006__p205811336191215">This section describes how to compress a container image into a <span class="keyword" id="swr_01_0006__keyword1627514431206">.tar</span> or <span class="keyword" id="swr_01_0006__keyword528394316203">.tar.gz</span> package.</p>
|
|
<ol id="swr_01_0006__ol18363637102613"><li id="swr_01_0006__li43632374266"><span>Log in to the device running Docker as a root user.</span></li><li id="swr_01_0006__li79031238202613"><span>Run the following command to list images.</span><p><p id="swr_01_0006__p14797209162715"><strong id="swr_01_0006__b16921162214134">docker images</strong></p>
|
|
<p id="swr_01_0006__p1021252082713">Check the name and tag of the image to be compressed.</p>
|
|
</p></li><li id="swr_01_0006__li1451117192717"><span>Run the following command to compress the image into a package.</span><p><p id="swr_01_0006__p919564717279"><strong id="swr_01_0006__b116000388322">docker save [OPTIONS] IMAGE [IMAGE...]</strong></p>
|
|
<div class="note" id="swr_01_0006__note3506058192"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="swr_01_0006__p689215193012"><strong id="swr_01_0006__b18969353172013">OPTIONS</strong>: You can set this to <strong id="swr_01_0006__b19975153172011">--output</strong> or <strong id="swr_01_0006__b189766532204">-o</strong>, indicating that the image is exported to a file.</p>
|
|
<p id="swr_01_0006__p138971932181910">The file should be in either .tar or .tar.gz.</p>
|
|
</div></div>
|
|
<p id="swr_01_0006__p855117239243">Sample:</p>
|
|
<pre class="screen" id="swr_01_0006__screen167864518337">$ docker save nginx:latest > nginx.tar
|
|
$ ls -sh nginx.tar
|
|
108M nginx.tar
|
|
|
|
$ docker save php:5-apache > php.tar.gz
|
|
$ ls -sh php.tar.gz
|
|
372M php.tar.gz
|
|
|
|
$ docker save --output nginx.tar nginx
|
|
$ ls -sh nginx.tar
|
|
108M nginx.tar
|
|
|
|
$ docker save -o nginx-all.tar nginx
|
|
$ docker save -o nginx-latest.tar nginx:latest</pre>
|
|
</p></li></ol>
|
|
</div>
|
|
<div class="section" id="swr_01_0006__section91019326453"><h4 class="sectiontitle">Importing an Image File</h4><p id="swr_01_0006__p526190114619">This section describes how to import an image package as an image using the <strong id="swr_01_0006__b6344142292014">docker load</strong> command.</p>
|
|
<p id="swr_01_0006__p369014461525">There are two modes:</p>
|
|
<p id="swr_01_0006__p569024617525"><strong id="swr_01_0006__b11981742102010">docker load < </strong><strong id="swr_01_0006__b14982742142014"><em id="swr_01_0006__i2981124216204">Path/File name.tar</em></strong></p>
|
|
<p id="swr_01_0006__p069054605218"><strong id="swr_01_0006__b191434657852744">docker load --input </strong><strong id="swr_01_0006__b214128217552744"><em id="swr_01_0006__i7251233352744">Path/File name.tar</em></strong> or <strong id="swr_01_0006__b13579767752744">docker load -i </strong><strong id="swr_01_0006__b78479332852744"><em id="swr_01_0006__i153361380852744">Path/File name.tar</em></strong></p>
|
|
<p id="swr_01_0006__p1569084695210">Sample:</p>
|
|
<pre class="screen" id="swr_01_0006__screen18601429105914">$ docker load --input fedora.tar</pre>
|
|
</div>
|
|
</div>
|
|
|