Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the operations related to docekr mirroring

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail the operations related to docekr mirroring. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

# # obtaining Image

We use the _ _ docker pull__ instruction to get the image. There are three sources for obtaining images: Docker official repository, third-party Docker repository, and local private repository.

# Docker official warehouse

The following example downloads a Ubuntu12.04 operating system image from Docker Hub

$docker pull ubuntu:12.04Pulling repository ubuntuab8e2728644c: Pulling dependent layers511136ea3c5a: Download complete5f0ffaa9455e: Download completea300658979be: Download complete904483ae0c30: Download completeffdaafd1ca50: Download completed047ae21eeaf: Download complete

The Docker pull tool outputs acquisition information for each layer, including the size of the current acquisition content, the speed of transmission, and the transmission status.

The _ _ docker pull ubuntu:12.04__ above actually executes

$sudo docker pull registry.hub.docker.com/ubuntu:12.04

Where _ _ registry.hub.docker.com__ is the warehouse registration server, ubuntu refers to the warehouse, and 12.04 refers to tag. That is, download the image labeled 12.04 from the ubuntu repository in the registration server registry.hub.docker.com.

Sometimes it is slow to download from the official warehouse, so we can use a third-party warehouse to speed up our download speed.

# third-party Docker repository

Once we understand the meaning of the complete pull option above, it is very easy to understand the following instruction to download an image from a third-party repository

Docker pull dl.dockerpool.com:5000/ubuntu:12.04Pulling dl.dockerpool.com:5000/ubuntuab8e2728644c: Pulling dependent layers511136ea3c5a: Download complete5f0ffaa9455e: Download completea300658979be: Download complete904483ae0c30: Download completeffdaafd1ca50: Download completed047ae21eeaf: Download complete

Download the image labeled 12.04 from the ubuntu repository in the registration server dl.dockerpool.com:5000.

# Private Warehouse

Well, I don't quite understand this area myself. I have a chance to build a private warehouse and add it.

# # Managing Local Images

# using Image for the first time

After the image download is complete, you can use the image and use _ _ docker run__ to launch a container to use the image.

Docker run-t-I ubuntu:12.04 / bin/bash

If it starts successfully, it will enter bash.

Root@fe7fc4bd8fc9:/#

# list local images

To view the local image, use _ _ docker images__

Docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu 12.04 74fe38d11401 4 weeks ago 209.6 MBubuntu precise 74fe38d11401 4 weeks ago 209.6 MBubuntu 14.04 99ec81b80c55 4 weeks ago 266 MBubuntu latest 99ec81b80c55 4 weeks ago 266 MBubuntu trusty 99ec81b80c55 4 weeks ago 266 MB...

Let's take a look at the respective meanings of the listed fields:

REPOSITORY: warehouse name

TAG: mirrored tag

IMAGE ID: mirror ID number (unique)

CREATED: creation time

VIRTUAL SIZE: mirror siz

Note: the ID of the image is the only indication of the image. It shows that the ubuntu:14.0 number is the same as the ubuntu:trusty ID number, which means they are the same image.

# create an image

There are many ways to create an image:

Modify an existing mirror

Using Dockerfile to create Mirror

Import from the local file system

Upload image

# modify existing images

To create an image by modifying an existing image, we first need to make changes in the existing image, and then submit the modified (updated) image.

Start the image that needs to be modified:

$sudo docker run-t-I ubuntu:12.04 / bin/bashroot@0b2616b0e5a8:/#

Remember the ID of the container for a while, that is, 0b2616b0e5a8, which will be used later.

Add json and gem applications to the container:

# gem install json

When it's over, we use exit to exit, and now that our container has been changed, use the docker commit command to submit the updated copy.

$docker commit-m "Added json gem"-a "Docker Newbee" 0b2616b0e5a8 ouruser/sinatra:v24f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c

Where-m specifies the submitted description information, similar to the version control tool we use;-a specifies the updated user information; followed by the ID of the image, the warehouse name, and the tag tag. Finally, the ID information of this image is returned after the image is successfully created.

Then, we use docekr images to view our modified image.

$docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEtraining/sinatra latest 5bc342fa0b91 10 hours ago 446.7 MBouruser/sinatra v2 3c59e02ddd1a 10 hours ago 446.7 MBouruser/sinatra latest 5db5f8471261 10 hours ago 446.7 M

You can then use the new image to create the container.

$sudo docker run-t-I ouruser/sinatra:v2 / bin/bashroot@78e82f680994:/#

# create an image using Dockerfile

Creating an image by modifying an existing image is simple and fast, but it is not easy to share with the team. We can use _ _ docker build__ to create an image, and use _ _ docker build__ to create an image. We need to write the _ _ Dockerfile__ configuration file first. Dockerfile contains the instructions needed to create an image step by step.

Create a new directory and dockerfile file:

$mkdir sinatra$ cd sinatra$ touch Dockerfile

Next, we write to Dockerfile:

