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

Installation, configuration and basic use of Docker Series 2:Docker

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

I. introduction of the basic environment

1. Introduction of basic software and hardware environment.

64-bit CPU is required

Linux kernel version 3.10 and above

The kernel supports cggroups and namespace

The system version is CentOS7.4 [centos6 can also be installed, but unstable]

Docker version 18.06

K8S version is 1.16 [K8s version must be compatible with docker version]

2. Check the corresponding relationship between k8s and docker version

Step 1: log in to github

Https://github.com/kubernetes/kubernetes/releases

Step 2: view the CHANGELOG file of the specified version k8s

Step 3: search docker version to see the supported docker version

3. Configure yum source

1) you can use the image of Ali Cloud, and the path is https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/stable/Packages/, as follows

2) configure yum source

[root@host1 ~] # cat / etc/yum.repos.d/docker.repo [docker] name=aliyun docker repoenabled=1gpgcheck=0baseurl= https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/stable/

Check to see if the configuration is successful

[root@host1 ~] # yum repolistLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirrors.huaweicloud.com * updates: mirrors.huaweicloud.comrepo id repo name statusdocker aliyun docker repo 58base/7/x86_64 CentOS-7-Base 10097extras/7/x86_64 CentOS-7-Extras 307updates/7/x86_64 CentOS-7-Updates nine hundred and ninety seven

2. Install and configure docker

1. Install docker 18.06.0

[root@host1 ~] # yum install docker-ce-18.06.0.ce

2. Create json files to accelerate the download speed of docker images

[root@host1 ~] # mkdir / etc/docker [root@host1 ~] # cat / etc/docker/daemon.json {"registry-mirrors": ["https://registry.docker-cn.com"]}"

3. Start the service

[root@host1 ~] # systemctl start docker [root@host1 ~] # systemctl status docker

Check out the docker version.

[root@host1] # docker-- versionDocker version 18.06.0-ce, build 0ffa825

View docker information

[root@host1 ~] # docker info

Third, about the operation of mirroring

1. About the firewall

Docker needs to start the iptables service, but in centos7, the default is to use firewalld to manage, not iptables, so it may cause problems with docer usage because iptables is required for port mapping. It can be solved in the following ways

[root@host1 ~] # systemctl disable firewalld ^ C [root@host1 ~] # yum install iptables-services-y ^ C [root@host1 ~] # systemctl enable iptables ^ C

2. View the local image

[root@host1 ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE

3. Search for images, such as nginx images

[root@host1 ~] # docker search nginx

As you can see from the search results above, some of the search results are just one content, while some results are separated by slashes

There is no slash separation, which we call the top warehouse, which is generally official.

Separated is called: user warehouse or like warehouse, generally, users register their own account, then make a warehouse, and put some images to others to use.

4. Pull out several mirrors

1) pull the nginx image. To save bandwidth, select the alpine version here.

[root@host1 ~] # docker image pull nginx:1.14-alpine1.14-alpine: Pulling from library/nginxbdf0201b3a05: Pull complete 3d0a573c81ed: Pull complete 8129faeb2eb6: Pull complete 3dc99f571daf: Pull complete Digest: sha256:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7Status: Downloaded newer image for nginx:1.14-alpine

2) pull busybox image

[root@host1 ~] # docker image pull busyboxUsing default tag: latestlatest: Pulling from library/busybox322973677ef5: Pull complete Digest: sha256:1828edd60c5efd34b2bf5dd3282ec0cc04d47b2ff9caa0b6d4f07a21d1c08084Status: Downloaded newer image for busybox:latest

3) View the downloaded images locally

[root@host1 ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEbusybox latest b534869c81f0 2 weeks ago 1.22MBnginx 1.14-alpine 8a2fb25a19f5 8 months ago 16MB

REPOSITORY: warehouse name

TAG: label

IMAGE ID: unique ID value

CREATED: when was it created

SIZE: siz

4) View the details of the image

[root@host1] # docker image ls-- no-truncREPOSITORY TAG IMAGE ID CREATED SIZEbusybox latest sha256:b534869c81f05ce6fbbdd3a3293e64fd032e059ab4b28a0e0d5b485cf904be4b 2 weeks ago 1.22MBnginx 1.14-alpine sha256:8a2fb25a19f5dc1528b7a3fabe8b3145ff57fe10e4f1edac6c718a3cf4aa4b73 8 months ago 16MB

IV. Operation of containers

1. Container operations include the following

Startup container: start

Stop Container: stop

Force stop: kill

Launch the container directly after creation: run

Pause container: pause

Unpause (continue) Container: unpause

You can also list all the containers: docker ps or docker container ls

2. Start the container operation

Start the container with the run command, including the following parameters

-t: here is to specify a terminal. If there is no terminal, you cannot log in to this container.

-I,-- interactive: you need to use this option if you want interactive access

-- name string: here is the name of the specified container

