12

I have a set of containers running in Windows 10 with Docker, this is the output of 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

And this is the output of 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"
                }
            }
        }
    }
]

I am trying to access http://localhost but I can't. I've tried also using the container IP meaning http://172.18.0.3 and doesn't work either.

When I say I can't it means the following message:

This site can’t be reached 172.18.0.3 took too long to respond.

The same container works perfectly in Linux.

This is the content of c:\Windows\System32\drivers\etc\hosts file:

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

The ports from the container are mapped to the host in the docker-compose.yml file:

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

What I am missing here?

ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • Have you mapped local port to docker container port? – Rao Dec 15 '16 at 02:57
  • @Rao yes, look at the edit on the OP – ReynierPM Dec 15 '16 at 03:02
  • What happens if you curl http://localhost from inside the php/nginx container? You can get shell in container using `docker exec -it php71-fpm-nginx bash` – jmiraglia Dec 15 '16 at 05:25
  • connecting to the container with localhost is not possible currently due to a bug in the windows 10 NAT stack. – Falco Alexander Dec 15 '16 at 10:09
  • @jmiraglia yes I can get shell into the container and this is the result of the CURL command: `[root@248e8c254eee /]# curl localhost curl: (7) Failed connect to localhost:80; Connection refused` – ReynierPM Dec 15 '16 at 11:13
  • @FalcoAlexander then if localhost can't be used what's the right way? – ReynierPM Dec 15 '16 at 11:14
  • If you can shell into the container, can you see if nginx is up and running? You may want to try separating php and nginx into separate containers. If you want, you can check out, my repo: https://github.com/onlinespaces/docker-project-base. I am not an expert but this works for me. – ScottCollier Dec 15 '16 at 12:59
  • @ScottCollier ohh that good really nice, I will give it a try, did you tried on Windows already? – ReynierPM Dec 15 '16 at 13:07
  • Yes, I use it at work on a mac and on windows at home. The only issue that I had on Windows is that you interactive containers are not supported. So, you can either do ```docker exec -it php-fpm bash``` as @jmiraglia stated above or you can connect via SSH and get a full shell. I prefer to SSH into it because I like to do everything inside the container to keep my Windows machine as clean as possible. I also like the pretty git information in the prompt which did not work when I used ```docker exec```. – ScottCollier Dec 15 '16 at 14:18
  • @ScottCollier after clone the repository, rename the file `.env` and try the command `docker-compose build` it ends with the following error `ERROR: Service 'db' failed to build: One or more build-args [DEFAULT_CHAR_SET COLLATION_SERVER CHAR_SET_SERVER] were not consumed, failing build.`, what I did miss here? – ReynierPM Dec 16 '16 at 01:07
  • @ReynierPM you can connect to the container either by its NAT IP (usually 172.* range) or externally from another computer with your "normal" IP – Falco Alexander Dec 16 '16 at 09:51
  • Sorry, I was working on the repo at the time and accidentally deleted some lines. You can download the new mysql/Dockerfile here: https://github.com/onlinespaces/docker-project-base/blob/master/docker/mysql/Dockerfile – ScottCollier Dec 19 '16 at 11:25
  • Does this answer your question? [Not open web page on port 8080 when start tomcat inside Docker](https://stackoverflow.com/questions/59547203/not-open-web-page-on-port-8080-when-start-tomcat-inside-docker) – ErikMD Jun 06 '20 at 18:47

2 Answers2

1

You can get the docker machine IP and access the application:
1. Using command docker-machine : docker-machine ip
2.or By login to the docker image which is created when you start the docker and getting the eth1 ip

Then try : [docker-machine ip]:[port]

Savio Mathew
  • 719
  • 1
  • 7
  • 14
0

Try login to the php's container and check if the httpd process is running.

Use docker-compose up without -d should help you to see the log from container or use docker-compose logs -f -t after docker-compose up -d

N.Kaewkhat
  • 19
  • 3