{"id":304414,"date":"2020-05-28T15:00:32","date_gmt":"2020-05-28T15:00:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=304414"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=304414","title":{"rendered":"\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434 docker pull \u0438 docker push \u0431\u0435\u0437 docker \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/504314\/\">\n<p>\u0423 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e <del>2 \u043c\u0435\u0448\u043a\u0430 \u0442\u0440\u0430\u0432\u044b, 75 \u0442\u0430\u0431\u043b\u0435\u0442\u043e\u043a \u043c\u0435\u0441\u043a\u0430\u043b\u0438\u043d\u0430<\/del> unix environment, docker \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b docker pull \u0438 docker push \u0431\u0435\u0437 \u0434\u043e\u043a\u0435\u0440 \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/mv\/a1\/9d\/mva19dlfjox7sohuv4jjpca0p4u.jpeg\"\/><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 \u044d\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b<br \/>  \u0418\u0442\u0430\u043a \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f docker pull? \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/docs.docker.com\/engine\/reference\/commandline\/pull\/\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>:<\/p>\n<p>  <\/p>\n<blockquote><p>&quot;Pull an image or a repository from a registry&quot;.<\/p><\/blockquote>\n<p>\u0422\u0430\u043c \u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <a href=\"https:\/\/docs.docker.com\/storage\/storagedriver\/\">understand images, containers, and storage drivers<\/a>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/np\/o6\/rk\/npo6rkmwp8gdhlq2a0z9tmq-fec.jpeg\"\/><\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u0447\u0442\u043e docker image \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u043d\u0435\u043a\u0438\u0445 layers, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0432 \u0438\u043c\u0435\u0434\u0436\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u043d\u044b. \u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 <a href=\"https:\/\/docs.docker.com\/registry\/spec\/api\/#pulling-an-image\">registry API<\/a>.<br \/>  \u0417\u0434\u0435\u0441\u044c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  <\/p>\n<blockquote><p>&quot;An \u201cimage\u201d is a combination of a JSON manifest and individual layer files. The process of pulling an &gt; image centers around retrieving these two components.&quot;<\/p><\/blockquote>\n<p>\u0418\u0442\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u044d\u0442\u043e \u201c<strong>Pulling an Image Manifest<\/strong>\u201d<br \/>  \u041f\u0443\u043b\u0438\u0442\u044c \u043c\u044b \u0435\u0433\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043d\u0435\u0433\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b. \u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430: <code>GET \/v2\/{name}\/manifests\/{reference}<\/code><\/p>\n<p>  <\/p>\n<blockquote><p>&quot;The name and reference parameter identify the image and are required. The reference may include a tag or digest.&quot;<\/p><\/blockquote>\n<p>\u041d\u0430\u0448 \u0434\u043e\u043a\u0435\u0440 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">curl -s -X GET &quot;http:\/\/localhost:8081\/link\/to\/docker\/registry\/v2\/centos-11-10\/manifests\/1.1.1&quot; -H &quot;header_if_needed&quot;<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ur\/2s\/n9\/ur2sn9qhj3vh9ope6yg3njkjuq4.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0412 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c json \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0435\u0440\u044b, \u0442\u043e\u0447\u043d\u0435\u0435 \u0438\u0445 \u0445\u044d\u0448\u0438. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0438\u0445, \u043c\u043e\u0436\u0435\u043c \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441: &quot;GET \/v2\/{name}\/blobs\/{digest}&quot;<\/p>\n<p>  <\/p>\n<blockquote><p>\u201cAccess to a layer will be gated by the name of the repository but is identified uniquely in the registry by digest.\u201d<\/p><\/blockquote>\n<p>digest \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438 \u0435\u0441\u0442\u044c \u0445\u044d\u0448, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0431\u0443\u0435\u043c <\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">curl -s -X GET &quot;http:\/\/localhost:8081\/link\/to\/docker\/registry\/v2\/centos-11-10\/blobs\/sha256:f972d139738dfcd1519fd2461815651336ee25a8b54c358834c50af094bb262f&quot; -H &quot;header_if_needed&quot; --output firstLayer<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/u5\/jv\/fj\/u5jvfjyh-xvnemsiemenm_mpcyi.png\"\/><\/p>\n<p>  <\/p>\n<p>\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u0437\u0430 \u0444\u0430\u0439\u043b \u043c\u044b \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043b\u0435\u0435\u0440\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">file firstLayer<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/up\/ye\/uh\/upyeuhr0wj74w5z0xd-h7io2kjg.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0442.\u0435. \u043b\u0435\u0435\u0440\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f tar \u0430\u0440\u0445\u0438\u0432\u044b, \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u0430\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0438\u043c\u0435\u0434\u0436\u0430.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0431\u0430\u0448 \u0441\u043a\u0440\u0438\u043f\u0442 \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0451 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">#!\/bin\/bash -eu  downloadDir=$1 # url as http:\/\/localhost:8081\/link\/to\/docker\/registry url=$2 imageName=$3 tag=$4  # array of layers layers=($(curl -s -X GET &quot;$url\/v2\/$imageName\/manifests\/$tag&quot; | grep -oP '(?&lt;=blobSum&quot; : &quot;).+(?=&quot;)'))  # download each layer from array for layer in &quot;${layers[@]}&quot;; do     echo &quot;Downloading ${layer}&quot;     curl -v -X GET &quot;$url\/v2\/$imageName\/blobs\/$layer&quot; --output &quot;$downloadDir\/$layer.tar&quot; done  # find all layers, untar them and remove source .tar files cd &quot;$downloadDir&quot; &amp;&amp; find . -name &quot;sha256:*&quot; -exec tar xvf {} \\; rm sha256:*.tar exit 0<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0441 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0438\u043c\u0435\u0434\u0436\u0430<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">.\/script.sh dirName \u201chttp:\/\/localhost:8081\/link\/to\/docker\/registry\u201d myAwesomeImage 1.0<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"chast-2---docker-push\">\u0427\u0430\u0441\u0442\u044c 2 \u2014 docker push<\/h4>\n<p>  <\/p>\n<p>\u0422\u0443\u0442 \u0431\u0443\u0434\u0435\u0442 \u0447\u0443\u0442\u044c \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435.<br \/>  \u041d\u0430\u0447\u043d\u0435\u043c \u043e\u043f\u044f\u0442\u044c \u0441 <a href=\"https:\/\/docs.docker.com\/registry\/spec\/api\/#pushing-an-image\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u0418\u0442\u0430\u043a \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u043b\u0435\u0435\u0440, \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442 \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0435\u0433\u043e \u0442\u043e\u0436\u0435. \u0412\u0440\u043e\u0434\u0435 \u0437\u0432\u0443\u0447\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>  <\/p>\n<p>\u0418\u0437\u0443\u0447\u0438\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0433\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u2014 &quot;POST \/v2\/{repoName}\/blobs\/uploads\/&quot;<\/li>\n<li>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u0435\u0435\u0440\u0430 (\u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043d\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443, \u0442.\u0435. \u043a\u0430\u0436\u0434\u044b\u0439 \u043b\u0435\u0435\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0446\u0435\u043b\u0438\u043a\u043e\u043c) \u2014 &quot;PUT \/v2\/{repoName}\/blobs\/uploads\/{uuid}?digest={digest}<br \/>  Content-Length: {size of layer}<br \/>  Content-Type: application\/octet-stream<br \/>  Layer Binary Data&quot;.<\/li>\n<li>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442\u0430 \u2014 &quot;PUT \/v2\/{repoName}\/manifests\/{reference}&quot;.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0443\u043f\u0443\u0449\u0435\u043d \u043e\u0434\u0438\u043d \u0448\u0430\u0433, \u0431\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u0414\u043b\u044f \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0438 \u0434\u043b\u044f \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 (chunked) \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043b\u0435\u0435\u0440 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c PATCH \u0437\u0430\u043f\u0440\u043e\u0441:<br \/>  &quot;PATCH \/v2\/{repoName}\/blobs\/uploads\/{uuid}<br \/>  Content-Length: {size of chunk}<br \/>  Content-Type: application\/octet-stream<br \/>  {Layer Chunk Binary Data}&quot;.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430, \u0442.\u043a. \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 202 \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c 4\u0445\u0445.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/li>\n<li>\u041f\u0430\u0442\u0447 \u043b\u0435\u0435\u0440\u0430<\/li>\n<li>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043b\u0435\u0435\u0440\u0430<\/li>\n<li>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442\u0430<br \/>  \u041f\u0443\u043d\u043a\u0442\u044b 2 \u0438 3 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0435\u0440\u043e\u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043b\u044e\u0431\u043e\u0439 \u0438\u043c\u0435\u0434\u0436. \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c archlinux:latest<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">docker pull archlinux<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/jv\/bj\/6u\/jvbj6udtej7zbqevddc_ldd07cm.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0435\u0433\u043e \u0441\u0435\u0431\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u0431\u043e\u0440\u0430<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">docker save c24fe13d37b9 -o savedArch<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/8i\/aa\/ji\/8iaaji32nxl_usmoy0hamugdwfu.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u043f\u0430\u043a\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0430\u0440\u0445\u0438\u0432 \u0432 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">tar xvf savedArch<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dd\/9q\/u2\/dd9qu2ag_-ht0fm9ussl8ucru3u.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u043b\u0435\u0435\u0440 \u043b\u0435\u0436\u0438\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0430\u043f\u043a\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u0442\u0440\u0443\u0442\u043a\u0443\u0440\u0443 \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 <\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">cat manifest.json | json_pp<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vw\/h6\/js\/vwh6js3j5_5tj4fe83i2hom8woy.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041d\u0435 \u0433\u0443\u0441\u0442\u043e. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a\u043e\u0439 \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/docs.docker.com\/registry\/spec\/manifest-v2-2\/#example-image-manifest\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/o6\/im\/9x\/o6im9xrjp-g7swip0hian3rrbai.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442 \u043d\u0430\u043c \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u0437\u043d\u0430\u0447\u0438\u0442 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u043e\u0439 \u0441 <del>\u0431\u043b\u044d\u043a\u0434\u0436\u0435\u043a\u043e\u043c \u0438 \u043a\u0443\u0440\u0442\u0438\u0437\u0430\u043d\u043a\u0430\u043c\u0438<\/del> \u043b\u0435\u0435\u0440\u0430\u043c\u0438 \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0423 \u043d\u0430\u0441 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043c\u0438\u043d\u043c\u0443\u043c \u043e\u0434\u0438\u043d config \u0444\u0430\u0439\u043b \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043b\u0435\u0435\u0440\u043e\u0432. \u0412\u0435\u0440\u0441\u0438\u044f \u0441\u0445\u0435\u043c\u044b 2 (\u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0430 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438), mediaType \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">echo \u2018{    &quot;schemaVersion&quot;: 2,    &quot;mediaType&quot;: &quot;application\/vnd.docker.distribution.manifest.v2+json&quot;,    &quot;config&quot;: {       &quot;mediaType&quot;: &quot;application\/vnd.docker.container.image.v1+json&quot;,       &quot;size&quot;: config_size,       &quot;digest&quot;: &quot;config_hash&quot;    },    &quot;layers&quot;: [       \u2019 &gt; manifest.json<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0435\u0433\u043e \u043d\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d json \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043b\u0435\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">{          &quot;mediaType&quot;: &quot;application\/vnd.docker.image.rootfs.diff.tar.gzip&quot;,          &quot;size&quot;: ${layersSizes[$i]},          &quot;digest&quot;: \\&quot;sha256:${layersNames[$i]}\\&quot;       },<\/code><\/pre>\n<p>  <\/p>\n<p>\u0435\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043b\u0435\u0435\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433 \u0444\u0430\u0439\u043b\u0430 \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0438 \u0432 \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442\u0435 \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">sed -i &quot;s\/config_size\/$configSize\/g; s\/config_hash\/$configName\/g&quot; $manifestFile<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0435\u0431\u0435 uuid, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">#!\/bin\/bash -eux  imageDir=$1 # url as http:\/\/localhost:8081\/link\/to\/docker\/registry url=$2 repoName=$3 tag=$4 manifestFile=$(readlink -f ${imageDir}\/manifestCopy) configFile=$(readlink -f $(find $imageDir -name &quot;*.json&quot; ! -name &quot;manifest.json&quot;))  # calc layers sha 256 sum, rename them accordingly, and add info about each to manifest file function prepareLayersForUpload() {   info_file=$imageDir\/info   # lets calculate layers sha256 and use it as layers names further   layersNames=($(find $imageDir -name &quot;layer.tar&quot; -exec shasum -a 256 {} \\; | cut -d&quot; &quot; -f1))    # rename layers according to shasums. !!!Set required amount of fields for cut command!!!   # this part definitely can be done easier but i didn't found another way, sry   find $imageDir -name &quot;layer.tar&quot; -exec bash -c 'mv {} &quot;$(echo {} | cut -d&quot;\/&quot; -f1,2)\/$(shasum -a 256 {} | cut -d&quot; &quot; -f1)&quot;' \\;    layersSizes=($(find $imageDir -name &quot;*.tar&quot; -exec ls -l {} \\; | awk '{print $5}'))    for i in &quot;${!layersNames[@]}&quot;; do     echo &quot;{          &quot;mediaType&quot;: &quot;application\/vnd.docker.image.rootfs.diff.tar.gzip&quot;,          &quot;size&quot;: ${layersSizes[$i]},          &quot;digest&quot;: \\&quot;sha256:${layersNames[$i]}\\&quot;       },&quot; &gt;&gt; $manifestFile   done   # remove last ','   truncate -s-2 $manifestFile   # add closing brakets to keep json consistent   printf &quot;\\n\\t]\\n}&quot; &gt;&gt; $manifestFile }  # calc config sha 256 sum and add info about it to manifest function setConfigProps() {   configSize=$(ls -l $configFile | awk '{print $5}')   configName=$(basename $configFile | cut -d&quot;.&quot; -f1)    sed -i &quot;s\/config_size\/$configSize\/g; s\/config_hash\/$configName\/g&quot; $manifestFile }  #prepare manifest file prepareLayersForUpload setConfigProps cat $manifestFile  # initiate upload and get uuid uuid=$(curl -s -X POST -I &quot;$url\/v2\/$repoName\/blobs\/uploads\/&quot; | grep -oP &quot;(?&lt;=Docker-Upload-Uuid: ).+&quot;)  # patch layers # in data-binary we're getting absolute path to layer file for l in &quot;${!layersNames[@]}&quot;; do   pathToLayer=$(find $imageDir -name ${layersNames[$l]} -exec readlink -f {} \\;)     curl -v -X PATCH &quot;$url\/v2\/$repoName\/blobs\/uploads\/$uuid&quot; \\   -H &quot;Content-Length: ${layersSizes[$i]}&quot; \\   -H &quot;Content-Type: application\/octet-stream&quot; \\   --data-binary &quot;@$pathToLayer&quot;  # put layer   curl -v -X PUT &quot;$url\/v2\/$repoName\/blobs\/uploads\/$uuid?digest=sha256:${layersNames[$i]}&quot; \\   -H 'Content-Type: application\/octet-stream' \\   -H &quot;Content-Length: ${layersSizes[$i]}&quot; \\   --data-binary &quot;@$pathToLayer&quot; done  # patch and put config after all layers curl -v -X PATCH &quot;$url\/v2\/$repoName\/blobs\/uploads\/$uuid&quot; \\   -H &quot;Content-Length: $configSize&quot; \\   -H &quot;Content-Type: application\/octet-stream&quot; \\   --data-binary &quot;@$configFile&quot;    curl -v -X PUT &quot;$url\/v2\/$repoName\/blobs\/uploads\/$uuid?digest=sha256:$configName&quot; \\   -H 'Content-Type: application\/octet-stream' \\   -H &quot;Content-Length: $configSize&quot; \\   --data-binary &quot;@$configFile&quot;  # put manifest curl -v -X PUT &quot;$url\/v2\/$repoName\/manifests\/$tag&quot; \\   -H 'Content-Type: application\/vnd.docker.distribution.manifest.v2+json' \\   --data-binary &quot;@$manifestFile&quot;  exit 0 <\/code><\/pre>\n<p>  <\/p>\n<p>\u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">.\/uploadImage.sh &quot;~\/path\/to\/saved\/image&quot; &quot;http:\/\/localhost:8081\/link\/to\/docker\/registry&quot; myRepoName 1.0<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0442\u0443\u043b\u044b GNU \u0432\u0435\u0440\u0441\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0410\u043c\u0435\u0440\u0438\u043a\u0443, \u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0437\u0440\u043e\u0437\u043d\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0431\u0435\u043b\u044b \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u0421\u043f\u0430\u0441\u0438\u0431\u043e, \u0447\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/504314\/\"> https:\/\/habr.com\/ru\/post\/504314\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/504314\/\">\n<p>\u0423 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e <del>2 \u043c\u0435\u0448\u043a\u0430 \u0442\u0440\u0430\u0432\u044b, 75 \u0442\u0430\u0431\u043b\u0435\u0442\u043e\u043a \u043c\u0435\u0441\u043a\u0430\u043b\u0438\u043d\u0430<\/del> unix environment, docker \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b docker pull \u0438 docker push \u0431\u0435\u0437 \u0434\u043e\u043a\u0435\u0440 \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/mv\/a1\/9d\/mva19dlfjox7sohuv4jjpca0p4u.jpeg\"\/><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-304414","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=304414"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304414\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=304414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=304414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=304414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}