Docker Login(Mac版Docker)如何知晓Artifactory运行的8081端口?
Great question! Let's break down the possible ways your Mac Docker client is figuring out to use port 8081 for Artifactory, even though you're only specifying docker.artifactory in the docker login command:
Docker Desktop Registry Configuration
The most common scenario is that you’ve pre-configured the repository’s port in Docker Desktop. On Mac, Docker Desktop lets you defineinsecure-registriesor explicit registry endpoints that include port numbers. For example, if you added"insecure-registries": ["docker.artifactory:8081"]in Settings > Docker Engine, the Docker client will automatically associate this domain with port 8081—prioritizing this over the default Registry ports (80/443, or your mentioned 8080) when you rundocker login docker.artifactory.HTTP Redirects from Artifactory
Another possibility is that when your Docker client tries connecting todocker.artifactory:8080(the default Registry port you referenced), Artifactory returns an HTTP 3xx redirect pointing to the Docker repository endpoint on port 8081. Docker clients are designed to follow valid redirects by default, so it will automatically switch to port 8081 to complete the login flow. This requires Artifactory to have redirect rules configured to route 8080 Registry traffic to its 8081 Docker repository.Local Port Forwarding/Proxy
You might have a local port forwarding setup on your Mac (using tools likepfctl, or third-party proxy apps) that forwards traffic from your machine’s port 8080 to the target IP’s port 8081. When you rundocker login docker.artifactory, the client connects to port 8080 by default, but the local forwarding routes that traffic to Artifactory’s 8081 port—making it seem like the client "automatically detected" the port.Artifactory's Dual Port Listening
Less likely, but possible: Artifactory might be configured to listen on both port 8080 and 8081, with its Docker repository enabled on both ports. Even though you assumed it only runs on 8081, a quick check of Artifactory’s network settings could confirm if 8080 is also serving the Docker repository.
To pinpoint the exact cause, you can:
- Check your Docker Desktop settings (the Docker Engine config file is typically at
~/.docker/config.json, or accessible via the GUI) - Review Artifactory’s HTTP access logs to look for redirect requests
- Verify local port forwarding rules on your Mac using
sudo pfctl -s nator similar commands
内容的提问来源于stack exchange,提问作者James Lee

