12

我有一组使用 Docker 在 Windows 10 中运行的容器,这是以下内容的输出docker-compose ps

> docker-compose ps
     Name                    Command               State                          Ports
--------------------------------------------------------------------------------------------------------------
db_mysql          docker-entrypoint.sh mysqld      Up      3306/tcp
elk               /usr/bin/supervisord -n -c ...   Up      0.0.0.0:81->80/tcp
php71-fpm-nginx   /config/bootstrap.sh             Up      443/tcp, 0.0.0.0:80->80/tcp, 0.0.0.0:9001->9001/tcp

这是输出docker inspect

> docker inspect php71-fpm-nginx
[
    {
        ...
            "NetworkMode": "anotherlampdocker_default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ],
                "9001/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "9001"
                    }
                ]
            },
        ...
        "Mounts": [
            {
                "Source": "/d/Development/www",
                "Destination": "/data/www",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            },
            ...
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "b96cf4c0f2c17d65659c31982b9200a79cca6f1c214770d31938204c493a6720",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "443/tcp": null,
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    }
                ],
                "9001/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "9001"
                    }
                ]
            },
            ...
            "Networks": {
                "anotherlampdocker_default": {
                    "IPAMConfig": null,
                    "Links": [
                        "db_mysql:db",
                        "db_mysql:db_mysql"
                    ],
                    "Aliases": [
                        "php-fpm",
                        "248e8c254eee"
                    ],
                    "NetworkID": "de1e10b63e6e5050809af59ac4d26b7cb691afd5805d1cf7f0492c702814f34d",
                    "EndpointID": "ccec71967c6100c5a9f3ad82d82bbb2a371f77e12c493bf05bfd15f2d188ce00",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:03"
                }
            }
        }
    }
]

我正在尝试访问http://localhost,但我不能。我也尝试过使用容器 IP 的含义http://172.18.0.3,但也不起作用。

当我说我不能时,这意味着以下消息:

无法访问此站点 172.18.0.3 响应时间过长。

相同的容器在 Linux 中完美运行。

这是c:\Windows\System32\drivers\etc\hosts文件的内容:

# localhost name resolution is handled within DNS itself.
    127.0.0.1       localhost

容器中的端口映射到docker-compose.yml文件中的主机:

services:
  php-fpm:
    container_name: "php71-fpm-nginx"
    build: php-fpm
    ports:
        - 80:80
        - 9001:9001
    environment:
        PHP_ERROR_REPORTING: 'E_ALL & ~E_DEPRECATED & ~E_NOTICE'
        STATUS_PAGE_ALLOWED_IP: '127.0.0.1'
    volumes:
        - D:\Development\www\:/data/www

我在这里缺少什么?

4

2 回答 2

1

您可以获取 docker 机器 IP 并访问应用程序:
1. 使用命令docker-machinedocker-machine ip
2. 或通过登录到启动 docker 时创建的 docker 映像并获取 eth1 ip

然后尝试:[docker-machine ip]:[port]

于 2018-07-24T09:49:35.010 回答
0

尝试登录到 php 的容器并检查 httpd 进程是否正在运行。

不使用docker-compose up-d 应该可以帮助您从容器中查看日志或docker-compose logs -f -t在之后使用docker-compose up -d

于 2019-06-09T02:27:44.657 回答