11

I start my docker container with:

docker run -it --expose 10001 --expose 8080 -p 10001:10001 -p 8080:8080 -p 80:80 --rm lucchi/covid90/100e

My docker -ps then has:

CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                  PORTS                                                                  NAMES    
1521e0c3d947        lucchi/covid90/100e   "/bin/sh -c /bin/bash"   2 seconds ago       Up Less than a second   0.0.0.0:80->80/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:10001->10001/tcp   funny_panini

But I can't connect to localhost from inside the container. I tried:

curl 0.0.0.0:8080 
curl 127.0.0.1:8080
curl https://localhost:8080

but keep getting

curl: (7) Failed to connect to localhost port 8080: Connection refused

Most of the asnwers I read are about adding -p to the run command, I don't get what I'm missing.

ALU
  • 353
  • 2
  • 4
  • 18
  • That `docker ps` output suggests your container is running a shell and not a server process. Can you include your image's Dockerfile in the question? (Other common causes are a server configured to listen on 127.0.0.1 and not 0.0.0.0, or running Docker Toolbox or another VM-oriented Docker installation.) – David Maze Aug 25 '20 at 14:38

3 Answers3

2

Are you trying to connect inside the container?

If not, you may fight this other unrelated question (covering the outside container case) helpful:

From inside of a Docker container, how do I connect to the localhost of the machine?

Alex R
  • 11,364
  • 15
  • 100
  • 180
vvg
  • 1,010
  • 7
  • 25
0

Instead of curl https://localhost:8080 try curl host.docker.internal:8080.

w. Patrick Gale
  • 1,643
  • 13
  • 22
-2

Is the a server process running inside the docker on the specified port ?

If the app logs are enabled you can get the logs of the container by executing the below command.

docker logs <container_name>

Additionally for ensuring if the app is up and running fine, try doing a curl from inside of the docker container. You can use the docker exec command to execute any command inside the container.

shek
  • 7
  • 1
  • 4
  • If the connection is refused the logs won't show any request. Unless you mean that the logs would show that something broke during the process, which is an obvious issue and I doubt is our case here – Shady Smaoui Apr 28 '22 at 20:51