-- rm: automatically deletes the container object when the container stops

-d,-- detach: make the current container work in the background

-- network string: specify the network to which the container is added. If not, it defaults to a bridge network.

3. Start the container based on busybox

[root@host1] # docker run-- name bbox-it busybox/ #

At this point, the container is started and entered into the container's shell

At this point, you can see that the busybox container has been started on other terminals.

[root@host1 ~] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESdc696a322096 busybox "sh" About a minute ago Up About a minute bbox

Looking at the information in the busybox container, you can see that the process with id 1 is sh instead of init.

/ # psPID USER TIME COMMAND 1 root 0:00 sh 6 root 0:00 ps

Simulate apache in a busybox container

/ # mkdir / data/html-p / # echo "test page" > > / data/html/index.html/ # / # httpd-f-h / data/html/

You can also check the details of the container in bash

[root@host1 ~] # docker inspect bbox2 | grep IPAddress "SecondaryIPAddresses": null, "IPAddress": "172.17.0.3", "IPAddress": "172.17.0.3"

You can see that the address of this container is 172.16.0.3

In fact, after installing docker, the system generates a virtual network card docker0 by default, and the physical machine uses docker0 to communicate with the virtual machine.

[root@host1 ~] # ip addr 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 10002: ens33: mtu 1500 qdisc pfifo_fast state UP group default qlen 10003: ens37: mtu 1500 qdisc pfifo_fast state UP group default qlen 10004: docker0: mtu 1500 qdisc noqueue state UP group default link/ether 02:42:d5:cc:54:6d brd ff:ff:ff:ff:ff:ff inet 172.17.0.1 mtu 16 brd 172.17.255.255 scope global docker0 Valid_lft forever preferred_lft forever inet6 fe80::42:d5ff:fecc:546d/64 scope link valid_lft forever preferred_lft forever6: veth96dc278@if5: mtu 1500 qdisc noqueue master docker0 state UP group default 10: veth793182e@if9: mtu 1500 qdisc noqueue master docker0 state UP group default

The address of docker0 is 172.17.0.1

You can access the apache in the container with curl on the physical machine

[root@host1 ~] # curl 172.17.0.3test page

3. Stop and restart the container

Execute exit to exit the container

/ # exit [root@host1 ~] #

After exiting the container, the container just stops, but it still exists

Docker ps: view running containers

Docker ps-a: view all containers, including those that have been stopped

[root@host1 ~] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@host1 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESdc696a322096 busybox " Sh "2 hours ago Up 2 hours bbox

Restart the container that starts the stop, using the start command, possibly with two options

-I: interactive mode

-a: attach to the terminal

[root@host1] # docker start-I-a bbox

4. Delete containers that have been stopped

[root@host1 ~] # docker rm bboxbbox [root@host1 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Add the rm option when creating the container, which can be deleted automatically when the container stops

[root@host1] # docker run-- rm-it-- name bbox2 busybox/ # / # exit [root@host1 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

When deleting a container, you can specify a name to delete it, or you can specify the ID of the container to delete it.

When you specify an ID, you don't need to write all the ID content, just write the first part.

[root@host1 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9c2d1bbe32e8 busybox "sh" 3 seconds ago Exited (0) 1 second ago bbox [root@host1 ~] # docker rm 9c2d9c2d [root@host1 ~] # docker Ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

The following command deletes all stopped containers at once

[root@host1] # docker rm $(docker ps-a-Q)

5. Delete, export, and import images

Rmi: delete a local mirror

Load: importing image fil

Save: exporting image fil

Check which mirrors are currently available

[root@host1 ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEbusybox latest b534869c81f0 2 weeks ago 1.22MBnginx 1.14-alpine 8a2fb25a19f5 8 months ago 16MB

Export the image of busybox to tmp

[root@host1 ~] # docker save busybox:latest > / tmp/busybox-latest.tar.gz [root@host1 ~] # ls / tmp/busybox-latest.tar.gz

Delete a local busybox image

[root@host1 ~] # docker rmi b53Untagged: busybox:latestUntagged: busybox@sha256:1828edd60c5efd34b2bf5dd3282ec0cc04d47b2ff9caa0b6d4f07a21d1c08084Deleted: sha256:b534869c81f05ce6fbbdd3a3293e64fd032e059ab4b28a0e0d5b485cf904be4bDeleted: sha256:eac247cb7af5edc34d3620e8bce653d4af7d4e3a0427d487a97530c7fac0b841 [root@host1 ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEnginx 1.14-alpine 8a2fb25a19f5 8 months ago 16MB

Import image files from tmp

[root@host1 ~] # docker load] 1.437MB/1.437MBLoaded image: busybox:latest [root@host1 ~] # docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEbusybox latest b534869c81f0 2 weeks ago 1.22MBnginx 1.14-alpine 8a2fb25a19f5 8 months ago 16MB

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