unable to access mailpile server inside docker container - docker

I have created a docker container and have installed the mailpile open source email client.
Running the mailpile binary inside the container prints the following message to STDOUT.
The Web interface address is: http://localhost:33411/
So I opened firefox on the host machine and tried 127.0.0.1:33411. It did not work.
Then I looked up the IP address assigned to the container by docker.
I looked it up by running the following command on the host,
docker inspect mp | grep IP
It said the container had an IP address of 172.17.0.3
So now, I tried 172.17.0.3:33411 on firefox running on my host. It still didn't work.
So then I stopped the container with docker stop mp. And then I committed it to an image under the name mp_image. I ran the following command on the host to do the commit.
docker commit mp mp_image
After the commit, I created a new running container, but this time forwarded port 33411 of the container to port 33411 of the host. I ran the following command on host,
docker run -i -t -p 33411:33411 --name "mailpile" mp_image /bin/bash
And now, once I got inside the container, ran the mailpile binary again and tried accessing it from the host. This time I used all these variations on the host browser,
127.0.0.1:33411
172.17.0.3:33411
Again not working. Now I started doubting if the server was running in the container in the first place. So I went inside the container and did wget 127.0.0.1:33411. And I got a nice index.html file. So the server is running..
I don't know what to do at this point. Can someone please advice?

Mailpile is built to listen on port 33411 from the local host only. Install a proxy or tunnel a connection as described here: https://github.com/mailpile/Mailpile/wiki/Accessing-The-GUI-Over-Internet

Related

Unable to access Docker container running in WSL2

I am new to containers and Docker. On my Windows 10 laptop (Version 20H2 Build 19042.630) I have WSL2 installed as well as Docker Desktop (Docker Engine v19.03.13). When I run the command below (from the docker documentation):
docker run -d -p 80:80 docker/getting-started
The container starts fine but I am unable to access the container from either within WSL or from the Windows 10 host.
Inside WSL, if I enter curl http://127.0.0.1 it returns the error curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused
From the Windows 10 host, if I open a browser and attempt to go to http://127.0.0.1 it just throws a 404 error.
From the Windows 10 host, when I open the Docker Desktop app, it shows the container running and listening on port 80 but if I then stop the container...and then attempt to restart it, it throws an error that says:
(HTTP code 500) server error - Ports are not available: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions
I have tried completely uninstalling WSL and Docker Desktop and resetting the TCP/IP stack but the end result is the same. I performed the exact same install steps on my desktop PC and everything works fine with no issues. I did notice on the desktop PC that the first time I tried accessing the "getting-started" container that it produced a pop-up to allow the traffic through my firewall. I never got this on the laptop. I compared the firewall rules on the PC to the Laptop and the PC had 4 rules for the com.docker.backed application that the Laptop did not have. I manually duplicated those rules on the laptop but it did not change the behavior any.
EDIT:
After doing more research on this issue...discovered why this is happening. The ports the container is attempting to listen on are excluded for my Laptop. Found the Github issue linked below that had the command netsh interface ipv4 show excludedportrange protocol=tcp that showed the list of excluded ports on my laptop. Seems Hyper-V is what is excluding the ports but the only reason Hyper-V is on the system is for WSL. The Github issue is still open as of today.
Unable to bind ports: Docker-for-Windows & Hyper-V excluding but not using important port ranges #3171
If your docker container uses localhost inside it won't work. I had the same issue with docker inside wsl and the solution was to change IP of underlying service (the one that is run inside docker) to 0.0.0.0.
You can check this by doing docker ps. In my case I ran the docker like this:
docker run --rm -p 8080:8080 hello-python
which was then bind to (part of docker ps output):
0.0.0.0:8080->8080/tcp
So basically the python code had to use 0.0.0.0:8080 instead of localhost:8080

Unable to run docker project in localhost

I have installed a repo from docker and ran it using the following command,
docker run -d --name searx -p $PORT:8888 wonderfall/searx
The container was also sucessfully created but while accessing it in my browser i get the following error,
dail tcp[::1]:8888: connectex: No connection could be made because the target machine actively refused it.
Does anyone know why this error occurs? I use a windows10 system.
Just installed docker toolbox
That means you cannot use localhost directly without declaring in Virtual Box a port-forwarding rule.
First, test your service using the IP of your VM (see docker-machine ip default output)
http://<ip>:8888
Then, declare a port-forward rule:
either directly in your VirtualBox graphical interface: see "How do I configure docker compose to expose ports correctly?"
or with VBoxManage controlvm commands: see "Not able to access tomcat application on Docker VM with host(windows) IP while using docker toolbox"

Connecting webpack-dev-server inside a Docker container from the host

I'm running a webpack-dev-server application inside a Docker container (node:4.2.1). If I try to connect to the server port from within the container - it works fine. However, trying to connect it from the host computer results in reset connection (the port is published, of course). How can I fix it?
This issue is not a docker problem.
Add --host=0.0.0.0 to your webpack command.
You need to connect to your page like this:
http://host:port/webpack-dev-server/index.html
Look to the iframe mode
You need to make sure:
you docker container has mapped the EXPOSE'd port to a host port
docker run -p x:y
your VM (if you are using docker machine with a VM) has forwarded that mapped port to the actual host (the host of the VM).
See "How to access tomcat running in docker container from browser?"

Docker container not exposed on network

I am new to docker. I am running it on windows. I am trying to get a container named "ghost" (available from the Docker Hub) to work on a Windows 8.1 machine. While the container starts correctly and supposedly exposes url at http://localhost:2368, when I enter this address nothing happens. The same has happened when trying other containers from the Hub which expose urls.
I tried accessing the container's exposed URL from the IP Address I get from the "docker ip" but it failed too. I also tried running the container with the "--net="bridge"" option, to no avail. I think I'm missing something pretty basic, but I can't for the life of me figure out what. Can someone point me in the right direction?
When you install Docker on Windows that means you most likely installed boot2docker.
boot2docker starts a minimal Linux VM (based on VirtualBox) because Docker requires a Linux kernel to run. The Docker daemon is started on that VM and not on your localhost.
You can determine the VMs IP address by typing boot2docker ip on your command line. The standard boot2docker IP address is 192.168.59.103 if you did not configure something else or have multiple instances of that VM running.
So when you execute docker run --name ghost -p 2368:2368 -d ghost the port 2368 is opened at 192.168.59.103:2368. That is where you need to connect to.
For more information please read the official boot2docker documentation.
You haven't provided the complete 'docker run ...' command you executed, so I'm assuming you ran the one specified in the image's page on Docker Hub (reproduced below).
docker run --name some-ghost -p 8080:2368 -d ghost
The command is mapping Ghost's exposed port inside the container (2368) to port 8080 in your boot2docker VM. The first thing you need to do is run boot2docker ip to find out the IP address of your boot2docker VM. About the port number, you have two options:
Access Ghost via port 8080 (http://BOOT2DOCKER-IP:8080)
Change the port mapping to expose 2368 (-p 2368:2368)

Obtaining the ip address of a docker container

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

Resources