Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Deploying and Configuring Nacos Using Docker

Tech May 9 4

Pull Nacos Image

Retrieve the official Nacos server image from Docker Hub.

podman pull nacos/nacos-server

Run Nacos Container

Launch a standalone instance mapped to host port 8848:

podman run -d -p 8848:8848 -e MODE=standalone --name nacos_svr nacos/nacos-server:latest

To connect Nacos to an external MySQL database, specify connection parameters:

podman run -d --name nacos_svr \
  -e MODE=standalone \
  -e SPRING_DATASOURCE_PLATFORM=mysql \
  -e MYSQL_SERVICE_HOST=192.168.211.128 \
  -e MYSQL_SERVICE_PORT=3306 \
  -e MYSQL_SERVICE_DB_NAME=nacos_cfg \
  -e MYSQL_SERVICE_USER=root \
  -e MYSQL_SERVICE_PASSWORD=123456 \
  -p 8848:8848 \
  nacos/nacos-server:latest

Additional environment variables can disable debug mode:

podman run -d --name nacos_svr \
  --env MODE=standalone \
  --env SPRING_DATASOURCE_PLATFORM=mysql \
  --env MYSQL_SERVICE_HOST=192.168.211.128 \
  --env MYSQL_SERVICE_PORT=3306 \
  --env MYSQL_SERVICE_DB_NAME=nacos_cfg \
  --env MYSQL_SERVICE_USER=root \
  --env MYSQL_SERVICE_PASSWORD=123456 \
  --env NACOS_DEBUG=n \
  -p 8848:8848 \
  nacos/nacos-server

Modify Configuration Inside Container

Access the running container shell:

podman exec -it nacos_svr bash

Edit the primary configuration file:

vi /home/nacos/conf/application.properties

Relevant properties for database connectivity:

  • db.url.0 — primary DB connection string
  • db.url.1 — replica DB connection string (optional)
  • db.user — database username
  • db.password — database password

For single-instance setups, omit or comment out db.url.1.

Web console is accessible at http://192.168.211.128:8848/nacos/index.html.

Prepare Data base Schema

Create the required schema and tables before starting Nacos with MySQL persistence. Fetch the initialization script from the Nacos repository:
https://github.com/alibaba/nacos/blob/master/config/src/main/resources/META-INF/nacos-db.sql

Example schema creation and essential tables:

CREATE DATABASE IF NOT EXISTS nacos_cfg;
USE nacos_cfg;

