In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. Introduction to Docker image
1. Introduction to the composition of images
Layered construction, the bottom is bootfs, the top is rootfs
The type of bootfs can be btrfs, aufs, lxc, and a kernel is required, but this kernel is only used to start the user control of the container.
Rootfs is represented as a root file system, which includes many files and directories
When you start the container, both layers are mounted read-only.
The basic process of building an image
Prepare a bootfs first.
Then install a minimum system (base image)
Install the application on the system. If you are building an image of apache, install apache on base image.
Note:
Mirrors are read-only.
When the container is started, a dedicated layer of the current container is added on the basis of the image, which is read-write
When you delete a container, the dedicated read-write layer of the container will be deleted, so the default container cannot persist the data.
2. Image repository
As mentioned earlier, the location specifically used to store docker iamge is called docker registry. When starting the container, the local docker daemon will download the image from the specified docker registry and complete the startup.
Docker registry can be divided into many categories.
Vendor registry: the official warehouse
Mirror registry: image acceleration such as Aliyun
Private registry: users create their own image repositories. For example, when large-scale deployment is needed within an enterprise, they can customize their own images and put them in their own repositories.
A general registry consists of two parts:
Part one: Repository
A registry can have multiple repository
Repository can be divided into top-level warehouse and user warehouse. The name of user warehouse is: user name / warehouse name.
The name of Repository is generally the name of the application, and there are multiple versions of the application in Repository.
Part II: index
Maintain account information
Provide retrieval port
3. The method of downloading images from image repository
The format is as follows
Docker pull [: port] / [/]:
Registry:port specifies which docker server to obtain the image from. If you are using docker's official hub.docker.com, you can omit it here.
Namespace here specifies which namespace it comes from, that is, which user's warehouse, if the top-level warehouse, then this can also be omitted
In addition to https://hub.docker.com, there are actually other things, such as https://hub.daocloud.io/, and for example, https://quay.io maintained by CoreOS
Because it is not the default repository, you need to specify an address when downloading the image
Examples of downloading flannel from quay.io are as follows
Step 1: log in to https://quay.io and search for flannel
Step 2: find the project address
Step 3: view the way to download the image
This method cannot be used because you need to specify a label
Step 4: check the specific label
Step 5: download the image
[root@host1 ~] # docker pull quay.io/coreos/flannel:v0.11.0-s390x [root@host1 ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEbusybox latest b534869c81f0 2 weeks ago 1.22MBnginx 1.14-alpine 8a2fb25a19f5 8 months ago 16MBquay.io/coreos/flannel v0.10.0-s390x 463654e4ed2d 23 months ago 47MB
Second, make a mirror image
1. Types of methods for making mirror images
Based on dockerfile
Based on the existing container: image based on the container, usually install a minimum container, then install the application in this container, and then make an image of the container in which the program is installed
Automatic creation function based on docker hub
2. Image based on the existing container
Step 1: start a busybox container and create a html page
[root@host1 ~] # docker run-- name img1-it busybox/ # mkdir / data/html-p / # echo "test page [v1.0]" > > / data/html/index.html
Step 2: open another terminal and make the container into an image
Command commit for making mirrors
The container to be mirrored cannot be stopped
When making a container as a mirror, it is best to ask the container to pause, which requires the option-p
The default image does not have tag, nor does it belong to any repository.
[root@host1 ~] # docker commit-p img1sha256:cd7cb2a774400c721ed71f62bd20abe2c000f1d0f7d51d3bf025db1239b86b7d [root@host1 ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZE cd7cb2a77440 6 seconds ago 1.22MB
Step 3: tag the image
Use the tag command to label
An image can have multiple different tags
[root@host1 ~] # docker tag cd7cb2a77440 zxhk/httpd:v1-0 [root@host1 ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEzxhk/httpd v1-0 cd7cb2a77440 2 minutes ago 1.22MB
Label it again.
[root@host1 ~] # docker tag cd7cb2a77440 zxhk/httpd:latest [root@host1 ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEzxhk/httpd latest cd7cb2a77440 3 minutes ago 1.22MBzxhk/httpd v1-0 cd7cb2a77440 3 minutes ago 1.22MB
Note:
If an image has multiple tags, how to delete it? you need to delete all of these images, similar to the hard links of the system.
Step 4: start a container based on this and run apache in the container
[root@host1] # docker run-- name newhttpd-it zxhk/httpd:latest/ # httpd-f-h / data/html
At this point, apache can run, but every time you start a new container, you need to start apache manually, and then adjust the image to automatically run apache after starting the container.
Step 5: upgrade the image to automatically run the internal apache
First, let's take a look at the details of the mirror image we made.
[root@host1 ~] # docker inspect zxhk/httpd:latest
Part of it is Cmd, which is the command to be executed after the container is running, as follows
"Cmd": ["sh"]
When commit creates an image, you can set these contents with options.
-a: specify the author
-c: change the command executed after starting based on the image
-m: the description is to miss you
-p: pause
And make a new mirror image.
[root@host1 ~] # docker commit\ >-a "zxhk"\ >-c 'CMD ["/ bin/httpd", "- f", "- h", "/ data/html"]' >-p img3 zxhk/httpd:v2.0
Start a container with this image
[root@host1] # docker run-- rm-- name test-httpd zxhk/httpd:v2.0
Take a look at the commands executed in the container
[root@host1] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES243f050288bd zxhk/httpd:v2.0 "/ bin/httpd-f-h / d …" 16 seconds ago Up 15 seconds test-httpd
Check the address information.
[root@host1 ~] # docker inspect 243 | grep IPAddress "SecondaryIPAddresses": null, "IPAddress": "172.17.0.4", "IPAddress": "172.17.0.4"
Host access to the site in the test container
[root@host1 ~] # curl 172.17.0.4test page [v1.0]
At this point, the image is created.
3. Upload the created image to docker hub
1. Register users in https://hub.docker.com/
You need to climb over the wall to register, you know!
Process of registering an account-brief
2. Create repository and registry on docker hub
Note:
The name of the created warehouse must be the same as the name of the image
3. Upload mirror files to your own warehouse
Step 1: log in to docker hub [my user name is zxhk]
[root@localhost ~] # docker login-uzxhkPassword: WARNING! Your password will be stored unencrypted in / root/.docker/config.json.Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded
Step 2: upload the image to hub [here we upload both versions of the httpd image]
[root@localhost ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEzxhk/httpd v2.0 89a647171235 18 hours ago 1.22MBzxhk/httpd latest cd7cb2a77440 19 hours ago 1.22MBzxhk/httpd v1-0 Cd7cb2a77440 19 hours ago 1.22MB [root@localhost ~] # docker push zxhk/httpd:v2.0The push refers to repository [docker.io/zxhk/httpd] f577c88ef366: Pushed eac247cb7af5: Mounted from library/busybox v2.0: digest: sha256:c1c3e604e37652595563b8dc2be877620c77314c925115c7ba35f9969b1a77a0 size: 734 [root@localhost ~] # docker push zxhk/httpd:v1-0
Step 3: check it out on docker hub
Step 4: use our own image in docker hub
The use of images has been identified in docker hub, as follows:
For effect, the local image is now deleted
[root@localhost ~] # docker rmi 89 zxhk/httpd:v1-0 [root@localhost ~] # docker rmi 89 zxhk/httpd:v2.0 [root@localhost ~] # docker image ls REPOSITORY TAG IMAGE ID CREATED SIZEbusybox latest b534869c81f0 2 weeks ago 1.22MB
Download image startup container
[root@localhost ~] # docker pull zxhk/httpd:v2.0 [root@localhost ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEzxhk/httpd v2.0 89a647171235 19 hours ago 1.22MBbusybox latest b534869c81f0 2 weeks ago 1.22MB [root @ localhost ~] # docker run-- rm-- name web1 89a
Check the information of the container
[root@localhost] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES0ec8687bb487 89a "/ bin/httpd-f-h / d …" 16 seconds ago Up 15 seconds web1 [root@localhost ~] # docker inspect 0ec | grep "IPAddr"SecondaryIPAddresses": null, "IPAddress": "172.17.0.2", "IPAddress": "172.17.0.2", [root@localhost ~] # curl 172.17.0.2test page [v1.0]
Upload the created image to Aliyun's image repository
1. Register users in Aliyun
Slightly
2. Enter the container image repository
3. The method of using Ali Cloud for image acceleration
Add an image file to the docker configuration file
[root@localhost ~] # vim / etc/docker/daemon.json {"registry-mirrors": ["https://registry.docker-cn.com"," https://mzxx8xy8.mirror.aliyuncs.com"]}
Restart the service
[root@localhost ~] # systemctl daemon-reload [root@localhost ~] # systemctl restart docker
4. Use Aliyun to create a warehouse
Check out how to use the image repository.
5. Upload the mirror image to Aliyun warehouse
Step 1: log in to Aliyun with your credentials
[root@localhost ~] # sudo docker login-- username=zxhk registry.cn-hangzhou.aliyuncs.comPassword: WARNING! Your password will be stored unencrypted in / root/.docker/config.json.Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded
Step 2: upload the image
The image uploaded to Aliyun needs to be tagged first.
[root@localhost ~] # docker tag 89a registry.cn-hangzhou.aliyuncs.com/zxhk1/httpd:v2.0 [root@localhost ~] # docker push registry.cn-hangzhou.aliyuncs.com/zxhk1/httpd:v2.0
Step 3: pull the image from Aliyun
[root@localhost ~] # sudo docker pull registry.cn-hangzhou.aliyuncs.com/zxhk1/httpd:v2.0
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.