启用docker容器报端口被占用:
[root@takeout docker]# docker-compose -f appDev.yml up -d
docker_seaweedfs-volume_1 is up-to-date
docker_seaweedfs-master_1 is up-to-date
docker_zookeeper_1 is up-to-date
docker_seaweedfs-filer_1 is up-to-date
docker_catering-mysql_1 is up-to-date
docker_seaweedfs-cronjob_1 is up-to-date
docker_seaweedfs-s3_1 is up-to-date
docker_kafka_1 is up-to-date
Creating docker_catering-app_1 ... error
ERROR: for docker_catering-app_1 Cannot start service catering-app: driver failed programming external connectivity on endpoint docker_catering-app_1 (44b6313f082745c9e222d199c385c36a088e687fa785688b54f56875a4d2d62c): Bind for 0.0.0.0:8081 failed: port is already allocated
ERROR: for catering-app Cannot start service catering-app: driver failed programming external connectivity on endpoint docker_catering-app_1 (44b6313f082745c9e222d199c385c36a088e687fa785688b54f56875a4d2d62c): Bind for 0.0.0.0:8081 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
[root@takeout docker]#
查看端口被哪个PID占用:
[root@takeout docker]# lsof -i |grep 8081
[root@takeout docker]# netstat -tnlp | grep 8081
删除占用端口的进程:
[root@takeout docker]# kill -9 [PID]
如果启用应用的时候,还是报端口被占用,
查看防火墙规则:
[root@takeout docker]# iptables -t nat -nL --line-number |grep 8081
16 DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8081 to:172.18.0.10:8080
[root@takeout docker]#
清空防火墙规则:
[root@takeout docker]# iptables -t nat -F
再重启应用,还是报端口被占用,
这是因为 docker-proxy 依然绑定着端口
查看docker-proxy占用端口的情况:
[root@takeout docker]# ps -aux | grep -v grep | grep docker-proxy
root 12228 0.0 0.0 0 0 ? Z 10:01 0:04 [docker-proxy]
root 17234 0.0 0.0 116376 76 ? Sl 3月31 0:01 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 53380 -container-ip 172.18.0.2 -container-port 8080
root 17246 0.0 0.0 181912 60 ? Sl 3月31 0:01 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 18080 -container-ip 172.18.0.2 -container-port 18080
root 17460 0.0 0.0 190108 108 ? Sl 3月31 0:01 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 19333 -container-ip 172.18.0.5 -container-port 19333
root 17473 0.0 0.0 268928 0 ? Sl 3月31 0:01 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9333 -container-ip 172.18.0.5 -container-port 9333
root 19671 0.0 0.0 181912 48 ? Sl 3月18 0:03 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8333 -container-ip 172.18.0.3 -container-port 8333
root 19726 0.0 0.0 190108 48 ? Sl 3月18 0:03 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 18888 -container-ip 172.18.0.4 -container-port 18888
root 19776 0.0 0.0 781180 320 ? Sl 3月18 1:28 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8888 -container-ip 172.18.0.4 -container-port 8888
root 20231 0.0 0.0 116376 68 ? Sl 3月18 0:03 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 2181 -container-ip 172.18.0.6 -container-port 2181
root 20246 0.0 0.0 181912 48 ? Sl 3月18 0:03 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3306 -container-ip 172.18.0.7 -container-port 3306
root 20258 0.0 0.0 190108 48 ? Sl 3月18 0:03 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9092 -container-ip 172.18.0.8 -container-port 9092
root 30790 0.0 0.0 116376 72 ? Sl 4月07 0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 80 -container-ip 172.17.0.2 -container-port 80
[root@takeout docker]#
实在没有招了,只能重启docker服务
systemctl restart docker