Port exposure issue when using docker run

Problem: I am unable access a container locally that was started using docker run

Background: I just started the k8s beginner course and am using an intel-based Macbook Pro (2020). I removed Docker Desktop and replaced it with Hyperkit, Docker CLI, kubectl and Minikube. I used homebrew to install these new tools.

When I execute docker run -d -p 8080:80 --name web nginx I am unable to access the container locally on port 8080. A curl to localhost:8080 returns curl: (7) Failed to connect to localhost port 8080: Connection refused

I have confirmed the container is up and part of the default bridge network by executing docker ps -f network=bridge

I would like to resolve this issue so that:

  1. I can perform my daily duties without reinstalling Docker Desktop (I use Docker, docker compose & Dockerfiles daily at work)
  2. I can continue through the course without creating a blocker by fixing this issue in the wrong way

I am so new to this that I am not yet sure how all of these pieces fit together so googling for an answer is possible however I cannot yet evaluate the results within the context of my specific problem. I appreciate anyone who is able to help.


edit: I was able to bypass this issue by executing minikube ip and using the provided IP to access my locally running container. I’d still prefer to use localhost if anyone knows of a solution.

curl -I 192.168.64.2:8080 now returns HTTP/1.1 200 OK

The following link will be useful :