In Nacos 2.x version, extra-open ports cause project deployment to fail to connect to Nacos
Li Wei
Title: Nacos 2.x Version – Additional Port Required for Project Deployment to Connect to Nacos
Problem Description
Log details:
- (log snippets omitted)
When the project starts, it cannot connect to the Nacos container on the server, although it works locally.
Investigation
- Starting Nacos with Docker works fine; the browser can access Nacos normally:
- (screenshot omitted)
- The relevant ports are open. When the YAML is configured with 8848, the error reports 9848; when configured with 9848, it reports 10848:
- (screenshot omitted)
Startup command: the command files have been custom‑modified.
Deployment steps:
- Deploy the gateway
- Deploy the admin service
- Deploy the project service
Using a
curlcommand, the service list can be retrieved from the Nacos server, indicating that Nacos itself is running correctly.
Potential Issues
Nacos version?
POM version:
- (snippet omitted)
Locally, version 2.1.1 works without issue. The Docker image uses the latest tag, which corresponds to 2.0.3.
Nacos database not configured. Nacos seems to have a default embedded database, which is outside the current scope of investigation.
Nacos username/password not configured. The local run also does not set these, so they are not being considered.
An attempt was made to unzip the Nacos package directly on the server and start it (JDK environment variables were also set), but this introduced more complex problems—Nacos failed to start—so the approach was abandoned.
Solution
In Nacos 2.x, gRPC support was added. Therefore, besides exposing port 8848, you also need to expose port 9848.
- 9848: In Nacos 2.x this is the default port for gRPC services. If the client‑server communication uses gRPC, this port must be mapped and exposed.
- 8848: This port remains used for HTTP/REST communication. If your client and server interact with Nacos via HTTP/REST, this port also needs to be mapped.
To run the container in standalone mode, execute the following command:
Originally written by Li Wei (李唯_) and published in Chinese on 后端技术栈全书 (Full-Stack Backend Engineering). Translated and adapted for DriftSeas with permission.