Not able to connect to an app running on a docker container via browser in mac - macos

I was trying to running a docker image from a gitlap repository as mentioned in https://codebabel.com/ci-gitlabci-docker/
I ran the image as shown below and it started
docker run -p 5000:50000 -it registry.gitlab.com/bacdef/flaskapp:latest
* Serving Flask app "helloworld" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 259-006-586
But when I try to access it via browser http://127.0.0.1:5000/ or http://localhost:5000/ or http://myip:5000/ it reply as follows
This page isn’t working 127.0.0.1 didn’t send any data.
ERR_EMPTY_RESPONSE
docker ps command output ias as follows
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
04cc5dc26ec5 registry.gitlab.com/bacdef/flaskapp:latest "python helloworld.py" 18 minutes ago Up 18 minutes 0.0.0.0:5000->50000/tcp hardcore_perlman
I am running it on a mac os.
Tried solution of similar questions like How to access webserver running in docker container from browser?, https://superuser.com/questions/1204030/cannot-access-to-http-localhost4000-after-i-map-this-port-number-to-docker but it does not work.
Can somebody please suggest what am I doing wrong?

Related

Docker on Win10 - is it possible to have multiple terminals?

I am new to Docker - installed DockerToolbox on Win10. And managed to run some basic docker examples. But I cannot seem to figure out how to access same container from multiple command line windows.
Quick online search suggested finding container ID (e.g. 2c7e29b9b666) via
docker ps
then running (I presume in new command window)
docker exec -it 2c7e29b9b666 bash
but that does not work in Win10.
Error message received is:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Edit: in the first window I started docker machine via:
docker-machine create --driver virtualbox tombox
and I can see 'tombox' in second window if I do:
docker-machine ls
Do I need to somehow reference 'tombox' when running docker commands in second window?

How to connect to a running docker image on a Mac?

I am following this tutorial on using docker images, and I am at the stage to run the example docker image like follows:
docker run -p 4000:80 friendlyhello
On the command line it seems ok:
>docker run -p 4000:80 friendlyhello
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
but when I try to open the page http://localhost:4000 on a web browser, it seems to be unable to connect (Safari and Firefox). On Firefox the error message is
Unable to connect
Firefox can't establish a connection to the server at localhost:4000.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
I also checked the file /etc/hosts and it contains the following entry
127.0.0.1 localhost
So what could be the problem?
I found this solution and tried the following command:
docker run -p 127.0.0.1:4000:80 friendlyhello
which still leads to the same problem. I also tried to open
`http://localhost:80`
again without success.

Docker port binding doesn't seem to work

I am running an example from Docker tutorial:
docker run -d -P nginx
This starts correctly as docker ps outputs the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5838f701c8f nginx "nginx -g 'daemon off" 3 minutes ago Up 2 minutes 0.0.0.0:32773->80/tcp, 0.0.0.0:32772->443/tcp compassionate_stallman
When I run docker inspect a5838f701c8f, I can see the IP of the container is 172.17.0.2.
However, for some reason going to localhost:32772 or 127.0.0.1:32772 or 0.0.0.0:32772 gives me ERR_CONNECTION_REFUSED. Going to 172.17.0.2:32772 just seems to endlessly load and load and never loads anything...
Could this be something with my host? I am using OSX 10.9.5 and docker 1.10.3, build 20f81dd.
You should test with URL 192.168.99.104:32772 If you are using Docker Machine.
Please take a look with https://docs.docker.com/machine/reference/ip/ to know how to get IP address with Docker Machine

dockerizing an application on Mac OS X

