【问题】docker run 时候的端口占用问题

现在希望启动一个docker container, 把 container 中的 80 端口映射到宿主机。

[root@cmdb2 ~]# docker run -p 80:80  -it 9d1c954badc7 /bin/bash
[root@cmdb2 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                NAMES
870ac9aaf081        9d1c954badc7        "/bin/bash"         3 minutes ago       Up 3 minutes        0.0.0.0:80->80/tcp   adoring_mestorf
[root@cmdb2 ~]# lsof -i:80
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 7056 root    4u  IPv6 128759      0t0  TCP *:http (LISTEN)
[root@cmdb2 ~]# netstat -antp|grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      7056/docker-proxy
[root@cmdb2 ~]# docker run -p 80:80  -it 9d1c954badc7 /bin/bash
docker: Error response from daemon: driver failed programming external connectivity on endpoint romantic_wing (d5fd42844e1838b26c123b002b6c0f5f3aaadcd7e8e8ff922cb2c23c33891bf4): Bind for 0.0.0.0:80 failed: port is already allocated.

扩展阅读:

centos7 下 lsof 需要单独安装:
yum install lsof

你可能感兴趣的:(【问题】docker run 时候的端口占用问题)