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

How to use Docker Mirror

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

Share

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

This article will explain in detail the use of Docker images for you. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

When running the container, if the image used does not exist locally, docker is automatically downloaded from the docker image repository. By default, it is downloaded from the Docker Hub public image source.

Let's learn:

1. Manage and use local Docker host images

2. Create an image

List a list of images

We can use docker images to list the images on the local host.

[root@huixuan ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Docker.io/hello-world latest e38bc07ac18e 2 weeks ago 1.85 kB

Docker.io/ubuntu 15.10 9b9cb95443b5 21 months ago 137 MB

Docker.io/training/webapp latest 6fae60ef3446 2 years ago 349 MB

[root@huixuan ~] #

Description of each option:

REPOSITORY: indicates the warehouse source of the image

TAG: the label of the image

IMAGE ID: mirror ID

CREATED: time when the image was created

SIZE: mirror siz

There can be multiple TAG in the same warehouse source, which represents different versions of the warehouse source. For example, there are different versions such as 15.10,14.04 in the ubuntu repository source. We use REPOSITORY:TAG to define different images.

So, if we want to use the ubuntu system image with version 15.10 to run the container, the command is as follows:

[root@huixuan] # docker run-t-I ubuntu:15.10 / bin/bash

Root@38a4ad967a4a:/#

If you want to use the ubuntu system image with version 14.04 to run the container, the command is as follows:

[root@huixuan] # docker run-t-I ubuntu:14.04 / bin/bash

If you do not specify a version tag for the image, for example, if you only use ubuntu,docker, the ubuntu:latest image will be used by default.

Get a new image

Docker automatically downloads the image when we use a non-existent image on the local host. If we want to download the image in advance, we can use the docker pull command to download it.

[root@huixuan ~] # docker pull ubuntu:13.10

After the download is complete, we can directly use this image to run the container.

Find Mirror

We can search for images from Docker Hub. The Docker Hub address is: https://hub.docker.com/

We can also use the docker search command to search for images. For example, we need an image of httpd as our web service. We can search httpd with the docker search command to find the right image for us.

[root@huixuan ~] # docker search httpd

INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED

Docker.io docker.io/httpd The Apache HTTP Server Project 1668 [OK]

Docker.io docker.io/hypriot/rpi-busybox-httpd Raspberry Pi compatible Docker Image with... 40

Docker.io docker.io/centos/httpd 17 [OK]

Docker.io docker.io/centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or b... twelve

Docker.io docker.io/armhf/httpd The Apache HTTP Server Project 8

Docker.io docker.io/macadmins/netboot-httpd use in combination with bruienne/bsdpy 5 [OK]

Docker.io docker.io/lolhens/httpd Apache httpd 2 Server 2 [OK]

Docker.io docker.io/salim1983hoop/httpd24 Dockerfile running apache config 2 [OK]

Docker.io docker.io/epflidevelop/os-wp-httpd WP httpd 1 [OK]

Docker.io docker.io/fboaventura/dckr-httpd Small footprint http server to use with ot... 1 [OK]

Docker.io docker.io/lead4good/httpd-fpm httpd server which connects via fcgi proxy... 1 [OK]

Docker.io docker.io/rgielen/httpd-image-simple Docker image for simple Apache httpd based... 1 [OK]

Docker.io docker.io/tplatform/aws-linux-httpd24-php71-fpm aws-linux-httpd24-php71-fpm 1 [OK]

Docker.io docker.io/buzzardev/httpd Based on the official httpd image 0 [OK]

Docker.io docker.io/cilium/demo-httpd 0

Docker.io docker.io/dockerpinata/httpd 0

Docker.io docker.io/fintaffy/fintaffy-httpd 0

Docker.io docker.io/interlutions/httpd httpd docker image with debian-based confi... 0 [OK]

Docker.io docker.io/manageiq/httpd Container with httpd, built on CentOS for... 0 [OK]

Docker.io docker.io/manasip/httpd 0

Docker.io docker.io/ppc64le/httpd The Apache HTTP Server Project 0

Docker.io docker.io/publici/httpd httpd:latest 0 [OK]

Docker.io docker.io/tplatform/aws-linux-httpd24-php70 aws-linux-httpd24-php70 0 [OK]

Docker.io docker.io/tplatform/aws-linux-httpd24-php71 aws-linux-httpd24-php71 0 [OK]

Docker.io docker.io/trollin/httpd 0

[root@huixuan ~] #

NAME: name of the image warehouse source

DESCRIPTION: description of the mirror

OFFICIAL: whether docker is officially released

Drag the mirror image

We decided to use the image of the official version of httpd in the image above and use the command docker pull to download the image.

[root@huixuan ~] # docker pull httpd

After the download is complete, we can use this image.

[root@huixuan ~] # docker run httpd

Create a mirror

When the image we downloaded from the docker image repository does not meet our needs, we can change the image in the following two ways.

1. Update the image from the container that has been created and submit the image

two。 Use the Dockerfile directive to create a new mirror

Update Mirror

Before updating the image, we need to use the image to create a container.

[root@huixuan] # docker run-t-I ubuntu:15.10 / bin/bash

Root@493da1af5d63:/#

Use the apt-get update command to update within the running container.

After completing the operation, type the exit command to exit the container.

At this point, ID is the container of 493da1af5d63, which is changed according to our requirements. We can submit a copy of the container by commanding docker commit.

[root@huixuan ~] # docker commit-m = "has update"-a = "tonykorn97" 493da1af5d63 tonykorn97/ubuntu:v2

Sha256:6bb0f7a6d1e68fa93197761f3fa86a18397b1dfff563a0405e48cc833d0b3112

Description of each parameter:

-m: submitted description information

-a: specify the mirror author

493da1af5d63: container ID

Tonykorn97/ubuntu:v2: specifies the name of the target image to be created

We can use the docker images command to view our new mirror tonykorn97/ubuntu:v2:

[root@huixuan ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Tonykorn97/ubuntu v2 6bb0f7a6d1e6 2 seconds ago 137 MB

3248dea71f18 About a minute ago 137 MB

Docker.io/ubuntu 14.04 8cef1fa16c77 3 days ago 223 MB

Docker.io/hello-world latest e38bc07ac18e 2 weeks ago 1.85 kB

Docker.io/ubuntu 15.10 9b9cb95443b5 21 months ago 137 MB

Docker.io/training/webapp latest 6fae60ef3446 2 years ago 349 MB

[root@huixuan ~] #

Use our new image tonykorn97/ubuntu to start a container

[root@huixuan] # docker run-t-I tonykorn97/ubuntu:v2 / bin/bash

Root@694ecac26845:/#

Build an image

We use the command docker build to create a new image from scratch. To do this, we need to create a Dockerfile file that contains a set of instructions to tell Docker how to build our image.

[root@huixuan ~] # cat Dockerfile

FROM centos

MAINTAINER Fisher "tonykorn97@sudops.com"

RUN / bin/echo 'root:123456' | chpasswd

RUN useradd tonykorn97

RUN / bin/echo 'tonykorn97:123456' | chpasswd

RUN / bin/echo-e "LANG=\" en_US.UTF-8\ "> / etc/default/local

EXPOSE 22

EXPOSE 80

CMD / usr/sbin/sshd-D

[root@huixuan ~] #

Each instruction creates a new layer on the mirror, and each instruction must be prefixed in uppercase.

The first FROM, which specifies which mirror source to use

The RUN instruction tells docker to execute the command in the image and what is installed.

Then we use the Dockerfile file to build an image through the docker build command.

[root@huixuan] # docker build-t docker.io/centos.

Sending build context to Docker daemon 42.5 kB

Step 1/9: FROM centos

-- > e934aafc2206

Step 2 tonykorn97@sudops.com 9: MAINTAINER Fisher "tonykorn97@sudops.com"

-- > Running in e8fba274a04f

-- > a957802c0f10

Removing intermediate container e8fba274a04f

Step 3 root:123456' 9: RUN / bin/echo 'root:123456' | chpasswd

-- > Running in 9b6d82512651

-- > 91895d25b7ca

Removing intermediate container 9b6d82512651

Step 4/9: RUN useradd tonykorn97

-- > Running in ca2a783aa01f

-- > da8e8eb44cb9

Removing intermediate container ca2a783aa01f

Step 5 tonykorn97:123456' 9: RUN / bin/echo 'tonykorn97:123456' | chpasswd

-- > Running in bcfd276a69cc

-- > e9bef27837e4

Removing intermediate container bcfd276a69cc

Step 6ax 9: RUN / bin/echo-e "LANG=\" en_US.UTF-8\ "> / etc/default/local

-- > Running in fb07b34deefd

-- > b34b2ad1c65b

Removing intermediate container fb07b34deefd

Step 7/9: EXPOSE 22

-- > Running in a580e3c0df37

-- > ae38f15b66c3

Removing intermediate container a580e3c0df37

Step 8/9: EXPOSE 80

-- > Running in b3e04bf32806

-- > 8964d002a4a9

Removing intermediate container b3e04bf32806

Step 9 + 9: CMD / usr/sbin/sshd-D

-- > Running in 804574e55fdc

-- > 3a42651974ec

Removing intermediate container 804574e55fdc

Successfully built 3a42651974ec

[root@huixuan ~] #

Parameter description:

-t: specify the name of the target image to be created

. The directory where the Dockerfile file is located, and you can specify the absolute path of Dockerfile

Use docker images to check that the created image already exists in the list, and the image ID is 3a42651974ec.

[root@huixuan ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Docker.io/centos latest 3a42651974ec 42 seconds ago 199 MB

Tonykorn97/ubuntu v2 6bb0f7a6d1e6 27 minutes ago 137 MB

3248dea71f18 29 minutes ago 137 MB

Docker.io/ubuntu 14.04 8cef1fa16c77 3 days ago 223 MB

Docker.io/hello-world latest e38bc07ac18e 2 weeks ago 1.85 kB

Docker.io/centos e934aafc2206 3 weeks ago 199 MB

Docker.io/ubuntu 15.10 9b9cb95443b5 21 months ago 137 MB

Docker.io/training/webapp latest 6fae60ef3446 2 years ago 349 MB

[root@huixuan ~] #

We can use the new image to create the container

[root@huixuan] # docker run-t-I centos / bin/bash

[root@6263f2eb5f6c /] # id tonykorn97

Uid=1000 (tonykorn97) gid=1000 (tonykorn97) groups=1000 (tonykorn97)

[root@6263f2eb5f6c /] #

From the above, we can see that the new image already contains the user tonykorn97 we created.

Set image label

We can use the docker tag command to add a new label to the image.

[root@huixuan ~] # docker tag 3a42651974ec tonykorn97/centos:dev

Docker tag image ID, here is 3a42651974ec, user name, image source name (repository name), and new tag signature (tag).

Using the docker images command, you can see that ID is an extra label for the image of 860c279d2fec.

[root@huixuan ~] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Docker.io/centos latest 3a42651974ec 3 minutes ago 199 MB

Tonykorn97/centos dev 3a42651974ec 3 minutes ago 199 MB

Tonykorn97/ubuntu v2 6bb0f7a6d1e6 30 minutes ago 137 MB

3248dea71f18 32 minutes ago 137 MB

Docker.io/ubuntu 14.04 8cef1fa16c77 3 days ago 223 MB

Docker.io/hello-world latest e38bc07ac18e 2 weeks ago 1.85 kB

Docker.io/centos e934aafc2206 3 weeks ago 199 MB

Docker.io/ubuntu 15.10 9b9cb95443b5 21 months ago 137 MB

Docker.io/training/webapp latest 6fae60ef3446 2 years ago 349 MB

[root@huixuan ~] #

On the use of Docker images to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can 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