map internal port 80 to localhost port 80 in docker - docker

I had ran the docker image and it is showing the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cbcc0a6d5c1e programming_applicationserver "bin/wait-for-it.sh …" About an hour ago Up About an hour 0.0.0.0:80->80/tcp, 5436/tcp programming_applicationserver_run_3
4cb5bdbb6c1d programming_onlineaccountverifier "bin/wait-for-it.sh …" 5 days ago Up About an hour 127.0.0.1:5435->5435/tcp programming_onlineaccountverifier_1
bf39ba383cec programming_onlineballotregulator "bin/docker_entrypoi…" 5 days ago Up About an hour 8545/tcp, 127.0.0.1:5434->5434/tcp, 30303/tcp programming_onlineballotregulator_1
but when I go to localhost:80 nothing is shown.
What should I do now ?

This is likely due to an error in the application itself and not docker.
To verify that, you can go into the container and make sure the application is port is working reachable:
docker exec -it programming_applicationserver_run_3 bash
Once you are inside the container, try accessing the port using one of the following command:
curl localhost:80
wget localhost:80
If non of these are successful, this would imply that the problem is related to the application and not to docker itself.

Related

Docker save: No such image

When i run docker save nifi > nifi_backup.tar i get
Error response from daemon: No such image: nifi
When i run docker ps -a i got
$docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8796cbf6cb1 apache/nifi:1.9.2 "../scripts/start.sh" 11 months ago Exited (0) 33 minutes ago nifi
f4ecf6ca0d16 apache/nifi "../scripts/start.sh" 12 months ago Exited (0) 12 months ago nervous_poincare
9a68c235bb3a apache/nifi "../scripts/start.sh" 12 months ago Exited (0) 12 months ago jolly_mendel
d608287fe560 superset_superset "/entrypoint.sh" 2 years ago Up 27 hours (healthy) 0.0.0.0:8088->8088/tcp, :::8088->8088/tcp superset_superset_1
fcea620b1983 postgres:10 "docker-entrypoint.s…" 2 years ago Up 27 hours 0.0.0.0:5433->5432/tcp, :::5433->5432/tcp superset_postgres_1
380782e0a024 redis:3.2 "docker-entrypoint.s…" 2 years ago Up 27 hours 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp superset_redis_1
Also, i cant start nifi image
if i run docker start nifi
it try to start about a minute, but then stop silently.
And there is no logs in result.
docker events says exit code = 0:
Maybe it has some relation for unavailable saving, so i inform about it too.
How to fix No such image in such a case?
Use the command docker images to see if there is an image named nifi. If not first build that image and than execute the command:
docker save nifi > nifi_backup.tar
It should not show the error No such image: nifi if the command docker images has an image named nifi.
As per documentation here, docker save command expects an image name, not a container. You're probably looking for docker export (export docs) command to achieve what you want.
The error about starting your container could be container-specific. As it exited already a year ago, maybe data is lost and the container cannot be started again. Using command docker events&, you can start the docker event listener in the background. This way you can obtain the hex value of this very start attempt and use it to search specific logs: docker logs <startId hex>. Maybe it can tell you more details about why the container did not properly start.

Ports not accessable

I installed docker and issues a 'docker swarm init' command.
I'm trying to launch a stack using the following command: docker stack deploy -c docker-compose.yml mystack
The docker-compose file can be found here, the first docker file here and the second here
The output of 'docker ps' is:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f582b3e8d33e tons/ip2country:latest "/bin/sh -c 'java -D…" 8 seconds ago Up 6 seconds 8080/tcp ip2flag_country-service.1.t5rvuqaw8tj7v20u0xo0dgy6x
bbf2c8304f1a tons/ip2flag:latest "/bin/sh -c 'java -D…" 10 seconds ago Up 8 seconds 8080/tcp ip2flag_app.1.z00gz8adj2yshpgimaw2o55d3
cbc7eaace4bf portainer/portainer "/portainer" 39 minutes ago Up 39 minutes 0.0.0.0:9000->9000/tcp portainer
The output of 'docker service ls' is:
ID NAME MODE REPLICAS IMAGE PORTS
ex51pyh1oyyo ip2flag_app replicated 1/1 tons/ip2flag:latest *:8080->8080/tcp
yhbt97lmjqan ip2flag_country-service replicated 1/1 tons/ip2country:latest
Since I'm running this on localhost I'd expect http://localhost:8080/ to return some sort of data. But it just times out. If I attach to the container and execute something like wget localhost:8080/some/path it works as expected. So the service is running and within the container listening to port 8080. However the port isn't exposed outside of dockers net. Further more I can add that launching with 'docker-compose up' works just fine too. But not with 'docker stack deploy'. Any clue about what I'm doing wrong?

Swarm cluster issue

