docker单点启动nacos持久化密码
//
# docker单点启动nacos持久化密码
nacos-docker启动文档 (opens new window)
nacos-dockerhub (opens new window)
- 构建nacos-docker镜像
我这里有点小改动,里面有个sed,修改了启动脚本,官方的镜像会依赖mysql服务
vi Dcokerfile
FROM openjdk:8u252-jdk
MAINTAINER "yangfk"
LABEL version="jdk-8u252",nacos="2.0.2"
RUN test -d /home || mkdir /home
#docker镜像nacos/nacos-server:v2.1.0-slim 拷贝/home/nacos目录制作nacos.tar包
#ADD ./nacos-server-2.0.2.tar.gz /home/
ADD https://github.com/alibaba/nacos/releases/download/2.0.2/nacos-server-2.0.2.tar.gz /home
WORKDIR /home/nacos
#输出信息软链接
RUN mkdir logs && touch logs/start.out && ln -sf /dev/stdout logs/start.out && ln -sf /dev/stderr logs/start.out \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/zonetime \
&& rm -rf /var/lib/apt/lists/* \
&& sed -i 's#\(nohup\)\(.*\)&#\2#g' /home/nacos/bin/startup.sh
#nacos
ENV MODE=cluster PREFER_HOST_MODE=ip BASE_DIR=/home/nacos CLASSPATH=.:/home/nacos/conf: CLUSTER_CONF=/home/nacos/conf/cluster.conf FUNCTION_MODE=all NACOS_USER=nacos JAVA=/usr/local/openjdk-8/bin/java JVM_XMS=1g JVM_XMX=1g JVM_XMN=512m JVM_MS=128m JVM_MMS=320m NACOS_DEBUG=n TOMCAT_ACCESSLOG_ENABLED=false TZ=Asia/Shanghai LANG=en_US.UTF-8
EXPOSE 8848
ENTRYPOINT ["bash","bin/startup.sh","-m","standalone"]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
- 构建镜像,启动
docker build . -t harbor.yfklife.cn/public/nacos:2.0.2
docker run -it --restart=always -p 8848:8848 --name nacos harbor.yfklife.cn/public/nacos:2.0.2
1
2
2
# 单机运行持久化密码
登录界面修改nacos密码,默认账号密码:nacos/nacos
test -d /data && cd /data || mkdir /data && cd /data
test -d /data/nacos-data || mkdir /data/nacos-data
docker stop nacos
docker cp nacos:/home/nacos/data/derby-data /data/nacos-data/derby-data
docker rm -f nacos
docker run -it --restart=always -p 8848:8848 --name nacos -v /data/nacos-data/derby-data:/home/nacos/data/derby-data harbor.yfklife.cn/public/nacos:2.0.2
1
2
3
4
5
6
2
3
4
5
6
# 使用docker-compose启动nacos
vi docker-compose-nacos.yml
version: '3'
#宿主机IP: 10.12.32.180
services:
prod_nacos:
restart: always
container_name: prod_nacos
image: harbor.yfklife.cn/public/nacos:2.0.2
working_dir: /home/nacos
volumes:
- /etc/localtime:/etc/localtime
- /etc/timezone:/etc/timezone
#- ./nacos-data/derby-data:/home/nacos/data/derby-data #密码存储文件,持久化密码需要拷贝,挂载出来
ports:
- "8848:8848"
healthcheck:
test: ["CMD", "curl", "-f", "http://127.0.0.1:8848/nacos/index.html"]
interval: 1m
timeout: 5s
retries: 3
deploy:
resources:
limits:
memory: 2G
reservations:
memory: 1G
network_mode: bridge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
- 宿主机service 配置nacos服务
cat >/etc/init.d/nacos<<'EOF'
#!/bin/bash
source /etc/profile #需要配置jdk 环境
start(){
if ! $(ps -ef |grep nacos-server.jar >/dev/null );then
/home/nacos/bin/startup.sh -m standalone >/dev/null 2>&1 &
fi
sleep 3
ps -ef |grep nacos-server.jar
}
stop() {
bash /home/nacos/bin/shutdown.sh
}
restart() {
bash /home/nacos/bin/shutdown.sh
sleep 3
/home/nacos/bin/startup.sh -m standalone >/dev/null 2>&1 &
}
status() {
ps -ef |grep nacos-server.jar
curl -I 127.0.0.1:8848/nacos/index.html
}
case "$1" in
start)
start
;;
status)
status
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage :$0 {start|stop|restart|status}"
;;
esac
EOF
chmod +x /etc/init.d/nacos
service nacos start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
如果此文章对您有帮助,点击 -->> 请博主喝咖啡 (opens new window)
上次更新: 2023/12/28, 15:54:41