目录
0. 官方文档
1. 修改docker的配置文件
2. 下载nacos代码
3. Dockerfile文件内容替换
4. 创建nacos的docker镜像
5. 启动nacos服务
6. 操作完后,打开docker
mac docker安装nacos异常
0. 官方文档
Nacos Docker 快速开始
ERROR org.springframework.boot.SpringApplication - Application run failed
com.alibaba.nacos.api.exception.runtime.NacosRuntimeException: ErrCode:500, ErrMsg:Function not implemented
at com.alibaba.nacos.core.listener.StartingApplicationListener.loadPreProperties(StartingApplicationListener.java:161)
at com.alibaba.nacos.core.listener.StartingApplicationListener.environmentPrepared(StartingApplicationListener.java:100)
at com.alibaba.nacos.core.code.SpringApplicationRunListener.environmentPrepared(SpringApplicationRunListener.java:65)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:342)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
at com.alibaba.nacos.Nacos.main(Nacos.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: com.alibaba.nacos.api.exception.NacosException: java.io.IOException: Function not implemented
at com.alibaba.nacos.sys.file.WatchFileCenter$WatchDirJob.<init>(WatchFileCenter.java:189)
at com.alibaba.nacos.sys.file.WatchFileCenter.registerWatcher(WatchFileCenter.java:97)
at com.alibaba.nacos.core.listener.StartingApplicationListener.registerWatcher(StartingApplicationListener.java:167)
at com.alibaba.nacos.core.listener.StartingApplicationListener.loadPreProperties(StartingApplicationListener.java:159)
... 16 common frames omitted
Caused by: java.io.IOException: Function not implemented
at sun.nio.fs.LinuxWatchService.<init>(LinuxWatchService.java:64)
at sun.nio.fs.LinuxFileSystem.newWatchService(LinuxFileSystem.java:47)
at com.alibaba.nacos.sys.file.WatchFileCenter$WatchDirJob.<init>(WatchFileCenter.java:184)
... 19 common frames omitted
出现这个的原因是,mac(m1我的是)jdk没有这个实现类,所以在执行的时候报错
1. 修改docker的配置文件
修改完后,保存,重启docker服务
{
"experimental": true,
"builder": {
"gc": {
"enabled": true,
"defaultKeepStorage": "20GB"
}
},
"features": {
"buildkit": false
}
}
2. 下载nacos代码
git clone https://github.com/nacos-group/nacos-docker.git
3. Dockerfile文件内容替换
FROM openjdk:8u312-jdk-slim-bullseye AS build-env-java
#FROM condaforge/mambaforge:4.9.2-5 as conda
MAINTAINER pader "huangmnlove@163.com"
# set environment
ENV MODE="cluster" \
PREFER_HOST_MODE="ip"\
BASE_DIR="/home/nacos" \
CLASSPATH=".:/home/nacos/conf:$CLASSPATH" \
CLUSTER_CONF="/home/nacos/conf/cluster.conf" \
FUNCTION_MODE="all" \
JAVA_HOME="/usr/local/openjdk-8" \
NACOS_USER="nacos" \
JAVA="/usr/local/openjdk-8/bin/java" \
JVM_XMS="256m" \
JVM_XMX="256m" \
JVM_XMN="128m" \
JVM_MS="128m" \
JVM_MMS="128m" \
NACOS_DEBUG="n" \
TOMCAT_ACCESSLOG_ENABLED="false" \
TIME_ZONE="Asia/Shanghai"
ARG NACOS_VERSION=2.1.1
ARG HOT_FIX_FLAG=""
RUN echo $NACOS_VERSION
WORKDIR $BASE_DIR
RUN apt-get update
RUN apt-get -y install wget
#RUN set -x \
# && yum update -y \
# && yum install -y java-8u312-jdk-slim-bullseye java-8u312-jdk-slim-bullseye-devel wget iputils nc vim libcurl
RUN wget https://github.com/alibaba/nacos/releases/download/${NACOS_VERSION}${HOT_FIX_FLAG}/nacos-server-${NACOS_VERSION}.tar.gz -P /home
RUN tar -xzvf /home/nacos-server-${NACOS_VERSION}.tar.gz -C /home \
&& rm -rf /home/nacos-server-${NACOS_VERSION}.tar.gz /home/nacos/bin/* /home/nacos/conf/*.properties /home/nacos/conf/*.example /home/nacos/conf/nacos-mysql.sql
#RUN yum autoremove -y wget \
# && ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo $TIME_ZONE > /etc/timezone \
# && yum clean all
RUN ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo $TIME_ZONE > /etc/timezone
#拷贝本地文件数据 到 容器文件夹内(前面的是本地文件可以使用绝对路径, 可以使用相对路径(相对build文件夹的路径))
#COPY nacos/target/* /home/nacos/target/
#COPY nacos/conf/* /home/nacos/conf/
ADD bin/docker-startup.sh bin/docker-startup.sh
ADD conf/application.properties conf/application.properties
# set startup log dir
RUN mkdir -p logs \
&& cd logs \
&& touch start.out \
&& ln -sf /dev/stdout start.out \
&& ln -sf /dev/stderr start.out
RUN chmod +x bin/docker-startup.sh
EXPOSE 8848
ENTRYPOINT ["bin/docker-startup.sh"]
4. 创建nacos的docker镜像
在该文件夹下执行命令 /nacos-docker/build
docker build -t nacos/nacos-server:v2.1.1 .
5. 启动nacos服务
standalone-derby.yaml 使用的是docker-compose对多个服务(nacos, prometheus, grafana)进行启动,如果只需启动nacos则将其他的服务配置注释掉即可
在该文件夹下执行命令 /nacos-docker
docker-compose -f example/standalone-derby.yaml up