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

Operation method of Image in docker Container

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Today, the editor will bring you an article about the operation of mirroring in docker containers. The editor thinks it is very practical, so I will share it for you as a reference. Let's follow the editor and have a look.

Article catalogue

Centos7 install docker

Configure docker Accelerator

Mirror management

Create an image through a container

Import and export image

Centos7 install docker

Download the docker yum source provided by Aliyun:

[root@linux01 ~] # yum-config-manager-- add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

one

Install docker Community Edition (free version):

[root@linux01 ~] # yum-y install docker-ce

one

Start the docker service:

[root@linux01 ~] # systemctl start docker

one

View docker version information: docker version

Configuration of docker Accelerator Foreign Exchange Technical www.gendan5.com/tech.html

Configuration Accelerator can speed up the acquisition of official Docker images and create configuration files:

[root@linux01 ~] # vi / etc/docker/daemon.json

one

Configuration file content:

{

"registry-mirrors": ["https://jmnbijcd.mirror.aliyuncs.com"]"

}

one

two

three

# the url is the address of the accelerator, and you need to obtain it from Aliyun-> Container Image Service-> Accelerator.

Restart the docker service:

[root@linux01 ~] # systemctl restart docker

one

Mirror management

Download the centos image of the official docker repository:

[root@linux01 ~] # docker pull centos

one

View the local image:

[root@linux01 ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Centos latest 0f3e07c0138f 3 months ago 220MB

one

two

three

# Image name, label, image id, creation time and size from left to right

Search for an image based on its name:

[root@linux01 ~] # docker search ubuntu

one

Change the image name:

[root@linux01 ~] # docker tag centos test

[root@linux01 ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Centos latest 0f3e07c0138f 3 months ago 220MB

Test latest 0f3e07c0138f 3 months ago 220MB

one

two

three

four

five

# changing the image name centos to test will result in an image with the same id but different image name

Change the image name and change the label:

[root@linux01 ~] # docker tag test abc:abc

[root@linux01 ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Test latest 0f3e07c0138f 3 months ago 220MB

Abc abc 0f3e07c0138f 3 months ago 220MB

Centos latest 0f3e07c0138f 3 months ago 220MB

one

two

three

four

five

six

Start the mirror:

[root@linux01 ~] # docker run-itd centos

Af57114ec8a10c96b6301de65fb6d6e30a61fee19ef48676a15d736e83628264

one

two

# the image becomes a container after startup.-I means to open the standard input of the container,-t means to assign a pseudo terminal,-d means to start in the background, and put-I-t-d in front of the image name.

View the container that is running:

[root@linux01 ~] # docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Af57114ec8a1 centos "/ bin/bash" 4 minutes ago Up 4 minutes charming_mclaren

one

two

three

# docker ps-a can view all containers (including those that are not running)

Delete the specified image:

[root@linux01 ~] # docker rmi test

one

When the image tag is not latest, you need to specify the image name and label before you can delete:

[root@linux01 ~] # docker rmi abc:abc

one

# if you specify an image id instead of an image name, all images of the id will be deleted

Create an image through a container

After starting the image using docker run, you can specify the container id to enter the container:

[root@linux01 ~] # docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Af57114ec8a1 centos "/ bin/bash" 12 minutes ago Up 12 minutes charming_mclaren

[root@linux01 ~] # docker exec-it af57114ec8a1 bash

[root@af57114ec8a1 /] #

one

two

three

four

five

Exit after installing any service in the container:

[root@af57114ec8a1 /] # yum-y install net-tools

[root@af57114ec8a1 /] # exit

[root@linux01 ~] #

one

two

three

Create an image of the changed container:

[root@linux01] # docker commit-m "add net-tools"-a "root" af57114ec8a1 centos_net

Sha256:f9dba795f88479c70133e18145ad5337c3199fe633523009a2bb84febf58d695

[root@linux01 ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Centos_net latest f9dba795f884 8 seconds ago 261MB

Centos latest 0f3e07c0138f 3 months ago 220MB

one

two

three

four

five

six

# the new image has been created successfully. This command is similar to the submission of git and svn. The-m parameter adds a description, and the-a parameter specifies the operator or author af57114ec8a1 string as the container id (obtained through docker ps), followed by the name of the new image.

Import and export image

Export the mirror:

[root@linux01] # docker save-o centos_net.tar centos_net

one

# Export centos_net image to .tar file

Delete the centos_net image:

[root@linux01 ~] # docker rmi centos_net

[root@linux01 ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Centos latest 0f3e07c0138f 3 months ago 220MB

one

two

three

four

Import the image:

[root@linux01 ~] # docker load

< centos_net.tar 45a8968b6423: Loading layer [==================================================>

] 41.4MB/41.4MB

Loaded image: centos_net:latest

one

two

three

# the second way to import images: docker load-- input centos_net.tar

Check whether the image is imported successfully:

[root@linux01 ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Centos_net latest f9dba795f884 31 minutes ago 261MB

Centos latest 0f3e07c0138f 3 months ago 220MB

This is the end of the operation of mirroring in the docker container. I hope the above content can be helpful to you and learn more. If you like this article, you might as well 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

Internet Technology

Wechat

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

12
Report