怎么使用docker部署centos系统测试环境

服务器   发布日期:2024年10月31日   浏览次数:387

今天小编给大家分享一下怎么使用docker部署centos系统测试环境的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

一、检查本地服务器系统版本

  1. [root@node ~]# cat /etc/os-release
  2. NAME="CentOS Linux"
  3. VERSION="7 (Core)"
  4. ID="centos"
  5. ID_LIKE="rhel fedora"
  6. VERSION_ID="7"
  7. PRETTY_NAME="CentOS Linux 7 (Core)"
  8. ANSI_COLOR="0;31"
  9. CPE_NAME="cpe:/o:centos:centos:7"
  10. HOME_URL="https://www.centos.org/"
  11. BUG_REPORT_URL="https://bugs.centos.org/"
  12. CENTOS_MANTISBT_PROJECT="CentOS-7"
  13. CENTOS_MANTISBT_PROJECT_VERSION="7"
  14. REDHAT_SUPPORT_PRODUCT="centos"
  15. REDHAT_SUPPORT_PRODUCT_VERSION="7"
  1. [root@node ~]# cat /etc/centos-release
  2. CentOS Linux release 7.6.1810 (Core)

二、检查docker版本

  1. [root@node ~]# docker version
  2. Client: Docker Engine - Community
  3. Version: 20.10.17
  4. API version: 1.41
  5. Go version: go1.17.11
  6. Git commit: 100c701
  7. Built: Mon Jun 6 23:05:12 2022
  8. OS/Arch: linux/amd64
  9. Context: default
  10. Experimental: true
  11. Server: Docker Engine - Community
  12. Engine:
  13. Version: 20.10.17
  14. API version: 1.41 (minimum version 1.12)
  15. Go version: go1.17.11
  16. Git commit: a89b842
  17. Built: Mon Jun 6 23:03:33 2022
  18. OS/Arch: linux/amd64
  19. Experimental: false
  20. containerd:
  21. Version: 1.6.6
  22. GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
  23. runc:
  24. Version: 1.1.2
  25. GitCommit: v1.1.2-0-ga916309
  26. docker-init:
  27. Version: 0.19.0
  28. GitCommit: de40ad0

三、检查docker状态

  1. [root@node ~]# systemctl status docker
  2. docker.service - Docker Application Container Engine
  3. Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  4. Active: active (running) since Fri 2022-11-04 09:12:32 CST; 18h ago
  5. Docs: https://docs.docker.com
  6. Main PID: 10162 (dockerd)
  7. Tasks: 62
  8. Memory: 3.6G
  9. CGroup: /system.slice/docker.service
  10. ├─10162 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
  11. ├─21803 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 27217 -container-ip 172.17.0.2 -container-port 27017
  12. ├─21808 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 27217 -container-ip 172.17.0.2 -container-port 27017
  13. ├─33495 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3548 -container-ip 172.17.0.3 -container-port 3306
  14. ├─33501 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3548 -container-ip 172.17.0.3 -container-port 3306
  15. ├─43634 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.17.0.4 -container-port 80
  16. ├─43640 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8080 -container-ip 172.17.0.4 -container-port 80
  17. ├─59700 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8098 -container-ip 172.17.0.5 -container-port 80
  18. └─59705 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8098 -container-ip 172.17.0.5 -container-port 80
  19. Nov 04 10:00:54 node dockerd[10162]: time="2022-11-04T10:00:54.645415843+08:00" level=info msg="Attempting next endpoint for pull after ...unknown"
  20. Nov 04 11:46:29 node dockerd[10162]: time="2022-11-04T11:46:29.261326827+08:00" level=info msg="Attempting next endpoint for pull after ...unknown"
  21. Nov 04 11:47:04 node dockerd[10162]: time="2022-11-04T11:47:04.769147449+08:00" level=info msg="Download failed, retrying (1/5): net/htt...timeout"
  22. Nov 04 11:51:16 node dockerd[10162]: time="2022-11-04T11:51:16.548891252+08:00" level=error msg="Not continuing with pull after error: c...anceled"
  23. Nov 04 11:55:42 node dockerd[10162]: time="2022-11-04T11:55:42.370401579+08:00" level=info msg="ignoring event" container=ac860c2aa163e2...kDelete"
  24. Nov 04 14:31:26 node dockerd[10162]: time="2022-11-04T14:31:26.826919720+08:00" level=warning msg="reference for unknown type: applicati...:latest"
  25. Nov 04 14:31:27 node dockerd[10162]: time="2022-11-04T14:31:27.105606415+08:00" level=warning msg="Error persisting manifest" digest="sha256:f2e...
  26. Nov 04 14:31:27 node dockerd[10162]: time="2022-11-04T14:31:27.105748609+08:00" level=warning msg="Image docker.io/romainlecomte/lighthttpd-dock...
  27. Nov 04 14:45:39 node dockerd[10162]: time="2022-11-04T14:45:39.628278832+08:00" level=error msg="Not continuing with pull after error: m...unknown"
  28. Nov 04 14:45:39 node dockerd[10162]: time="2022-11-04T14:45:39.628408475+08:00" level=error msg="Handler for POST /v1.41/images/create r...unknown"
  29. Hint: Some lines were ellipsized, use -l to show in full.

