docker学习记录一 --- docker run -d -p 80:80 --name webserver nginx 运行错误

    按照 什么是Docker · Docker —— 从入门到实践 - yeasy - GitBook 中

    Mac 安装docker方式进行安装测试(https://yeasy.gitbooks.io/docker_practice/install/mac.html),遇到以下问题,并进行记录~

问题一

运行 docker run -d -p 80:80 --name webserver nginx 提示:

docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (d8a338771744851ff152f9eb43954a4c85ccde2b652029a323d4d41663b52686): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).

解决方案

EADDRINUSE  stackoverflow的解释是:EADDRINUSE means that the port number which listen() tries to bind the server to is already in use, 即我们想要绑定的端口被占用了,

使用 lsof -i:80 查看80 端口是否被占用,如果有输出则表示被占用,没有输出则未被占用。我自己的查看确实被占用,被tomcat占用了

所以解决方案为修改端口号,其中第一个80,即冒号(:)前面的为端口号,可以修改为任意未被占用的端口,此处我修改为8080

也可以停掉使用80端口的服务,再重新执行(我没有尝试)

问题二

运行 docker run -d -p 8080:80 --name webserver nginx 提示:

docker: Error response from daemon: Conflict. The container name "/webserver" is already in use by container "06a951c1400c7d97094afd41e637bcebf51710a49391d5d45f80f97011199da3". You have to remove (or rename) that container to be able to reuse that name.

解决方案

重命名webserver名称,或者删除已经生成的container

我采用删除的方式,即 docker rm 06a951c1400c7d97094afd41e637bcebf51710a49391d5d45f80f97011199da3

docker rm

再次执行docker run -d -p 8080:80 --name webserver nginx

浏览器查看localhost:8080,出现

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

表示nginx启动成功。






你可能感兴趣的:(docker)