SoFunction
Updated on 2025-04-11

Example of implementation of starting Nacos in Docker

To start Nacos in Docker, you can use the following steps to start the Nacos service. I already have/ddn-k8s//nacos/nacos-server:v2.4.2.1This mirror.

1. Create and start the MySQL container (Nacos dependent on MySQL)

Nacos uses MySQL as the database by default, so you need to start a MySQL container first to ensure that the database is running normally.

First, start the MySQL container and use the following command:

docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=nacos -p 3306:3306 mysql:5.7

Here are the options descriptions:

  • -d: Run containers in the background
  • --name mysql: Assign the name to the container asmysql
  • -e MYSQL_ROOT_PASSWORD=root: Set the root user password of MySQL toroot
  • -e MYSQL_DATABASE=nacos: Create a name callednacosThe database
  • -p 3306:3306: Map the host's port 3306 to port 3306 in the container

If it has been created, just shut down and restart, you can directly

docker start nacos

2. Create and start the Nacos container

After the MySQL container is successfully started, start the Nacos container:

docker run -d --name nacos \
  -e MODE=standalone \
  -e MYSQL_HOST=192.168.100.128 \
  -e MYSQL_PORT=3306 \
  -e MYSQL_USER=root \
  -e MYSQL_PASSWORD=root \
  -e MYSQL_DATABASE=nacos \
  -p 8848:8848 \
  /ddn-k8s//nacos/nacos-server:v2.4.2.1

Here are the options descriptions:

  • -d: Run containers in the background
  • --name nacos: Assign the name to the container asnacos
  • -e MODE=standalone: Specify that Nacos starts in stand-alone mode
  • -e MYSQL_HOST=192.168.100.128: Specify the IP address of the MySQL database (here, assume that your local MySQL container address is192.168.100.128, if it is used by this machinelocalhostor127.0.0.1
  • -e MYSQL_PORT=3306: MySQL port number
  • -e MYSQL_USER=root: MySQL username
  • -e MYSQL_PASSWORD=root: MySQL password
  • -e MYSQL_DATABASE=nacos: Databases used by Nacos
  • -p 8848:8848: Map the container's port 8848 to the host's port 8848, which is the default management interface port for Nacos

3. Check the container status

After starting the Nacos container, you can view the running status of the container through the following command:

docker ps

You should be able to seenacosThe container is running.

4. Access the Nacos console

If everything works fine, you can access the Nacos console through your browser, and the access address is:

http://<host IP>:8848/nacos

For example, if your host IP address is192.168.100.128, then the URL should be:

http://192.168.100.128:8848/nacos

The default username and password are:

  • username:nacos
  • password:nacos

5. Configure the database

If there is a database connection problem after Nacos starts, you can try the following:

  • Make sure the MySQL container is running properly
  • Make sure MySQL users and database configuration is correct
  • Check if MySQL allows external connections (you may need to adjust the MySQL configuration or allow network communication between containers)

Through the above steps, you should be able to successfully launch Nacos and access it. If you have any questions, check the container log for more information:

docker logs nacos

This is the end of this article about the implementation example of starting Nacos in Docker. For more related content on starting Nacos, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!