cannot reach port 80 from Windows to Docker image - docker

Running on Windows 10 with Docker Installed
// DockerFile
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y apache2
ADD index.html /var/www/html/
CMD /usr/sbin/apache2ctl -D FOREGROUND
EXPOSE 80
// building image, running container and checking IP
$ docker network inspect bridge
and getting
"IPv4Address": "172.17.0.2/16"
when trying to access via Chrome browser to http://172.17.0.2, I get "This site can’t be reached"

Expose Port: Please check have you exposed port number 80. (not only in docker file)? but In your docker run command, you need to specify "-p 80:80". Can you please share your command, how you are running your docker container?
IPAddress: 172.17.0.2 This IPAddress is docker internal docker ip address, you need to use localhost or your_machine_ip_address to access that docker container.
Please let me know, If you have any difficulty with this, share your docker run command.

Related

TCP connection between docker containers

I have a server listening on port 6000 inside a docker container and I've exposed port 6000 in the dockerfile:
FROM rust:latest
WORKDIR /usr/src/server
COPY . .
RUN cargo install --path .
EXPOSE 6000
RUN cargo run
then run it using:
docker build -t server
docker run --rm -it -p 6000:6000 server
I then have a client in another container trying to make a tcp connection at port 6000, but it's failing to connect. When they're both run not in containers they can connect no issues, but trying to use docker is causing issues. Do I have to do something with my clients container in order to connect to port 6000 outside of its own container? I think it's probably a very simple issue I'm just new to docker so any help would be greatly appreciated.
The RUN command is a build time execution, I think you are looking for CMD instead. Also the EXPOSE is not necessary, it only serves documentational purposes. Lastly, you need to check whether the container is even running before trying to access it from the client. Do a docker ps -a after starting the server and look at the container status. If it isn't running you can check the logs with docker logs <container name / hash>. Let me know if you have questions.

Docker Desktop created container do not have access to macos [duplicate]

Running docker for Mac 17.06.0 I have created a docker file that creates an image of Apache server. Notice it exposes port 80.
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y apache2
ADD index.html /var/www/html/
CMD /usr/sbin/apache2ctl -D FOREGROUND
EXPOSE 80
In the same folder of the Dockerfile I have created a simple index.httml file.
Then I built and ran it using
docker build -t webserver .
docker run -d webserver
I took the IP address of the running container using
docker inspect [container_name] | grep -i IPAddress
and when I curl
curl 172.17.0.2
I get no answer.
I do get an answer when running -p 80:80 and using localhost in the curl command.
curl localhost
But I want to understand why can't I curl the container IP.
Questions:
How can I get an answer for my curl?
I understand I can't ping my container when using docker for Mac (link).
Can I telnet it just to verify that the port is exposed?
Can I SSH it?
On Docker for Mac the Docker engine is running inside a small VM using Hyper-V. As consequence, the ip 172.17.0.2 is valid only inside that VM and not on your host system. See https://docs.docker.com/docker-for-mac/docker-toolbox/#the-docker-for-mac-environment for more details and comparison to other VM concepts like Docker Machine.
When you run your Docker container, you need to bind a local port to the container like so:
docker run -d -p 80:80 webserver
where the first 80 is the port on the localhost and the second is the port on the container that is exposed. Just having the port exposed in the dockerfile is not enough to access it from the localhost.

I can't access my Docker container on GCP Compute Engine

I have my Docker container running on GCP Compute Engine. The CE server is running on CentOS 7. My Docker container has the application being served by Nginx with port 80 exposed. For some reason, I can't access it from the external IP address on my browser.
I ran the container with this command:
sudo docker run --name myapp -p 80:80 -d myapp:1.0.0
When I do sudo curl <internal_ip>:80 or sudo curl <localhost>:80 it will show that the application is running and returns back the content, but if I try to access in my browser with <external_ip>:80, it doesn't load anything. What can I do to make this accessible through the external IP address?
It seems I had to configure the firewall to open up port 80.

Why can't I connect to localhost port 5000, why does it get refused?

I'm trying to build a docker image, but whenever I run the app my connection to localhost gets refused.
The problem does not only occur with port 5000, but also with every else. I'm running the Docker Toolbox on Windows.
My command is :
docker run 5000:80 azure-text
When I curl or just do a docker run, the error message says "Failed to connect to localhost port 5000: Connection refused"
My Dockerfile:
FROM python:2.7-slim
WORKDIR /app_
COPY . /app_
RUN pip install --trusted-host pypi.python.og -r requirements.txt
EXPOSE 80
ENV NAME World
CMD ["python", "app.py"]
Would be happy about advice!
If you're using Docker Toolbox you need an additional port forward to connect to localhost. You can the reach docker in another IP. Run this command to see which host is running your docker host:
docker-machine ls
For example, if your docker machine is running on 192.168.99.100, you can access your running service on http://192.168.99.100:5000

Cannot get port-mapping to work with Shiny on Docker with Digital Ocean droplet

I am trying to get a Shiny application working as a web server on a Digital Ocean droplet, using a docker image by rocker. All seems to be working fine, but somehow I cannot access the page through a browser.
Docker seems properly exposed to port 80 on the droplet:
R seems to correctly listen to port 80 inside the docker container:
Docker process listing looks correct:
As does the machine listing:
The command by which I started the container is:
docker run -d -p 80:80 --name ggplotgui jelkink/fpr
My Dockerfile looks as follows:
FROM rocker/shiny:latest
COPY . /srv/shiny-server/docker
RUN sudo apt-get install -y libssl-dev xdg-utils
RUN sudo R -e "install.packages(c('shiny', 'dplyr', 'plotly',
'rmarkdown', 'ggplot2', 'readxl', 'haven', 'rio', 'stringr', 'readr',
'devtools'))"
RUN chmod +x /srv/shiny-server/docker/continuous_shiny_run.sh
EXPOSE 80
CMD /srv/shiny-server/docker/continuous_shiny_run.sh
Although, to be honest, I also didn't manage to get it work under my local Docker installation, so perhaps it's unrelated to DigitalOcean.
Running the nginx hello world example on DigitalOcean - same droplet, different docker image - works just fine, including the use of port 80.
My Shiny code explicitly requests port 80:
shinyApp(ui, server, options = list(port = 80))
Docker is binding to port 80 on the ipv6 interface only and not the ipv4 interface, you can tell from the missing tcp *:http entry in your netstat output.
Because of that, your connection to the ipv4 IP does not succeed and curl and others return "Connection refused".
See e.g. this Stack Overflow issue with details how to make Docker use the ipv4 interface.

Resources