How to expose Nginx port - docker

I’m learning to set up Nginx using docker.
I created a docker 17.12.0 ce on 16.04 at DigitalOcean.
I followed the instruction to setup .
I run the docker and bind the port using -p 80:80. I tried to access but connection is refused.
Failed to connect to 139.59.245.108 port 80: Connection refused
Container info:
docker ps
Btw, I noticed the messages:
"ufw" has been enabled. All ports except 22 (SSH), 80 (http) and 443 (https)
have been blocked by default

No sure why now it is working... But I guess maybe I need to set sudo ufw allow 80, I shut down the docker and start a new docker. Then docker port <my-container>, it finally shows up 80/tcp -> 0.0.0.0:80

Related

Error "Failed to open TCP connection to localhost:35729" on Rails app on a Docker container

I am having getting an error message "Failed to open TCP connection to localhost:35729 (Cannot assign requested address - connect(2) for "localhost" port 35729)" when I start my Rails local server on my Docker container by foreman start. I tried to access the server on "localhost:5000". The rails server is configured to be hosted on port 5000 on the localhost.
As for the docker container, I started it from an image by running a docker command
docker run -it --name <my-container-name> -p 5000:5000 -p 35729:35729 -v <host_project-directory>:/home <image-name> /bin/bash
in order to bind the port 35729 on the docker container with the host's port 35729. The port 5000 is where this rails application is configured to run the local server, so I also bound it with the host.
I also confirmed the ports are bound to the local machine by starting the container and run
docker port <my-container-name>
which gave me
35729/tcp -> 0.0.0.0:35729
5000/tcp -> 0.0.0.0:5000
So I'm guessing it is not the problem with port binding.
Why am I getting this error message even though the port is open on the Docker container and is bound to the host machine? I appreciate any advice to be able to connect to the local server running on the container from the host machine.
Notes:
Rails Version: 4.2.11.1
Docker container: Debian GNU/Linux 9

Connect a websocket client in a docker container to a websocket server in host

I have a websocket server running in my host, listening to port 8080.
In a docker container, I deployed a websocket client listening to the said server using this snippet:
connect_url="ws://0.0.0.0:80/"
and, exposing/mapping port 80 of the container to port 8080 of the host.
Dockerfile:
EXPOSE 80
When I ran the container:
docker run -p 8080:80 <name>
But I'm getting this error:
docker: Error response from daemon: driver failed programming external connectivity on endpoint : Error starting userland proxy: Bind for 0.0.0.0:8080 failed: port is already allocated.
Now I think this error is because the server in the host is already using port 8080, that's why it can't be mapped.
With these details given, I just wanted to know how can my websocket client inside the docker container connect to the websocket server in the host.
I think problem is port 80 inside your container already in use, not 8080 on your host machine. Try to use another port for connect socket inside your docker container instead 80 (for example 777 port). Then run docker run -p 8080:777 <name>
By the way, check your host machine port already in user or not:
sudo lsof -i tcp:8080
If not thing show up, that mean port 8080 not yet used. Incase already in use. Kill that process on port 8080:
sudo kill -9 your_PID_ID
Then try again

Conflict between docker-proxy and nginx

I want to run a dockerized nginx on port 443 (https), but this seems to be taken by the docker-proxy.
Why is this, and can I do someting about it?
EDIT
The same conflict happens with the http port (80)
docker-proxy is run when you publish a port on the host. Look for the container or service you have run that is publishing the port and remove it:
$ docker container ls
$ docker service ls

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