# This is a commentFROM ubuntu:12.04MAINTAINER Docker Newbee RUN apt-get-qq updateRUN apt-get-qqy install ruby ruby-devRUN gem install sinatr

First, let's take a look at how to understand the above:

# used to comment

The FROM instruction tells Docker which image to use as the basis

Then comes the maintainer's information.

The instructions at the beginning of RUN are run during creation, such as installing a software package, where apt-get is used to install some software

Each instruction in Dockerfile creates a layer of mirrors.

After writing the Dockerfile, we can use docker build to generate the image.

$docker build-t = "ouruser/sinatra:v2" .uploading context 2.56 kBUploading contextStep 0: FROM ubuntu:14.04-- > 99ec81b80c55 Step 1: MAINTAINER Newbee-- > Running in 7c5664a8a0c1-- > 2fa8ca4e2a13 Removing intermediate container 7c5664a8a0c1Step 2: RUN apt-get-qq update-- > Running in b07cc3fb4256-- > 50d21070ec0c Removing intermediate container b07cc3fb4256Step 3: RUN apt-get-qqy install ruby ruby-dev-- > Running in a5b038dd127e Selecting previously unselected package libasan0:amd64. (Reading database. 11518 files and directories currently Installed.) Preparing to unpack... / libasan0_4.8.2-19ubuntu1_amd64.deb... Setting up ruby (1libasan0_4.8.2 1.9.3.4)... Setting up ruby1.9.1 (1.9.3.484-2ubuntu1)... Processing triggers for libc-bin (2.19-0ubuntu6)...-> 2acb20f17878 Removing intermediate container a5b038dd127eStep 4: RUN gem install sinatra-- > Running in 5e9d0065c1f7. . .Successful installed rack-protection-1.5.3Successfully installed sinatra-1.4.54 gems installed-> 324104cde6ad Removing intermediate container 5e9d0065c1f7Successfully built 324104cde6ad

-t is used to add the tag tag to specify the user information of the new image, "." Is the path where the Dockerfile is located (the current directory), or it can be replaced with the path of a specific Dockerfile.

You can see that the build process is performing an operation. The first thing it needs to do is upload the Dockerfile content, because all operations are done according to Dockerfile. Then, the instructions in the Dockfile are executed one by one. Each step creates a new container, executes instructions in the container and commits changes (just like the docker commit described earlier). When all instructions have been executed, the final mirror id is returned. All containers generated by the intermediate steps are deleted and cleaned.

Note that an image cannot exceed 127 layers.

For more detailed syntax of dockerfile, there will be a blog post devoted to explaining it.

# Import from the local file system

To import an image from the local file system, you can use the template of openvz (the pioneer technology of container virtualization) to create it: the template download address of openvz is templates.

For example, download an image of ubuntu-14.04, and then import it using the following command:

Cat ubuntu-14.04-x86_64-minimal.tar.gz | docker import-ubuntu:14.04

Then view the newly imported image.

Docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu 14.04 05ac7c0b9383 17 seconds ago 215.5 MB

# upload image

Users can upload the created images to the repository to share through the docker push command. For example, after registering on Docker Hub, users can push their own images to the repository.

$sudo docker push ouruser/sinatraThe push refers to a repository [ouruser/sinatra] (len: 1) Sending image listPushing repository ouruser/sinatra (3 tags)

# Export and Import Images

# Image everywhere

To docker save the image locally, use the mirror command:

Docker images$ docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu 14.04 c4ff7513909d 5 weeks ago 225.4 MB...$ docker save-o ubuntu_14.04.tar ubuntu:14.04

# Import an image

You can use docker load to import from an exported local file to a local mirror library, such as

$docker load-input ubuntu_14.04.tar

Or

$docker load < ubuntu_14.04.tar

This imports the image and its associated metadata information (including labels, etc.).

# remove local image

If you want to remove the local mirror, you can use the docker rmi command. Note that the docker rm command is to remove the container.

$docker rmi training/sinatraUntagged: training/sinatra:latestDeleted: 5bc342fa0b91cabf65246837015197eecfa24b2213ed6a51a8974ae250fedd8dDeleted: ed0fffdcdae5eb2c3a55549857a8be7fc8bc4241fb19ad714364cbfd7a56b22fDeleted: 5c58979d73ae448df5af1d8142436d81116187a7633082650549c52c3a2418f0

Note: use docker rm to delete all containers that depend on the image before deleting the image.

# # implementation principle of Image

How do Docker images be incrementally modified and maintained? Each mirror consists of many layers, and Docker uses Union FS to combine these different layers into a single image.

Usually, Union FS has two uses. On the one hand, it is possible to hang multiple disk into the same directory without the help of LVM and RAID, and the other is to combine a read-only branch with a writable branch. Live CD is based on this method to allow users to do some write operations on it on the basis of the image unchanged. The container built by Docker on AUFS takes advantage of a similar principle.

This is the end of this article on "what are the operations related to docekr mirroring?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report