Concept and application of Docker mirror container and warehouse

  • 2020-05-27 07:53:26
  • OfStack

Docker concept of mirror, container, and warehouse

Docker mirror

The Docker image (Image) is similar to the virtual machine image and can be understood as a read-only template for the Docker engine, containing the file system.

For example, an image can fully contain the Ubuntu operating system environment, which can be referred to as an Ubuntu image. An image can also be installed with the Apache application (or other software), which you can call an Apache image.

Mirroring is the basis for creating the Docker container. Through versioning and incremental file systems, Docker provides a simple 10-point mechanism for creating and updating existing images. Users can download a finished application image from the Internet and use it directly through the command. In short, an application needs an environment to run, and mirroring provides that environment.

Docker container

The Docker container (Container) is similar to a lightweight sandbox (because Docker is a virtual technology based on the Linux kernel, it consumes 10 cents less), and Docker USES the container to run and isolate applications.

Containers are run instances of applications created from images that can be started, started, stopped, and deleted, all of which are isolated from each other and not visible to each other.

Think of each container as a simplified version of the Linux system environment (including root user permissions, process space, user space, and network space) and an application box packaged with the applications running in it.

The mirror image itself is read-only. When the container starts from the image, Docker creates a writable layer on top of the image, and the image itself remains the same. Just like after installing the system with ISO, there is no change in ISO.

Docker warehouse

The Docker repository (Repository), similar to the code repository, is where Docker centralizes mirror files.

Sometimes you will see data that mixes the Docker warehouse and the registration server (Registry) into a 1, without making a strict distinction. In fact, the registry server is the repository where multiple repositories are stored. Each warehouse stores a certain type of image centrally, often including multiple image files, distinguished by different labels (tag). For example, the Ubuntu operating system image repository, known as Ubuntu repository, may contain 14.04,12.04 and other versions of the mirror.

The Docker warehouse is divided into two forms: public warehouse (Public) and private warehouse (Private), depending on whether the image of the storage is publicly Shared or not.

Currently, the largest public repository is Docker Hub, which holds a large number of images for users to download. Domestic open warehouses include Docker Pool, etc., which can provide stable domestic access. If you don't want to share your image publicly, Docker also allows you to create a private repository within your local network that you can access only.

Once a user has created his or her own image, push can be used to upload it to a specified public or private repository. This way, the next time the user USES the image on another machine, he or she simply takes it down from the warehouse pull.

The following article describes the basic commands for these concepts

Docker's basic commands for mirroring, containers, and warehouses

The mirror

1. Get a mirror


$ docker pull dl.dockerpool.com:5000/ubuntu:14.04

dl.dockerpool.com is the registered server, 5000 is the port number, ubuntu is the warehouse name, 14.04 is the mirror and version number

2. View mirror information

Lists all existing images of the localhost


$ docker images 

Change change information


$ docker tag dl.dockerpool.com:5000/ubuntu:latest ubuntu:latest

000 is the mirror ID, showing the details of this mirror


$ docker inspect 000

3. Search for mirrors


$ docker search mysql  (the output information includes the image name, description, star, whether it is created officially, and whether it is created automatically) 

4. Delete the image


$ docker rmi dl.dockerpool.com:5000/ubuntu:latest

Note: when the container created by the image exists, the image file cannot be deleted by default, so it is better to delete all containers dependent on the image before deleting the image, please do not use forced deletion.

5. Create a mirror

There are three ways:

Container creation based on an existing image


$ docker commit -m  " add new image " -a "" 000( The container ID) test (new image name ) 

Import based on local templates


$ cat ubuntu-14.04-x86_64-minimal.tar.gz | Docker import - ubuntu:14.04

Created based on dockerfile

6. Save the mirror image


$ docker save -o ubuntu_14.04.tar ubuntu:14.04

7. Load the image


$ docker load --input ubuntu_14.04.tar

or


$ docker images 
0

8. Upload a mirror


$ docker push user/test:latest

user users need to register with the dockerHub website

The container

The container is a running instance of the image, but it has an additional writable layer

1. Create a container


$ docker create -it ubuntu:12.04

2. Create and start the container


$ docker images 
3

3. Daemon operation


$ docker images 
4

4. View container information


$ docker images 
5

View termination status

5. Get the output information of the container


$ docker images 
6

cet is the first three characters of the container ID

6. Terminate the container


$ docker stop cet

7. Start the container


$ docker start cet

Restart the container


$ docker images 
9

Enter the container

attach command


$ docker attach nostalgic(nostalgic is docker the name)

Disadvantages: all Windows are displayed synchronously

exec command


- docker exec -it 243... /bin/bash (243... for docker ID)

nsenter command

1. To find PID


$ PID=$(docker-pid 243..)

2. Link containers via PID


$ nsenter --target $PID --mount --uts --ipc --net --pid

10. Delete the container


$ docker rm [-f -l -v] cet

-f forcibly terminated and deleted

-l removes the link to the container and retains the container

-v deletes mounted data volumes


$ docker export cet >test.tar

12. Import the container (import the container snapshot into the local mirror library)


$ cat test.tar | docker import - test/ubuntu:v1.0

Re - specify the image name of the label ubuntu and the version number v 1.0

docker load can also import the image store file to the local image library, which has the advantage over import in that importing the image snapshot file will lose all history and metadata information.

Note: container migration can be achieved by exporting and importing containers (copy files)

warehouse

A warehouse is a place where mirrors are stored centrally. There are many warehouses on one registration server and many mirrors in one warehouse.

1. Login


$ docker login

2. Basic operation

Find, upload, download

3. Automatic creation

4. View the mirror

http://www.dockerpool.com/downloads

5. Update mirror labels


$ docker tag dl.dockerpool.com:5000/ubuntu:12.04 ubuntu:12.04

Change the previous image to ubuntu:12.04

6. Create a private repository


$ docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registryregistry

Automatically download and launch the registry container to create a local private warehouse service. The default container for the warehouse ship is /tmp/registry, which can be stored on the specified path with the -v parameter

7. Manage private warehouse mirrors

Suppose the private warehouse address is 10.0.2.2 and the port is 5000,


$ docker tag ubuntu:14.04 10.0.2.2:5000/test

Change tag name


$ docker push 10.0.2.2:5000/test

push mirror, will automatically push to the 10.0.2.2 address of the machine


$ curl http://10.0.2.2:5000/v1/search

Check whether the test image is included in the warehouse 10.0.2.2:5000


docker pull 10.0.2.2:5000/test

Download the image on any machine that has access to the 10.0.2.2 address

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: