Troubleshooting Dockerized Nginx Container Port 80 on Mac (Sonoma 14.4)
Docker is a popular platform for developing, shipping, and running applications inside containers. Nginx is a web server that can also be used as a reverse proxy, load balancer, and HTTP cache. This article will help you troubleshoot a common issue when running a Dockerized Nginx container with port 80 on a Mac (Sonoma 14.4).
Prerequisites
Before diving into the troubleshooting steps, make sure you have the following:
- A Mac running Sonoma 14.4
- Docker Desktop installed
- A basic understanding of Docker and Nginx
Issue: Unable to Access Nginx on Port 80
When trying to run a Dockerized Nginx container with port 80, you might encounter the following situation:
$ sudo docker run -d -p 80:80 myapp_frontend:0.0.1
no error messages running container, up and running
However, when trying to access Nginx using a web browser or a tool like curl, you might face connection issues.
Troubleshooting Steps
Step 1: Check if the Container is Running
First, ensure that the container is running:
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e1f6c7c2b18d myapp_frontend:0.0.1 "nginx -g 'daemon off;'" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp nginx_frontend
Step 2: Inspect the Container
If the container is running, inspect it to gather more information:
$ sudo docker inspect e1f6c7c2b18d
...
"NetworkSettings": {
"Bridge": "",
"SandboxID": "2a2d985287e2e46a8f63a283e4e35c0e11a355d26f91310e86081f6e052123e3",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
},
{
"HostIp": "::",
"HostPort": "80"
}
]
},
"SandboxKey": "/var/run/docker/netns/2a2d985287e2",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "642c23e88253686f9a5e188e0a381c145b1a25b23e12263e15e3536c04a85e8b",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "21c62648e8d28b6606c6a54065e16302261e120d1a3e53120f0252458e5b1d2b",
"EndpointID": "642c23e88253686f9a5e188e0a381c145b1a25b23e12263e15e3536c04a85e8b",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
...
Step 3: Check Firewall Settings
On macOS, the built-in firewall might block incoming connections on port 80. To check the firewall settings:
$ sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
Enabled
If the firewall is enabled, you can add a rule to allow incoming connections on port 80:
$ sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add <ip-address> 80 ALLOW
Replace <ip-address> with your machine's IP address.
In this article, we covered the common issue of being unable to access Nginx on port 80 when running a Dockerized Nginx container on a Mac (Sonoma 14.4). We discussed troubleshooting steps, including checking if the container is running, inspecting the container, and verifying firewall settings. By following these steps, you should be able to resolve the issue and access Nginx successfully.
References
-
docker run - Run a command in a new container
-
docker inspect - Display detailed information on one or more containers