tl;dr summary of the problem:
Application launches successfully within container, binds to 127.0.0.1:8080 within the container, and successfully services web requests, but only within the container
docker ps -a confirms that port 8080 is being exposed
I cannot communicate with the application from the host using the container's actual IP address when I request http://[Container IP address]:8080
The host is running Windows 10
The Windows Firewall is completely disabled for troubleshooting
To troubleshoot I have created the simplest possible application to run in a dockers container, an F# / Suave application like so:
open Suave
[<EntryPoint>]
let main args =
startWebServer defaultConfig (Successful.OK "Hello World!")
0
Which works fine, returning a simple "Hello World!" when I run it locally.
To containerize the app I have followed the instructions at "Dockerize a .NET Core application" which instructs me to run the container like
$ docker run -d -p 8080:80 --name myapp aspnetapp
I cannot connect to the "website" at http://localhost:80 nor http://localhost:8080, which apparently is a common problems for Docker users running Windows. However the solution that seems to have fixed this problem for every other Windows user on the internet, running
docker inspect myapp
and then hitting the resulting IPAddress, does not work either. I get:
Hitting both http://172.17.0.2:80 and http://172.17.0.2:8080 in Chrome gives me "Site can't be reached."
Also worth noting, when I run
docker logs myapp
The only line is
[17:43:21 INF] Smooth! Suave listener started in 73.476ms with binding 127.0.0.1:8080
As a guess, I have also tried
ipconfig
and then hitting the IP address of the Docker NAT adapter, but this also results in an unreachable site.
UPDATE:
Another observation which might or might not be relevant: Many online tutorials suggest that under Windows you need to directly connect to the IP Address of the container, and to get that IP address by running
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" myapp
which for me, always yields:
When I run a vanilla
docker inspect myapp
the resulting JSON is not structured exactly like the recommended query. I get a bridge node, but no nat node:
Your app says it’s bound to localhost:8080, but you’re publishing port 80. Stop the container, and rerun with:
docker run -d -p 8080:8080 --name myapp aspnetapp
Try adding the following lines in docker file
ENV ASPNETCORE_URLS http://+:80
EXPOSE 80
Reference: https://www.sep.com/sep-blog/2017/02/20/hosting-asp-net-core-docker/
My containerized app needed to listen/bind to 0.0.0.0 rather than 127.0.0.1.
Related
Using Ubuntu 20.04.
I have a Docker web container that I can access locally at localhost:8000 I want to instead access this by typing hello.localhost in my browser.
I can accomplish this by adding the containers ip address to my /etc/hosts file but the problem is that this ip address can change. How can I resolve this?
Generally, you would solve this using port publishing. Let's say you have multiple containers; we'll call them hello and goodbye. You'd like to access them as http://hello.localhost and http://goodbye.localhost, without having to append a port number.
You can bind each container to a specific ip on your host, like this:
docker run --name hello -p 127.0.0.2:80:8000 myimage
docker run --name goodbye -p 127.0.0.3:80:8000 myimage
Here, we've bound port 8000 on container hello to 127.0.0.2:80, and port 8000 on container goodbye to 127.0.0.3:80. All that we need to do now is tell our host about names for these addresses, which we can do by adding something like this to /etc/hosts:
127.0.0.2 hello.localhost
127.0.0.3 goodbye.localhost
Now you can browse to http://hello.localhost or http://goodbye.localhost (as long as your browser is running on the same machine as your docker containers).
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.
Im not able to access my docker image. my setup is windows 7 and have the docker linux vm which is running on oracle vm. i have build my app and i can see my app using below
i dont know how i can access myapp container. since its wokring on localhost i believe i can access on localhost:port number. but i have no clue where i can see and how i can start. if you have face this same prob can you help ?
Update log hung :
in the below screen the server startup hung almost 10 mins and i terminate the process, any idea about this error ?
What you have shown in your screenshot is the image list. So you would first have to docker run your image, binding the application's port exposed by the docker image (with EXPOSE, I'm assuming 8081 for the sake of my example) to the host:
docker run --publish 8081:8081 3b98
If you forgot to expose the port in your image you can do that on the commandline adding the argument --expose 8081 to run.
Then, since your working with the Windows 7 setup, you cannot access your running application in its container on localhost but on the docker-machine's (the docker linux VM) IP. You can find out the assigned IP with
docker-machine ip
So if your application publishes itself on 8081 and docker-machine ip returns 192.168.99.100 you would find your app on 192.168.99.100:8081
I'm using ASP Core image to create a new container.
I've developed simple service which uses port 5000.
Now I created Dockerfile and built container which exposes
EXPOSE 5000
Running this container with a command
docker run -it -p 8080:5000 <name>
or even
docker run -it -p 127.0.0.1:8080:5000 <name>
doesn't lead to navigation to the 127.0.0.1:8080. So my browser says this site can't be reached.
p.s. I've checked the service without docker - it works correctly
UPD1
docker ps
shows my launched container with ports mapping information:
127.0.0.1:8080->5000/tcp
UPD2
this is netstat output from the host
tcp 0 0 localhost:5000 *:* LISTEN
lynx 127.0.0.1:5000 shows 200 OK
netstat -a on a client box doesn't show 8081 port or 5000
UPD3
I've just created a new container for NodeJs using public image.
Created a simple server with exposed port. After running it works as expected.
Actually it looks like the problem with exact Asp image
Which OS are you using? If you're running on OSX or Windows you will need to use the IP of your boot2docker virtual machine, not 127.0.0.1.
docker-machine ip will show you the IP of your current host.
I have a ubuntu machine which is a VM where I have installed docker in it. I am using this machine from my local windows machine and doing ssh , opening the terminal to the ubuntu machine.
Now , I am going to take a docker image which contains all the necessary softwares for eg: apache installed in it. Later I am going to deploy a sample appication(which is a web applicationP on to it and save it .
Now , I am in a confused mode as in how to check the deployed application if its running properly. i.e., what would be the address of the container which containds the deployed application.
for eg:- If I type http://127.x.x.x which is the address of the ubuntu machine , I am just getting time out .
Can anyone tell me how to verify the deployed application . Also, the printing the output of the program on the console works seemlessly fine , as the output gets printed , only thing I have some doubts is regarding the web application.
There are some possibilities to check whether your app is running.
Remote API
As JimiDini said, one possibility is the Docker remote API. You can use it to see all running containers (which would be your use case, right?), inspect a certain container or start and stop containers. The API is a REST-API with several binding for programming languages (at https://docs.docker.io/reference/api/remote_api_client_libraries/). Some of them are very outdated. To use the Docker remote API from another machine, I needed to open it explicitly:
docker -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock -d &
Note that the API is open to the world now! In a real scenario you would need to secure it in some way (e.g. see the example at http://java.dzone.com/articles/securing-docker%E2%80%99s-remote-api).
Docker PS
To see all running containers run docker ps on your host. This will list all running containers. If you do not see your app, it is not running. It also shows you the ports your app is exposing. You can also do this via the remote API.
Logs
You can also check the logs. You can run docker attach <container id> to attach to a certain container an see its stdout. You can run also run docker logs <container id> to receive the Docker logs. What I prefer is to write the logs to a certain directory, e.g. all logs to /var/log and mount this folder to my host machine. Then all your logs will end up in /home/ubuntu/docker-logs on your host.
docker run -p 80:8080 -v /home/ubuntu/docker-logs:/var/log:rw my/application
One word to ports and IP
Every container will get its own IP address. You can check this IP address via the remote API or via Docker on the host machine directly. You can also specify a certain host name for the container (by passing the --hostname="test42" to the run command). However, you mostly did not need that.
To access the application in the container, you need to open the port in the container and bind to a port on the host.
In your Dockerfile you need to EXPOSE the port your app runs on:
FROM ubuntu
...
EXPOSE 8080
CMD run-my-app.sh
When you start your container, you need to bind this port to a port of the host:
docker run -p 80:8080 my/application
Now you can access your app on http://localhost:80 or http://127.0.0.1:80.
If you app does not response, check if the container is running by typing docker ps or the remote API. If it is not running, check the logs for the reason.
(Note: If you run your Ubuntu VM in something like VirtualBox and you try to access it from your Windows machine, make sure you opened the ports in VirtualBox too!).
Docker container has a separate IP address. By default it is private (accessible only from the host-machine).
Docker provides all metadata (including IP address) via its API:
https://docs.docker.io/reference/api/docker_remote_api_v1.10/#inspect-a-container
https://docs.docker.io/reference/api/docker_remote_api_v1.10/#monitor-docker-s-events
You can also take a look at a little tool called docker-gen for inspiration. It monitors docker-events and created configuration-files on host machine using templates.
To obtain the ip address of a docker container, if you know its id (a long hex string) or if you named it:
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-id-or-name>
Docker is running its own network and to get information about it you can run the following commands:
docker network ls
docker network inspect <network name>
docker inspect <container id>
In the output, you should be able to find the IP.
But there is also a couple of things you need to be aware of, regarding Dockerfile and docker run command:
when you EXPOSE a port in Dockerfile, the service in the container is not accessible from outside Docker, but from inside other Docker containers
and when you EXPOSE and use docker run -p ... flag, the service in the container is accessible from anywhere, even outside Docker
So for example, if your apache is running on port 8080 you should expose it in Dockerfile and then you can run it as:
docker run -d -p 8080:8080 <image name> and you should be able to access it from your host on HTTP://localhost:8080.
It is an old question/answer but it might help somebody else ;)
working as of 2020
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id