I'm following the tutorial "Getting started with Docker for Mac" but I'm unable to access the nginx home page at localhost. Every time I access localhost, the displayed page is "It works!" which is the default page contained in /Library/WebServer/Documents/index.html.en. I tried to kill all httpd services to remove the binding to the port 80 but it didn't change anything. I also checked that there wasn't any application that was running on port 80 and that neither Skype, MAMP or an Apache server who could be using this port was running.
I think that my Docker installation is correct as I'm able to run the docker --version, docker-machine --version and docker-compose --version without error. I'm running the container with the command described in the tutorial
docker run -d -p 80:80 --name webserver nginx but it doesn't work. I tried many ports but it didn't change anything.
Here is the output of a
docker ps
So I tried to access the app via 0.0.0.0:80 but it didn't work neither, it always redirect me to the page contained in Library/WebServer/Documents/index.html.en. I tried binding to all kind of ports (8080:80, 8181:81, 8181:80, 8181:8181 ...) and nothing never changed. In those case, I got a page telling me
"Safari can't connect to server. Safari can't open the page "0.0.0.0:8080" because Safari can't connect to server "0.0.0.0".
I also tried replacing localhost by 127.0.0.1 but I still have the issue.
If you need further explanations or have any question, ask me. Thanks in advance for your help
Related
I use Docker CE for Windows on latest Windows 10 and have built an image with a
script that runs a test against a web server.
(A litmus test suite for a WebDAV server to be exact, but I think the problem
is general.)
I run the web server on a Powershell console:
> wsgidav -p 8080 -H localhost
21:04:19.107 - <13348)> wsgidav INFO : Running WsgiDAV/3.0.0a3 Cheroot/6.4.0 Python/3.6.5
21:04:19.107 - <13348)> wsgidav INFO : Serving on http://localhost:8080 ...
From another Powershell console, I run my script in a Docker container (using FROM alpine).
The script starts and tries to access the endpoint, but does not succeed:
> docker pull mar10/litmus
> docker run --rm -p 8080:8080 mar10/litmus http://gateway.docker.internal:8080
-> running `basic':
0. init.................. FAIL (connection refused by `gateway.docker.internal' port 8080: Operation timed out)
I tried so far
Using the gateway.docker.internal hostname
using -p PORT:PORT
using --net=host
restarting the docker daemon (which interestingly sometimes also was neccessary to
fix timeouts in docker pull)
different IP addresses for the web server (127.0.0.1, localhost, 0.0.0.0, local IP)
Nothing worked so far (although the failure message may be different).
Maybe I just missed a working combination of the above, or any other trick?
FWIW, I was able to solve it by building the container with the --network host option and use a real IP of the client (instead of localhost or 0.0.0.0).
Details here: https://hub.docker.com/r/mar10/docker-litmus/
I have a docker image that runs a webserver and I would like to access it from my local OSX, but I'm having issues.
I start the container with: docker run -p 8000:8000 <container-name>
and I can see log messages telling me that the local server is listening on localhost:8000
I am able to get a successful response from running:
docker exec <IMAGE-ID> curl "http://localhost:8000/"
Addresses I've tried on my local OSX are:
http://localhost:8000/
http://<DOCKER-IP-172.17.0.2:8000/
Neither of those work. Any suggestions?
Container is built from golang:1.8
Docker Version: Version 17.03.1-ce-mac5 (16048)
MacOS Sierra: 10.12.4
Firewall is turned off for testing purposes
I've tried the same process on Ubuntu 16.04 and no luck their either.
The newer versions of docker use vpnkit on OSX to manage the port forwarding to the containers... you should allow vpnkit through your firewall if you want to expose the container ports.
Also, in your Go code, make sure to bind to 0.0.0.0 rather than 127.0.0.1 for your webserver code.
Problem: Network is not routed to the host machine.
e.g.:
docker run -tip 80:8080 httpd
does NOT result in apache responding on localhost:8080 on the host machine or on docker.local:8080 or anything like that. If I try to connect from inside, the container works fine:
docker run -ti debian
curl 172.17.0.2
<html><body><h1>It works!</h1></body></html>
It seems that on the Docker side itself is everything just fine.
On docker ps you get: ... 80/tcp, 0.0.0.0:80->8080/tcp ...
Environment: New, clean OS installation - OSX Sierra 10.12.2, Docker.app Version 1.13.0 stable (plus 1.13.0. beta and 1.12.0 beta tried as well with same results).
Assumption: There is something broken in between Docker and OS. I guess that this 'something' is Hyperkit (which is like a black box for me). There might be some settings broken by build script from here: http://bigchaindb-examples.readthedocs.io/en/latest/install.html#the-docker-way which is docker-machine centric, which fact I've probably underestimated. Funny fact is also that this was a new install: this build script was the first thing I've done on it -- I don't know if the networking actually worked before.
Question: How do I diagnose this stuff. I would like to be able to trace where exactly the traffic gets lost and fix it accordingly.
Your command line has the ports reversed:
docker run -tip 8080:80 httpd
That's the host port first, with an optional interface to bind, followed by the container port. You can also see that in the docker ps output where port 80 on the host is mapped to port 8080 inside the container.
The other problem some have is the service inside the container needs to listen on all container interfaces (0.0.0.0), not the localhost interface of the container, otherwise the proxy can't forward traffic to it. However, the default settings from official images won't have this issue and your curl command shows that doesn't apply to you.
In my current job we have development environment made with docker-compose.
One container is nginx, which provide routing to other containers.
Everything seems fine and work to my colleague on windows and osx. But on my system (osx El Capitan), there is problem with accessing nginx container on port 80.
There is setup of container from docker-compose.yml
nginx:
build: ./dockerbuild/nginx
ports:
- 80:80
links:
- php
volumes_from:
- app
... and more
In ./dockerbuild/nginx there is nothing special, just nginx config as we know it from everywhere.
When I run everyting with docker-compose create and docker-compose start. Then docker ps give me
3b296c1e4775 docker_nginx "nginx -g 'daemon off" About an hour ago Up 47 minutes 0.0.0.0:80->80/tcp, 443/tcp docker_nginx_1
But when I try to access it for example via curl I get error. curl: (7) Failed to connect to localhost port 80: Connection refused
I try to run container with port 81 and everything works fine.
Port is really binded to docker
22:47 $ sudo lsof -i -n -P | grep TCP
...
com.docke 14718 schovi 38u IPv4 0x6e9c93c51ec4b617 0t0 TCP *:80 (LISTEN)
...
Firewall in osx is turned off and I have no other security.
if you are using docker-for-mac:
Accessing by localhost:80 is correct, though you still have to ensure you do not have a local apache/nginx service running. Often leftovers from boxen/homebrew exist binding that port, because thats what developers did back then :)
if you are using dockertoolbox/virtualbox/whatever hypervisor
You will not be able to access it by localhost, by by the docker-machine ip, so write docker-machine ip default and the use http://$ip:80 in your browser
if that does not help
Ensure your nginx container actually does work, so connect to the container: docker exec -i -t <containerid> bash
and then run ps aux nginx or if telnet is installed try to connect to localhost
Solved!
Problem was, that long long time ago I installed pow (super simple automated rails server which run application on app_name.local domain). And this beast left LaunchAgent script which update pf to forward port 80 to pow port.
In my current job we have development environment made with docker-compose.
A privilege to use.
[W]hen I try to access [nginx on port 80] for example via curl I get error.
Given there's nothing from causing you from accessing docker on your host os you should look at the app running inside the container to ensure it's binding to the correct host, e.g. 0.0.0.0 and not localhost.
For example, if you're running Nuxt inside a container with nuxt-ts observe Nuxt will default to localhost thereby causing the container not to connect to the docker network whereas npx nuxt-ts -H 0.0.0.0 gets things squared away with the container's internal server connecting to the ip of the docker network used (verify ip like docker container inspect d8af01990363).
I have docker toolbox 1.8.2c installed on my Mac running yosemite. If I launch hello-world-nginx from the docker hub in Kitematic, I can connect to its TCP port without an issue.
When trying to do the same thing from the CLI, I can't connect. Why?
Here is what I am running on the docker CLI, which looks to me to be pretty standard:
docker run -d -i -t -P kitematic/hello-world-nginx /bin/sh
In the case above, docker ps shows that port 80 is mapped to 0.0.0.0:32769. So I try and connect on 192.168.99.100:32769 (that's my docker machine IP) and I can't connect.
I want to use the CLI so I can set the hostname/fqdn on the container, which it doesn't look like Kitematic supports. Here is another thing I tried, with the IP address of my docker machine in the args:
docker run -d -i -t -p 192.168.99.100:32769:80 -h nginx.example.com kitematic/hello-world-nginx /bin/sh
This doesn't work either.
In each case, the container starts successfully and I can attach to it with out an issue.
What am I doing wrong?
I had the same problem, but in windows 10 pro witn the same image kitematic/hello-world-nginx. Kitematic was open a wep page by default with Internet Explorer and the message was inmediatetly can't connect, later I tried with another web browers, chrome, and it worked. maybe if you try with another web browser, this problem can be solved.