Skip to content

Docker - Troubleshooting Localhost Connection Issues

Published: at 12:00 AM

When attempting to access a service running inside a Docker container via localhost, you might encounter connection errors. These few troubleshooting steps usually helps me resolve the issue.

1. Verify Docker Daemon Status

First, ensure Docker is running on your system:

docker ps

If the command returns no output, Docker might not be running. Refer to your specific operating system’s instructions for starting Docker.

2. Check Port Mapping

If your container exposes a port (e.g., port 80 for web applications), you need to map it to a host port using the -p flag when running the container:

docker run -p <host_port>:<container_port> <image_name>

Replace <host_port> with a port number you want to access on your machine (e.g., 3000) and <container_port> with the port the service inside the container exposes (e.g., 80).

3. Identify Container Network

By default, Docker containers run on a virtual network separate from your host machine. Accessing a service on localhost might require using the container’s IP address instead:

# List available networks
docker network ls

# Inspect container network settings
docker inspect <container_name>

Look for the container’s IP address under “Networks” in the inspection output.

4. Disable Auto HTTPS Redirect (Optional)

If you suspect an automatic HTTPS redirection may be interfering, you can temporarily disable it in your browser:

5. Address SSL Certificate Issues

An SSL_ERROR_RX_RECORD_TOO_LONG error usually indicates a problem with the container’s SSL certificate. For development environments, you can employ libraries like @vitejs/plugin-basic-ssl to create self-signed certificates for local development.

Side-note: I personally have not enjoyed using the library, can’t put a finger on why exactly.

6. Clear browser cache

Sometimes cached data can cause connection issues.

If you had your “localhost:<host_port>” run on “https”, that’s cached too.

Try clearing your browser’s cache and reloading the page.

Additional Resources

Docker documentation: The official Docker documentation provides in-depth guides and troubleshooting resources: https://docs.docker.com/


Previous Post
MLP vs MVP - Understanding Minimum Viable and Lovable Products
Next Post
High Memory Usage by 'vmmem' Process