今天在Docker中安装Nacos连接MySQL的时候出现了问题,发现容器间需要通信。
现在记录下来:
1、创建自定义网络(用于容器间通讯)
docker network create common-network
2、查看网络
docker network ls
3、重新安装mysql
docker run -p 13306:3306 --name mysql \ ##运行镜像生成容器
--network common-network \
-v /opt/myfile/mysql/conf:/etc/mysql/conf.d \
-v /opt/myfile/mysql/logs:/logs \
-v /opt/myfile/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=admin123 \ ##密码
-d mysql:5.6
4、查看mysql容器的网络
docker network inspect common-network
5、安装docker
1、拉取镜像
docker pull nacos/nacos-server
2、创建本地映射文件
mkdir -p /opt/software/myfile/naocs/init.d /opt/software/myfile/nacos/logs
touch /opt/software/myfile/nacos/init.d/custom.properties
在custom.properties中写入:
management.endpoints.web.exposure.include=*
3、创建数据库 nacos_config
4、nacos初始化sql,需要先创建nacos数据库后,然后执行下面的Sql
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for app_configdata_relation_pubs
-- ----------------------------
DROP TABLE IF EXISTS `app_configdata_relation_pubs`;
CREATE TABLE `app_configdata_relation_pubs` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`gmt_modified` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_app_pub_config_datagroup`(`app_name`, `data_id`, `group_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for app_configdata_relation_subs
-- ----------------------------
DROP TABLE IF EXISTS `app_configdata_relation_subs`;
CREATE TABLE `app_configdata_relation_subs` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`gmt_modified` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_app_sub_config_datagroup`(`app_name`, `data_id`, `group_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for app_list
-- ----------------------------
DROP TABLE IF EXISTS `app_list`;
CREATE TABLE `app_list` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`is_dynamic_collect_disabled` smallint(6) NULL DEFAULT 0,
`last_sub_info_collected_time` timestamp(0) NOT NULL DEFAULT '1970-01-01 08:00:00',
`sub_info_lock_owner` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sub_info_lock_time` timestamp(0) NOT NULL DEFAULT '1970-01-01 08:00:00',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_appname`(`app_name`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for config_info
-- ----------------------------
DROP TABLE IF EXISTS `config_info`;
CREATE TABLE `config_info` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`gmt_create` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`gmt_modified` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`src_user` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip',
`c_desc` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`c_use` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`effect` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`type` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`c_schema` mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_configinfo_datagrouptenant`(`data_id`, `group_id`, `tenant_id`) USING BTREE,
INDEX `configinfo_dataid_key_idx`(`data_id`) USING BTREE,
INDEX `configinfo_groupid_key_idx`(`group_id`) USING BTREE,
INDEX `configinfo_dataid_group_key_idx`(`data_id`, `group_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for config_info_aggr
-- ----------------------------
DROP TABLE IF EXISTS `config_info_aggr`;
CREATE TABLE `config_info_aggr` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`datum_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`gmt_modified` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_configinfoaggr_datagrouptenantdatum`(`data_id`, `group_id`, `tenant_id`, `datum_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for config_info_beta
-- ----------------------------
DROP TABLE IF EXISTS `config_info_beta`;
CREATE TABLE `config_info_beta` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`beta_ips` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`gmt_create` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`gmt_modified` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`src_user` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_configinfobeta_datagrouptenant`(`data_id`, `group_id`, `tenant_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for config_info_tag
-- ----------------------------
DROP TABLE IF EXISTS `config_info_tag`;
CREATE TABLE `config_info_tag` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`tag_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`gmt_create` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`gmt_modified` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`src_user` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'source ip',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_configinfotag_datagrouptenanttag`(`data_id`, `group_id`, `tenant_id`, `tag_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for config_tags_relation
-- ----------------------------
DROP TABLE IF EXISTS `config_tags_relation`;
CREATE TABLE `config_tags_relation` (
`id` bigint(20) NOT NULL,
`tag_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tag_type` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`nid` bigint(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`nid`) USING BTREE,
UNIQUE INDEX `uk_configtagrelation_configidtag`(`id`, `tag_name`, `tag_type`) USING BTREE,
INDEX `config_tags_tenant_id_idx`(`tenant_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for group_capacity
-- ----------------------------
DROP TABLE IF EXISTS `group_capacity`;
CREATE TABLE `group_capacity` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`quota` int(11) NULL DEFAULT 0,
`USAGE` int(11) NULL DEFAULT 0,
`max_size` int(11) NULL DEFAULT 0,
`max_aggr_count` int(11) NULL DEFAULT 0,
`max_aggr_size` int(11) NULL DEFAULT 0,
`max_history_count` int(11) NULL DEFAULT 0,
`gmt_create` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`gmt_modified` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_group_id`(`group_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for his_config_info
-- ----------------------------
DROP TABLE IF EXISTS `his_config_info`;
CREATE TABLE `his_config_info` (
`id` bigint(20) NOT NULL,
`nid` bigint(20) NOT NULL AUTO_INCREMENT,
`data_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`group_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`app_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`md5` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`gmt_create` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`gmt_modified` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`src_user` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`src_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
`op_type` char(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`nid`) USING BTREE,
INDEX `hisconfiginfo_dataid_key_idx`(`data_id`) USING BTREE,
INDEX `hisconfiginfo_gmt_create_idx`(`gmt_create`) USING BTREE,
INDEX `hisconfiginfo_gmt_modified_idx`(`gmt_modified`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for permissions
-- ----------------------------
DROP TABLE IF EXISTS `permissions`;
CREATE TABLE `permissions` (
`role` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`resource` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`action` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
UNIQUE INDEX `uk_role_permission`(`role`, `resource`, `action`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for roles
-- ----------------------------
DROP TABLE IF EXISTS `roles`;
CREATE TABLE `roles` (
`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`role` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
UNIQUE INDEX `uk_username_role`(`username`, `role`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of roles
-- ----------------------------
INSERT INTO `roles` VALUES ('nacos', 'ROLE_ADMIN');
-- ----------------------------
-- Table structure for tenant_capacity
-- ----------------------------
DROP TABLE IF EXISTS `tenant_capacity`;
CREATE TABLE `tenant_capacity` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`quota` int(11) NULL DEFAULT 0,
`USAGE` int(11) NULL DEFAULT 0,
`max_size` int(11) NULL DEFAULT 0,
`max_aggr_count` int(11) NULL DEFAULT 0,
`max_aggr_size` int(11) NULL DEFAULT 0,
`max_history_count` int(11) NULL DEFAULT 0,
`gmt_create` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
`gmt_modified` timestamp(0) NOT NULL DEFAULT '2010-05-05 00:00:00',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_tenant_id`(`tenant_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for tenant_info
-- ----------------------------
DROP TABLE IF EXISTS `tenant_info`;
CREATE TABLE `tenant_info` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`kp` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tenant_id` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`tenant_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
`tenant_desc` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`create_source` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`gmt_create` bigint(20) NOT NULL,
`gmt_modified` bigint(20) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uk_tenant_info_kptenantid`(`kp`, `tenant_id`) USING BTREE,
INDEX `tenant_info_tenant_id_idx`(`tenant_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`PASSWORD` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`enabled` tinyint(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`username`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1);
SET FOREIGN_KEY_CHECKS = 1;
启动容器
docker run --network common-network --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server
//查看网络
docker network ls
//查看网络容器
docker network inspect common-network
// 进入容器
docker exec -it nacos bash
// 修改容器配置
cd conf
vi application.properties
或者 将 容器中的 配置挂载出来再修改
docker container cp nacos:/home/nacos/conf .
docker run -d -p 7848:7848 -p 8848:8848 -p 9555:9555 -p 9848:9848 -p 9849:9849 \
--network common-network \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.73.107 \
-e MYSQL_SERVICE_PORT=13306 \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=admin123 \
-e MYSQL_DATABASE_NUM=1 \
-v /opt/software/myfile/nacos/conf/application.properties:/home/nacos/conf/application.properties \
-v /opt/software/myfile/nacos/conf/nacos-logback.xml:/home/nacos/conf/nacos-logback.xml \
-v /opt/software/myfile/nacos/logs:/home/nacos/logs \
--restart always --name nacos nacos/nacos-server