四、下载centos镜像

  1. [root@node ~]# docker pull centos:7
  2. 7: Pulling from library/centos
  3. Digest: sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
  4. Status: Image is up to date for centos:7
  5. docker.io/library/centos:7

五、创建centos容器

1.运行cnentos容器

  1. [root@node ~]# docker run -it --name centos_test centos:7 /bin/bash
  2. [root@db4f4dfa3a84 /]#

2.进入容器内

  1. [root@node ~]# docker run -it --name centos_test centos:7 /bin/bash
  2. [root@db4f4dfa3a84 /]# ls
  3. anaconda-post.log bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
  4. [root@db4f4dfa3a84 /]# pwd
  5. /

六、centos容器内部测试

1.安装ifconfig命令的软件包

  1. [root@db4f4dfa3a84 /]# yum -y install net-tools
  2. Loaded plugins: fastestmirror, ovl
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.huaweicloud.com
  5. * extras: mirrors.ustc.edu.cn
  6. * updates: mirrors.ustc.edu.cn
  7. Resolving Dependencies
  8. --> Running transaction check
  9. ---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be installed
  10. --> Finished Dependency Resolution
  11. Dependencies Resolved
  12. ===================================================================================================================================================
  13. Package Arch Version Repository Size
  14. ===================================================================================================================================================
  15. Installing:
  16. net-tools x86_64 2.0-0.25.20131004git.el7 base 306 k
  17. Transaction Summary
  18. ===================================================================================================================================================
  19. Install 1 Package
  20. Total download size: 306 k
  21. Installed size: 917 k
  22. Downloading packages:
  23. net-tools-2.0-0.25.20131004git.el7.x86_64.rpm | 306 kB 00:00:00
  24. Running transaction check
  25. Running transaction test
  26. Transaction test succeeded
  27. Running transaction
  28. Installing : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
  29. Verifying : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
  30. Installed:
  31. net-tools.x86_64 0:2.0-0.25.20131004git.el7
  32. Complete!

2.查看容器内IP地址

  1. [root@db4f4dfa3a84 /]# ifconfigeth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.6 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:ac:11:00:06 txqueuelen 0 (Ethernet) RX packets 7037 bytes 25618849 (24.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4655 bytes 269171 (262.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@db4f4dfa3a84 /]# ifconfig
  2. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  3. inet 172.17.0.6 netmask 255.255.0.0 broadcast 172.17.255.255
  4. ether 02:42:ac:11:00:06 txqueuelen 0 (Ethernet)
  5. RX packets 7037 bytes 25618849 (24.4 MiB)
  6. RX errors 0 dropped 0 overruns 0 frame 0
  7. TX packets 4655 bytes 269171 (262.8 KiB)
  8. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  9. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  10. inet 127.0.0.1 netmask 255.0.0.0
  11. loop txqueuelen 1000 (Local Loopback)
  12. RX packets 0 bytes 0 (0.0 B)
  13. RX errors 0 dropped 0 overruns 0 frame 0
  14. TX packets 0 bytes 0 (0.0 B)
  15. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

3.测试与宿主机网络连通情况

  1. [root@db4f4dfa3a84 /]# ping 192.168.3.166 -c 6
  2. PING 192.168.3.166 (192.168.3.166) 56(84) bytes of data.
  3. 64 bytes from 192.168.3.166: icmp_seq=1 ttl=64 time=0.091 ms
  4. 64 bytes from 192.168.3.166: icmp_seq=2 ttl=64 time=0.130 ms
  5. 64 bytes from 192.168.3.166: icmp_seq=3 ttl=64 time=0.104 ms
  6. 64 bytes from 192.168.3.166: icmp_seq=4 ttl=64 time=0.109 ms
  7. 64 bytes from 192.168.3.166: icmp_seq=5 ttl=64 time=0.075 ms
  8. 64 bytes from 192.168.3.166: icmp_seq=6 ttl=64 time=0.092 ms
  9. --- 192.168.3.166 ping statistics ---
  10. 6 packets transmitted, 6 received, 0% packet loss, time 5010ms
  11. rtt min/avg/max/mdev = 0.075/0.100/0.130/0.018 ms

4.让centos容器后台运行

从容器退出,但不停止容器: Ctrl+P+Q

  1. [root@node ~]# docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. db4f4dfa3a84 centos:7 "/bin/bash" 11 minutes ago Up 11 minutes centos_test

以上就是怎么使用docker部署centos系统测试环境的详细内容,更多关于怎么使用docker部署centos系统测试环境的资料请关注九品源码其它相关文章!