I installed boot2docker as explained on the docker website. Here are some command runs to show that I have things installed correctly:
$$:~ kv$ boot2docker start
Waiting for VM and Docker daemon to start...
...................ooo
Started.
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/kvantum/.boot2docker/certs/boot2docker-vm/key.pem
Your environment variables are already set correctly.
$$:~ kv$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 b39b81afc8ca 11 days ago 188.3 MB
hello-world latest e45a5af57b00 3 weeks ago 910 B
After this, I ran the following command:
docker run -t -i ubuntu:14.04 /bin/bash
Inside the container, I installed zeromq, and started a zeromq server on port 5555 using tcp.
My questions are following:
If I exit out of the container, will it save all the work I do inside it?
I have no idea how to connect to the server running on port 5555. I read something about exposing a port, but I am not sure how to go about doing that. I did an ifconfig inside the container, and tried to connect to the server from the host like this:
$$:~ kv$ ./zmq_client tcp://container_ip:5555
This did not work. Can someone please lists the steps I need to take in order to connect to the server running within the container.
For completion sake, I am providing the list of my environment variables:
TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/km/5kbpdx4s7cg4rmyc6d5q9l9r0000gq/T/
DOCKER_HOST=tcp://192.168.109.103:2376
Apple_PubSub_Socket_Render=/tmp/launch-1tWMHJ/Render
TERM_PROGRAM_VERSION=326
OLDPWD=/Users
TERM_SESSION_ID=262CBC8B-0A74-4B70-9F28-D9FA51FF713C
USER=kv
SSH_AUTH_SOCK=/tmp/launch-ZTWNGL/Listeners
__CF_USER_TEXT_ENCODING=0x1F7:0:0
DOCKER_TLS_VERIFY=1
__CHECKFIX1436934=1
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
PWD=/Users/kv
DOCKER_CERT_PATH=/Users/kv/.boot2docker/certs/boot2docker-vm
HOME=/Users/kv
SHLVL=1
LOGNAME=kv
LC_CTYPE=UTF-8
DISPLAY=/tmp/launch-rco9zt/org.macosforge.xquartz:0
_=/usr/bin/env
One last question I have is about code performance. So within my Mac OS X, I have a docker container running (which runs Ubuntu). If I run the application, like a zeromq based server inside the container, will it not be slower as compared to running it on Mac OS X directly. Please explain the benefits of using docker in such a scenario..
You should really do some more reading and research before turning to SO, then ask about anything you can't figure out. But:
No. If the container is "exited" you can restart it and your files will still be there, but once it is removed your files are gone. You can use docker commit to save them to an image, but the best bet is to use a Dockerfile.
docker run -p 5000:8000 image will expose port 8000 in the container as port 5000 on the host.
Yes, it will be slower due to the boot2docker VM. It would not be slower if you were running on a Linux host. The advantage is that zeromq is now running in an isolated container with all its dependencies.

Port forwarding issues trying to run a docker container

I am new to docker and nowhere near a networking expert, but I am seeing some strangeness when trying to run a docker container instance (right word?). I am running docker on OSX and set it up using the documentation found here: http://viget.com/extend/how-to-use-docker-on-os-x-the-missing-guide
Everything seems to have gone along fine, then I set up the port forwarding rules via these lines:
for i in {49000..49900};
do VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i";
done
I can confirm the boot2docker VM instance by checking the configuration within the Oracle VM VirtualBox Manager->Network->Adapter 1->Port Forwarding with the OSX.
I then run this command to get the container.
docker run -d -P dockerhub.emory.edu/ecoi_trunk:2
I do a "docker ps" and get this info.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f20bfefa2e97 dockerhub.emory.edu/ecoi_trunk:2 "/usr/sbin/apachectl 18 seconds ago Up 15 seconds 0.0.0.0:49153->443/tcp, 0.0.0.0:49154->80/tcp cranky_einstein
However, when I run an "lsof -i :49153" I see nothing is listening. I also can't reach the container via the "l****host:49153" in my browser. It just hangs.
What's strange is if I explicitly set the port (rather than allowing docker to assign one) via the following command:
docker run -d -p 49000:80 dockerhub.emory.edu/ecoi_trunk:2
It seems to work (lsof -i:49000 displays a TCP LISTEN), and I can confirm it's listening and the container is reachable via "l****host:49000". However, it's extremely slow. I'm not sure if either are related, but would welcome any tips or thoughts.

Resources