I am trying to configure swarm cluster for my http service. But it looks like the http container was not getting started on my worker node even though i set the replica while creating service as 3.
docker service create --name www -p 8080:8080 -replicas 3 nginxdemos/hello
7697736869d5 nginxdemos/hello:latest "nginx -g 'daemon
of…" 9 minutes ago Up 9 minutes 80/tcp
www.3.ondv0trbihswroe32n7hbdwy6
e77cef0511b8 nginxdemos/hello:latest "nginx -g 'daemon
of…" 9 minutes ago Up 9 minutes 80/tcp
www.2.266mjs85leavrvwb0yik23hzh
09594341b984 nginxdemos/hello:latest "nginx -g 'daemon
of…" 9 minutes ago Up 9 minutes 80/tcp
www.1.m1syq4qchmzwm6qcpm1sikeax
[root#slc07gpc ~]# docker node ls
ID HOSTNAME STATUS
AVAILABILITY MANAGER STATUS
2c87tpbao6bpv57l2y2fk20un * manager1 Ready
Active Leader
mym5vl8xo29dnbxlcwt4fhe23 manager2 Ready
Active
yxj0gok5ii5o3bnewyn7gno61 manager2 Down
Active
w16a3p2owe5tb4n09wv8qm1jb worker1 Ready
Active
vk37whv1ov8micyd30s48u14q worker2 Ready
Active
Issue is the container was not started and i could not see any docker process when i execute ps -a on manager2,worker1,worker2. Can someone please help me
It looks like you have one manager, with 3 workers (and one down node yxj0gok5ii5o3bnewyn7gno61).
Assuming you have NO other services/containers running in the swarm, you may have network issues preventing proper task creation on other nodes. Try removing all nodes from the swarm docker swarm leave except the manager1 and one other node. Then remove and recreate service and see what happens. Try creating it without publishing a port, and see what happens.
Then maybe if it's still an issue you can update your answer with the results. Also showing your docker versions and general network setup would be good.

Connect to a Service running inside a docker container from outside

I have a service running in a docker container (local machine). I can see the service URL in the Ambari service config.
Now I want to connect to that service using my local development environment.
I found I can connect to that within the container but when I use that URL outside in my local I get connection refused.
Cause: org.apache.http.conn.HttpHostConnectException: Connect to
xx.xx.xx.com:12008 [xx.xx.xx.com/195.169.98.101] failed: Connection refused
How to connect to a service running inside a container from outside?
In my case code execute in my local machine.
If your container has mapped its port on the VM 12008 port, you would need to make sure you have port forwarded 12008 in your VirtualBox connection settings, as I mention in "How to connect mysql workbench to running mysql inside docker?"
VBoxManage controlvm "boot2docker-vm" --natpf1 "tcp-port12008 ,tcp,,12008,,12008"
VBoxManage controlvm "boot2docker-vm" --natpf1 "udp-port12008 ,udp,,12008,,12008"
The question needs more clarification, but I will answer with some assumptions.
I used an Ambari docker image (chose this randomly based on popularity).
Then I started 3 clusters as mentioned and my amb-settings and docker ps looked like this:
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ amb-settings
NODE_PREFIX=amb
CLUSTER_SIZE=3
AMBARI_SERVER_NAME=amb-server
AMBARI_SERVER_IMAGE=hortonworks/ambari-server:latest
AMBARI_AGENT_IMAGE=hortonworks/ambari-agent:latest
DOCKER_OPTS=
AMBARI_SERVER_IP=172.17.0.6
CONSUL=amb-consul
CONSUL_IMAGE=sequenceiq/consul:v0.5.0-v6
EXPOSE_DNS=false
DRY_RUN=false
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2483a74d919 hortonworks/ambari-agent:latest "/usr/sbin/init syste" 20 minutes ago Up 20 minutes amb2
4acaec766eaa hortonworks/ambari-agent:latest "/usr/sbin/init syste" 21 minutes ago Up 20 minutes amb1
47e9419de59f hortonworks/ambari-server:latest "/usr/sbin/init syste" 21 minutes ago Up 21 minutes 8080/tcp amb-server
548730bb1824 sequenceiq/consul:v0.5.0-v6 "/bin/start -server -" 22 minutes ago Up 22 minutes 53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 8301-8302/udp, 8500/tcp amb-consul
27c725af6531 sequenceiq/ambari "/usr/sbin/init" 23 minutes ago Up 23 minutes 8080/tcp awesome_tesla
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$
As of now, I can visit the Ambari server through: http://172.17.0.6:8080/
This works also from my host computer. However, if you want this to be connected from another computer from a similar network, then one option is to have a haproxy which does the redirection from:
localhost:8080 -> 172.17.0.6:8080
So, I created a small haproxy.cfg and Dockerfile to achieve this:
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ cat Dockerfile
FROM haproxy:1.6
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ cat haproxy.cfg
frontend localnodes
bind *:8080
mode http
default_backend ambari
backend ambari
mode http
server ambari-server 172.17.0.6:8080 check
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ docker build --rm -t ambariproxy .
Sending build context to Docker daemon 9.635 MB
Step 1 : FROM haproxy:1.6
---> af749d0291b2
Step 2 : COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
---> Using cache
---> 60cdd2c7bb05
Successfully built 60cdd2c7bb05
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ docker run -d -p 8080:8080 ambariproxy
63dd026349bbb6752dbd898e1ae70e48a8785e792b35040e0d0473acb00c2834
Now if I say localhost:8080 or MY_HOST_IP:8080 I can see the ambari-server and this should work also from computers in the same network.
Hope I managed to answer your question :)
Thanks,

binding of ports not working in docker

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2047cd997469 q1 "/bin/bash" 2 hours ago Up 2 hours **8001/tcp, 0.0.0.0:8001->9001/tcp** wicket1
ddb02ced5a0b q2 "/bin/bash" 28 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp tender_fermi
3966528ee466 q3 "/start.sh -D FOREGR 5 days ago Up 3 hours 0.0.0.0:3306->3306/tcp
As you can see I have three docker images running everything is working fine except for the image q1 I am not able to run through the port 9001 ..says connection refused. what may be the possible reason. application is working fine inside the container.
below is the port command:
sudo docker port 2047cd997469
9001/tcp -> 0.0.0.0:8001
Are you using vagrant or boot2docker? If need to connect 8001 port on your virtual machine. For the boot2docker, you can use boot2docker ip to get the ip. For the vagrant, you can use vagrant ssh to login and get the ip.

Resources