坑一
坑: 学习docker网络时,进入tomcat容器发现ip addr不可以使用
[root@VM-16-15-centos ~]# docker run -it --name tomcat04 tomcat /bin/bash root@828d1e76b08d:/usr/local/tomcat# ip addr bash: ip: command not found
原因: 通过查找发现,我们下载的tomcat镜像是精简版的,利用这个镜像打开一个容器,发现没有ip addr命令。所以导致错误
解决办法:
先进入docker
容器中docker exec -it xxx /bin/bash
执行
ip addr
命令root@828d1e76b08d:/usr/local/tomcat# apt update Get:1 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB] Get:2 http://deb.debian.org/debian bullseye InRelease [116 kB] Get:3 http://security.debian.org/debian-security bullseye-security/main amd64 Packages [154 kB] Get:4 http://deb.debian.org/debian bullseye-updates InRelease [39.4 kB] Get:5 http://deb.debian.org/debian bullseye/main amd64 Packages [8182 kB]
执行
apt install -y iproute2
root@828d1e76b08d:/usr/local/tomcat# apt install -y iproute2 Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libatm1 libbpf0 libcap2 libcap2-bin libelf1 libmnl0 libpam-cap libxtables12 Suggested packages: iproute2-doc
测试
root@828d1e76b08d:/usr/local/tomcat# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 108: eth0@if109: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group >default link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0 valid_lft forever preferred_lft forever
坑二
坑: 在学习docker网络部署时,进入tomcat容器发现ping命令,不存在,原因如上,所以需要进行ping命令的安装
root@828d1e76b08d:/usr/local/tomcat# ping bash: ping: command not found
先进入
docker
容器中docker exec -it xxx /bin/bash
执行
apt-get update
root@828d1e76b08d:/usr/local/tomcat# apt-get update Hit:1 http://deb.debian.org/debian bullseye InRelease Hit:2 http://deb.debian.org/debian bullseye-updates InRelease Hit:3 http://security.debian.org/debian-security bullseye-security InRelease Reading package lists... Done
执行
apt install iputils-ping
root@828d1e76b08d:/usr/local/tomcat# apt install iputils-ping Reading package lists... Done Building dependency tree... Done Reading state information... Done The following NEW packages will be installed: iputils-ping 0 upgraded, 1 newly installed, 0 to remove and 38 not upgraded. Need to get 49.8 kB of archives. After this operation, 116 kB of additional disk space will be used. Get:1 http://deb.debian.org/debian bullseye/main amd64 iputils-ping amd64 >3:20210202-1 [49.8 kB] Fetched 49.8 kB in 2s (28.4 kB/s) debconf: delaying package configuration, since apt-utils is not installed Selecting previously unselected package iputils-ping. (Reading database ... 12909 files and directories currently installed.) Preparing to unpack .../iputils-ping_3%3a20210202-1_amd64.deb ... Unpacking iputils-ping (3:20210202-1) ... Setting up iputils-ping (3:20210202-1) ...