Port binding is not working in docker on windows - docker

I have installed docker on my Windows m/c.
I am trying to install Gerrit on that.
Pull image is done-Successfully
Run image is also done -->
docker run -d -p 8080:8080 -p 29418:29418 ******/gerrit
I try to connect it through browser with my container id:8080 but it throws error
This site can’t be reached
What is oing wrong.. Please help with suggestions.
BR,
Rash

You need to access your container by IP of virtual machine. You can obtain it with command: docker-machine ls. Then access container in browser by (replace ip) http://192.168.99.100:8080

This is a known limitation of windows containers at the moment as per the docker documentation (https://docs.docker.com/docker-for-windows/troubleshoot/#limitations-of-windows-containers-for-localhost-and-published-ports).
As of Windows 10 Creator's update this has kinda been fixed where you can use host IP with the bounded host port(http://<hostIp>:<hostBoundedPort>), but still not localhost or any of it's aliases.
Alternatively you can avoid port mapping hit the container IP directly. There is numerous ways to get your container IP. Personally I would use:
docker ps
This lists out all the the running docker containers allowing you to find the Container ID for the container that you want to hit followed by:
docker inspect <initial_part_or_full_id>
This will output low level information about the container, including it's Network settings where you will find the NAT-ed endpoint details containing the IP. Then simply http://<containerIP>:<containerPort>.

Related

Resource cannot be found error when accessing a page in Docker Container

I created a asp.net webform project in Visual Studio with Docker support (Windows). When I run the project using Visual Studio page comes up as below
Visual Studio creates a docker image which I saw using command
docker images
See image below (webapplication3)
Now I run another instance of Image (webapplication3) by command
Docker run webapplication3:dev
I can see container running
Docker ps
see image below
But now when I access this new running container using ip http://172.17.183.118/PageA.aspx
it's not coming up, see image below (I have taken IP 172.17.183.118 from docker inspect command, so it is correct.
Can someone tell me why am I not able to view the page? Why is it saying "Resource cannot be found" error?
When you run a Docker container default, the container will run with an internal IP address and an expose port map the local machine port, and the IP address will go out to the internet through the docker bridge which associated with the local machine network interface.
When you access the container inside the local machine, you just need to access the localhost with the port shows you. In your issue, you need to access the address http://localhost:62774/PageA.aspx. If you want to access the container from the Internet, you should access the IP address of your local machine with the port. For you, it means the address http://your-local-machine-public-ip:62774/PageA.aspx.
You can get more details from Docker Network. Also, I suggest you'd better run the container with the special port you plan just like docker run -d -p nodePort:containerPort --name containerName yourImage.

Access service running in a container from browser

I'm using docker to run a test environment locally On Ubuntu 16.04. I spin up a container using the command -
fwx#asus:~$ docker run -p 3000:3000 -v ~/work/website/:/website -it test-env bash
This puts me inside the container where I do some initial setup and start the service like so -
root#c98d858cb1a4:/website# start-service
The service is configured to the endpoint http://127.0.0.1:3000/ and docker inspect on the container provides me the IP address 172.17.0.2.
As I understand from the multiple blog / forum posts addressing similar issues, I should be able to access the pages served through a browser on my host at http://172.17.0.2:3000. However, trying to access it thusly throws a connection error that the website cannot be reached.
I have tried various solutions proposed on similar questions including adding 172.17.0.0 to the route, but to no avail. Can someone please tell me what I'm doing wrong?
Whenever you create a docker container it will be assigned a private ip, To access the container you need to expose it which in your case is -p 3000:3000 try accessing the service from your host ip address and also try by disabling firewall.

How to access a docker container through SSH?

I am currently thinking of building a docker image for my ipython parallel nodes. Because its a pain to configure each manually with commands. Will i be able to access this image (located on a different PC on my LAN) simply by typing ssh user#ip on my laptop (Master Node)? How do i get the ip of the docker image running on my Node?
Will i be able to access this image (located on a different PC on my LAN) simply by typing ssh user#ip on my laptop (Master Node)?
You cannot ssh into a container unless you arrange to run sshd inside that container. Normally that's not necessary; as this answer explains you can simply use docker exec to access a running container.
How do i get the ip of the docker image running on my Node?
First, a note about nomenclature: an image is just a collection of files. A container is what you get when you start services from an image. In other words, it doesn't make sense to ask questions about accessing or getting the ip address of an image.
You can get the ip address of a container using the docker container inspect command, which will show you a variety of information about your container. However, this may not be what you want: the ip address of the container will be a private ip address on a docker internal network that is only accessible from the host where you're running docker.
You provide remote access to services by using port forwarding (the -p flag to docker run). For example, if you're running a webserver on port 8080 inside a container, you could make that available on port 80 on your host doing something like:
docker run -p 80:8080 mywebserver
This document describes in more detail some of the options related to port forwarding.

Unable to connect outside database from Docker container App

we have two machine…one is windows machine and another in Linux machine. My application is running under Docker Container at Linux machine. our data base is running at Windows machine.our application need to get data from windows machine DB.
As we have given proper data source detail like IP, username ,password in our application. it works when we do not use docker container but when we use docker container it do not work.
Can anyone help me out to get this solution that how we can connect outside DB from Docker enabled application as we are totally new guys in term of Docker.
Any help would be much appreciated.
Container's default network is "bridge",you should choose macvlan or host network.
method 1
docker run -d --net host image
this container will share your host IP address and will be able to access your database.
method 2
Use docker network create command to create a macvlan network,refrence here
then create your container by
docker run -d --net YOURNETWORK image
The container will have an IP address which is the same gateway with its host.
There are a lot of issues that could be affecting your container's ability to communicate with your database. In the future you should compose your question with as much detail as possible. To correctly answer this you will, at a minimum, need to include the following details:
Linux distribution name & version
Docker version
Output of docker inspect from the container
Linux firewall configuration
Network configuration
Is your Windows machine running on the same local network / subnet as your Linux machine? If so, please provide information about the subnet, as the default bridge set up by Docker may restrict access to local resources, whereas those over a wide area network would still be accessible.
You can try passing the --network=host option to your docker run command like so: docker run --network=host <image name>. Doing so eliminates the need to specify port mappings in your run command, as they are ignored when using the host's network.
Please edit your question and include the above requested details to get a complete answer.

Access docker remote API from container

I'm trying to access Docker remote API from within a container because I need to start other containers.
The host address is 172.19.0.1, so I'm using http://172.19.0.1:2375/images/json to get the list of images (from host, http://localhost:2375/images/json works as expected.
The connection is refused, I guess because Docker (for Windows) listens on 127.0.0.1 and not on 0.0.0.0.
I've tried to change configuration (both from UI and daemon.json) adding the entry:
"hosts": ["tcp://0.0.0.0:2375"]
but the daemon fails to start. How can I access the api?
You can set DOCKER_OPTS in windows as below and try. In Windows, Docker runs inside a VM. So, you have to ssh into the VM and make the changes.
DOCKER_OPTS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock'
Check if it works for you.
Update :- To ssh into the VM (assuming default is the VM name you have created using Docker toolbox), enter the following command in the Docker Quickstart Terminal,
docker-machine ssh default
You can find more details here.
You could link the host's /var/run/docker.sock within the container where you need it. This way, you don't expose the Docker Remote API via an open port.
Be aware that it does provide root-like access to docker.
-v /var/run/docker.sock:/var/run/docker.sock
You should use "tcp://host.docker.internal:2375" to connect to host machine from container. Please make sure that you can ping the "host.docker.internal" address
https://github.com/docker/for-win/issues/1976

Resources