How do I "point" container to port 8080? - docker

I'm learning the ins and outs of Docker from book and I'm asked to:
"Open a web browser and navigate to the DNS name or IP address of the Docker host
that you're running the container from, and point it to port 8080."
I don't understand what I'm asked to do. I've got a container with image running on my machine
but I don't understand how do I get IP address of Docker host ? I can run docker-machine ip [instance] but I've got no instance running in the cloud and the container is up locally.
Can anyone explain to me what I'm asked to do ?
0c7d84a472ed test:latest "node ./app.js" 15 minutes ago Up 15 minutes 8080/tcp, 0.0.0.0:8080->80/tcp web1

You need to map the port when running the container by adding flags of -p <hostport>:<serviceport_inside_container>

Since the container is running locally in your machine (desktop/laptop), open the web browser to the url http://localhost:8080 or https://localhost:8080.
Container port 80 is mapped to 8080 of the node (which is the docker host - the host machine that is running the container. This docker host in your example is localhost itself.
Hence, http://localhost:8080 should work
Phrase "Point to" actually means to open the web page hosted in this context.

I don't understand how do I get the IP address of Docker host? You have use server IP and port for the specific app or service. find below example.
ex: docker run -d --name app1 -p 8080:8080 tomcat ( ServerIpaddress:8080)
docker run -d --name app2 -p 8081:8080 tomcat ( ServerIPaddress:8081)
Note: make sure you have open the port on the security group.

Related

How to Connect Docker Container to localhost [duplicate]

This question already has answers here:
Exposing a port on a live Docker container
(16 answers)
Closed yesterday.
I've created a docker container with ubuntu image. In that I've created a react app and when I try to run the app I could not see the app is running on localhost but in the terminal of container it says its running on the port. How can we connect a docker container with our localhost.
If You have a docker file just pass the port to docker run with -p
3001:3000
If you have a docker compose set the port with:
ports:
- 3001:3000
and run docker-compose up -d
Finally navigate to localhost:{Port}
From official documentation : docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
This binds port 8080 of the container to TCP port 80 on 127.0.0.1 of the host machine. You can also specify udp and sctp ports. The Docker User Guide explains in detail how to manipulate ports in Docker.
Then docker ps and verify its running and ports are exposed.
Also check about your firewall, it may block ports.

Docker desktop for windows: Can't access my container via the browser

I'm trying to run httpd container
The ip address is 172.17.0.2 (I'm sure of it cause I've ran docker container inspect <container_name>) and I the port is 4400 and when I run the container can't access it via the browser on this address http://172.17.0.2:4400 !
I've tried to disable the firewall but still the same problem.
This is how I started it:
docker container run -d -p 4400:8080 httpd
This is what docker container ls give me
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e9f92cfceb76 httpd "httpd-foreground" 24 minutes ago Up 13 minutes 80/tcp, 0.0.0.0:4400->8080/tcp interesting_wright
What am I missing ?
The problem was with wamp
when I disabled it I was able to access the container via http://localhost:4400
docker run -dit --name my-apache-app -p 4400:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
And then user your localhost + that port, and/or the LAN IP + that port.
Reference: https://hub.docker.com/_/httpd
I also was facing the same problem in windows with XAMPP installed
I resolved it by modifying the hosts file
/c/Windows/System32/drivers/etc
Just comment on the xampp IP and in this file you can also see the docker internal IP use it to access the application inside the container

docker container is not accessible from other machines on host's network

I was doing some devops and writing a script to turn my current host/nginx server/nginx setup into a host/docker/nginx server/docker/nginx set up so I can keep directories and etc the same between them.
The problem is that any ports I expose on a docker container are only accessible on the host and not from any other machines on the host network.
When typing 192.168.0.2 from a machine such as 192.168.0.3 it just says took too long to respond, but typing 192.168.0.2 from 192.168.0.2 will bring up the welcome to nginx page?! The interesting part is I did a wireshark analysis on en0 on port 80 and there are actually some packets coming through
See pastebins of packet inspections:
LAN to docker: https://pastebin.com/4qR2d1GV
Host to docker: https://pastebin.com/Wbng9nDB
I've tried using docker run -p 80:80 nginx/nginx and docker run -p 192.168.0.2:80:80 nginx/nginx and docker run -p 127.0.0.1:80:80 nginx/nginx but this doesn't seem to fix anything.
Should see welcome to nginx when connecting from 192.168.0.3 to 192.168.0.2.
this is in my dev environment which is an osx 10.13.5 system.
when I push this to my ubuntu 16.04 server it works just fine with the containerized nginx accessible from the www and when I run ngnix on my host without docker I can connect from external machines on the network too
Your description is a bit confusing the 127.0.0.1 within the port line will bind it to localhost only - you won't be able to access the docker from another machine. Remove the IP address and you should be able to access the docker from outside localhost.

Run docker but get This site can’t be reached 192.168.99.100 refused to connect

I unable to access docker exposed port on windows machine. In details I do the following:
$ docker build -t abc01 .
$ docker run -d -p 80:4000 abc01
Then I try to reach docker container in browser:
http://192.168.99.100:4000
and get annoying result:
This site can’t be reached 192.168.99.100 refused to connect.
What is the issue?
You are exposing the right ports, however, you need to access the website at: 80 instead of 4000, given that 4000 is the port on which your application is listening.
The way exposing ports in Docker works is as follows:
docker run -p 80:4000 myImage
where
80[is the outside port]
The one is exposed on your host and you will use it in your browser
4000 [is the inside port]
The port that is used inside the container by the application

Docker DB connection refused

I have fedora 20 running in my container, I can start my container and point it to a specific port through docker and the Websphere Liberty page loads just fine. (which is what i have in it). However, in the same container i have my db connection string- i can ping it fine, but in the logs when the wlp service start it throws db connection exception- cant connect. Maybe i ned to expose a port that db is running on? not sure, or maybe I am doing something completely wrong? I just got Dockers and dont have much experience with it...any help would be great! thanks!
When you run a container, Docker has two methods of assigning ports on the Docker host:
Docker can randomly assign a high port from the range 49000 to 49900
on the Docker host that maps to port 80 on the container.
You can specify a specific port on the Docker host that maps to port
80 on the container.
This will open a random port on the Docker host that will connect to port 80 on
the Docker container.
The -p flag manages which network ports Docker exposes at runtime.
$ sudo docker ps -l command will let you view the Docker port mapping.

Resources