我正在尝试在macOS上构建Flask / PostgreSQL / SQLAlchemy / Alembic / libpq-dev / psycopg2 Web应用程序。 我从未使用过Docker,所以我想尝试一下。我安装了它,并正在执行“入门”步骤。
$ docker --version
Docker version 18.06.0-ce, build 0ffa825
$ docker-compose --version
docker-compose version 1.22.0, build f46880f
$ docker-machine --version
docker-machine version 0.15.0, build b48dc28d
然后我进入第二步:
$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
一切都像文档一样工作,但是随后我尝试了下一步,“启动Docker化的Web服务器”,这就是发生的事情...
$ docker run -d -p 80:80 --name webserver nginx
159841d356d8cf6b16fd592b22daa76f3a734a8b35bf24f9f83b3dce6486d49e
docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (2d93210e398bf70794b706d6e07ca2c2b78297b9f337271710f4c62be8a79b7d): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).
因此,我搜索了该错误,并在诸如github和stackoverflow之类的论坛上找到了许多此错误或类似错误的实例。我尝试了所有可以解决的步骤。
sudo netstat -nl -p tcp | grep 8123
Password:
MyMacName@My-MacBook-Pro ~
$ sudo netstat -nl -p tcp | head
Active Internet connections
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 0 10.0.0.94.49655 54.174.175.30.443 ESTABLISHED
tcp4 0 0 10.0.0.94.49654 192.30.253.117.443 ESTABLISHED
tcp4 0 0 10.0.0.94.49653 50.16.137.101.443 ESTABLISHED
tcp4 0 0 10.0.0.94.49652 192.30.253.125.443 ESTABLISHED
tcp4 0 0 10.0.0.94.49651 151.101.4.133.443 ESTABLISHED
tcp4 0 0 10.0.0.94.49650 151.101.4.133.443 ESTABLISHED
tcp4 0 0 10.0.0.94.49649 151.101.56.133.443 ESTABLISHED
tcp4 0 0 10.0.0.94.49648 34.238.78.202.443 ESTABLISHED
但是我不知道该怎么做,所以它本身对我没有任何好处。所以我找到了这些步骤并进行了尝试...
$ docker stop $(docker ps -a -q)
2eb7a75a5fd7
$ docker rm $(docker ps -a -q);
2eb7a75a5fd7
$ docker volume rm $(docker volume ls -qf dangling=true)
"docker volume rm" requires at least 1 argument.
See 'docker volume rm --help'.
Usage: docker volume rm [OPTIONS] VOLUME [VOLUME...]
Remove one or more volumes
$ docker network rm $(docker network ls -q)
Error response from daemon: bridge is a pre-defined network and cannot be removed
Error response from daemon: host is a pre-defined network and cannot be removed
Error response from daemon: none is a pre-defined network and cannot be removed
$ sudo lsof -nP | grep LISTEN
Password:
httpd 97 root 4u IPv6 0xb250f70d0ca8909d 0t0 TCP *:80 (LISTEN)
mysqld 113 _mysql 19u IPv6 0xb250f70d0ca8a1dd 0t0 TCP *:3306 (LISTEN)
mysqld 113 _mysql 22u IPv6 0xb250f70d0ca8a79d 0t0 TCP *:33060 (LISTEN)
awacsd 215 root 8u IPv6 0xb250f70d0ca8b31d 0t0 TCP [fd24:e01e:118f:e97:75e1:c8cf:5efb:c34c]:4488 (LISTEN)
httpd 234 MyMacName 4u IPv6 0xb250f70d0ca8909d 0t0 TCP *:80 (LISTEN)
httpd 235 MyMacName 4u IPv6 0xb250f70d0ca8909d 0t0 TCP *:80 (LISTEN)
httpd 236 MyMacName 4u IPv6 0xb250f70d0ca8909d 0t0 TCP *:80 (LISTEN)
httpd 237 MyMacName 4u IPv6 0xb250f70d0ca8909d 0t0 TCP *:80 (LISTEN)
httpd 238 MyMacName 4u IPv6 0xb250f70d0ca8909d 0t0 TCP *:80 (LISTEN)
rapportd 402 MyMacName 3u IPv4 0xb250f70d1db86225 0t0 TCP *:58588 (LISTEN)
rapportd 402 MyMacName 4u IPv6 0xb250f70d0ca8851d 0t0 TCP *:58588 (LISTEN)
postgres 441 MyMacName 5u IPv6 0xb250f70d0ca8965d 0t0 TCP [::1]:5432 (LISTEN)
postgres 441 MyMacName 6u IPv6 0xb250f70d0ca8ad5d 0t0 TCP [fe80:1::1]:5432 (LISTEN)
postgres 441 MyMacName 7u IPv4 0xb250f70d0cf3db85 0t0 TCP 127.0.0.1:5432 (LISTEN)
Adobe\x20 567 MyMacName 13u IPv4 0xb250f70d1335fe45 0t0 TCP 127.0.0.1:15292 (LISTEN)
Adobe\x20 567 MyMacName 31u IPv4 0xb250f70d0ecd1225 0t0 TCP 127.0.0.1:15393 (LISTEN)
httpd 744 MyMacName 4u IPv6 0xb250f70d0ca8909d 0t0 TCP *:80 (LISTEN)
node 746 MyMacName 15u IPv4 0xb250f70d0e5be225 0t0 TCP 127.0.0.1:49255 (LISTEN)
httpd 748 MyMacName 4u IPv6 0xb250f70d0ca8909d 0t0 TCP *:80 (LISTEN)
httpd 749 MyMacName 4u IPv6 0xb250f70d0ca8909d 0t0 TCP *:80 (LISTEN)
cupsd 3415 root 5u IPv6 0xb250f70d13944e9d 0t0 TCP [::1]:631 (LISTEN)
cupsd 3415 root 6u IPv4 0xb250f70d16c228c5 0t0 TCP 127.0.0.1:631 (LISTEN)
pgAdmin4 4253 MyMacName 14u IPv4 0xb250f70d0e7638c5 0t0 TCP 127.0.0.1:54792 (LISTEN)
不幸的是,我也不知道这意味着什么。我认为问题可能在于最后一行显示PostgreSQL的PgAdmin4正在运行。因此进入Utility Monitor并强制退出。仍然有5-6个“ postgres”实例由于某种原因我无法强制退出。这一定与我的Mac附带某种postgres有关。
我在这里粘贴的任何内容是否可以帮助认识Docker的人诊断出我可以做些什么来克服这个问题?
答案 0 :(得分:2)
我遇到了同样的问题,但是docker restart并没有帮助。 因此,我启动了Kitematic并打开了我的postgres容器的设置,然后再次将配置的端口更改为 localhost:5432 。现在对我有用。
或使用以下命令:
docker stop postgres
docker commit postgres postgres2
docker run -p 54320:5432 -td postgres2
答案 1 :(得分:1)
$ docker run -d -p 80:80 --name webserver nginx
159841d356d8cf6b16fd592b22daa76f3a734a8b35bf24f9f83b3dce6486d49e
docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (2d93210e398bf70794b706d6e07ca2c2b78297b9f337271710f4c62be8a79b7d): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).
您可以docker -d -p [another_host_port]:80-命名网络服务器nginx将其绑定到另一个端口而不是80,我认为还有另一个应用程序或实例正在使用您找不到的端口80。
Docker端口绑定语法:host:guest
。
(https://docs.docker.com/engine/reference/run/#expose-incoming-ports)
nginx在Docker实例中运行并公开80本身,因此我们将nginx的80(来宾)映射到所需的端口(主机),然后通过该端口访问应用程序。