CREATE TABLE config_data (
  rec_id BIGINT AUTO_INCREMENT PRIMARY KEY,
  data_key VARCHAR(255) NOT NULL,
  grp_key VARCHAR(255) DEFAULT NULL,
  payload LONGTEXT NOT NULL,
  checksum VARCHAR(32) DEFAULT NULL,
  created_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  updated_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  src_user TEXT,
  src_address VARCHAR(20) DEFAULT NULL,
  app_label VARCHAR(128) DEFAULT NULL,
  namespace_id VARCHAR(128) DEFAULT '',
  description VARCHAR(256) DEFAULT NULL,
  usage VARCHAR(64) DEFAULT NULL,
  effect VARCHAR(64) DEFAULT NULL,
  format VARCHAR(64) DEFAULT NULL,
  schema_body TEXT,
  UNIQUE KEY uniq_key_grp_ns (data_key, grp_key, namespace_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Configuration entries';

CREATE TABLE agg_config_data (
  rec_id BIGINT AUTO_INCREMENT PRIMARY KEY,
  data_key VARCHAR(255) NOT NULL,
  grp_key VARCHAR(255) NOT NULL,
  datum_key VARCHAR(255) NOT NULL,
  payload LONGTEXT NOT NULL,
  updated_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  app_label VARCHAR(128) DEFAULT NULL,
  namespace_id VARCHAR(128) DEFAULT '',
  UNIQUE KEY uniq_agg_key_grp_ns_datum (data_key, grp_key, namespace_id, datum_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Aggregated configuration items';

CREATE TABLE beta_config_data (
  rec_id BIGINT AUTO_INCREMENT PRIMARY KEY,
  data_key VARCHAR(255) NOT NULL,
  grp_key VARCHAR(128) NOT NULL,
  app_label VARCHAR(128) DEFAULT NULL,
  payload LONGTEXT NOT NULL,
  beta_hosts VARCHAR(1024) DEFAULT NULL,
  checksum VARCHAR(32) DEFAULT NULL,
  created_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  updated_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  src_user TEXT,
  src_address VARCHAR(20) DEFAULT NULL,
  namespace_id VARCHAR(128) DEFAULT '',
  UNIQUE KEY uniq_beta_key_grp_ns (data_key, grp_key, namespace_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Beta-release configurations';

CREATE TABLE tagged_config_data (
  rec_id BIGINT AUTO_INCREMENT PRIMARY KEY,
  data_key VARCHAR(255) NOT NULL,
  grp_key VARCHAR(128) NOT NULL,
  namespace_id VARCHAR(128) DEFAULT '',
  tag_label VARCHAR(128) NOT NULL,
  app_label VARCHAR(128) DEFAULT NULL,
  payload LONGTEXT NOT NULL,
  checksum VARCHAR(32) DEFAULT NULL,
  created_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  updated_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  src_user TEXT,
  src_address VARCHAR(20) DEFAULT NULL,
  UNIQUE KEY uniq_tag_key_grp_ns_tag (data_key, grp_key, namespace_id, tag_label)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Tagged configuration entries';

CREATE TABLE config_tag_links (
  link_id BIGINT NOT NULL,
  tag_label VARCHAR(128) NOT NULL,
  tag_kind VARCHAR(64) DEFAULT NULL,
  data_key VARCHAR(255) NOT NULL,
  grp_key VARCHAR(128) NOT NULL,
  namespace_id VARCHAR(128) DEFAULT '',
  seq_id BIGINT AUTO_INCREMENT,
  PRIMARY KEY (seq_id),
  UNIQUE KEY uniq_link_conf_tag (link_id, tag_label, tag_kind),
  INDEX idx_namespace (namespace_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Links between configs and tags';

CREATE TABLE group_limits (
  limit_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  grp_key VARCHAR(128) NOT NULL DEFAULT '',
  capacity_quota INT UNSIGNED NOT NULL DEFAULT 0,
  used_quota INT UNSIGNED NOT NULL DEFAULT 0,
  max_item_size INT UNSIGNED NOT NULL DEFAULT 0,
  max_agg_items INT UNSIGNED NOT NULL DEFAULT 0,
  max_agg_item_size INT UNSIGNED NOT NULL DEFAULT 0,
  max_history INT UNSIGNED NOT NULL DEFAULT 0,
  created_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  updated_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  UNIQUE KEY uniq_grp (grp_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Capacity limits per group';

CREATE TABLE historic_config_data (
  origin_id BIGINT UNSIGNED NOT NULL,
  hist_seq BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  data_key VARCHAR(255) NOT NULL,
  grp_key VARCHAR(128) NOT NULL,
  app_label VARCHAR(128) DEFAULT NULL,
  payload LONGTEXT NOT NULL,
  checksum VARCHAR(32) DEFAULT NULL,
  created_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  updated_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  src_user TEXT,
  src_address VARCHAR(20) DEFAULT NULL,
  operation VARCHAR(10) DEFAULT NULL,
  namespace_id VARCHAR(128) DEFAULT '',
  INDEX idx_created (created_at),
  INDEX idx_updated (updated_at),
  INDEX idx_datakey (data_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Historical configuration revisions';

CREATE TABLE tenant_limits (
  limit_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  tenant_id VARCHAR(128) NOT NULL DEFAULT '',
  capacity_quota INT UNSIGNED NOT NULL DEFAULT 0,
  used_quota INT UNSIGNED NOT NULL DEFAULT 0,
  max_item_size INT UNSIGNED NOT NULL DEFAULT 0,
  max_agg_items INT UNSIGNED NOT NULL DEFAULT 0,
  max_agg_item_size INT UNSIGNED NOT NULL DEFAULT 0,
  max_history INT UNSIGNED NOT NULL DEFAULT 0,
  created_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  updated_at DATETIME NOT NULL DEFAULT '2010-05-05 00:00:00',
  UNIQUE KEY uniq_tenant (tenant_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Per-tenant capacity settings';

CREATE TABLE tenant_profiles (
  profile_id BIGINT AUTO_INCREMENT PRIMARY KEY,
  access_key VARCHAR(128) NOT NULL,
  tenant_id VARCHAR(128) DEFAULT '',
  tenant_label VARCHAR(128) DEFAULT '',
  tenant_description VARCHAR(256) DEFAULT NULL,
  source VARCHAR(32) DEFAULT NULL,
  created_ts BIGINT NOT NULL,
  updated_ts BIGINT NOT NULL,
  UNIQUE KEY uniq_access_tenant (access_key, tenant_id),
  INDEX idx_tenant (tenant_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Tenant metadata';

CREATE TABLE sys_users (
    user_name VARCHAR(50) NOT NULL PRIMARY KEY,
    pwd_hash VARCHAR(500) NOT NULL,
    active BOOLEAN NOT NULL
);

CREATE TABLE sys_roles (
    user_name VARCHAR(50) NOT NULL,
    role_name VARCHAR(50) NOT NULL,
    CONSTRAINT uniq_user_role UNIQUE (user_name, role_name)
);

CREATE TABLE sys_permissions (
    role_name VARCHAR(50) NOT NULL,
    res_path VARCHAR(512) NOT NULL,
    act VARCHAR(8) NOT NULL,
    CONSTRAINT uniq_role_perm UNIQUE (role_name, res_path, act)
);

INSERT INTO sys_users (user_name, pwd_hash, active) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);

INSERT INTO sys_roles (user_name, role_name) VALUES ('nacos', 'ROLE_ADMIN');

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.