麒麟Arm64nacos打包docker镜像说明
将conf的nacos-logback.xml和application.properties拷贝到对应目录。下载版本为jdk-8u321-linux-aarch64.tar.gz的jdk。(1)麒麟根据ubuntu开发,基础镜像最好根据ubuntu发布;(2)修改nacos-standlone-mysql.env。(2)现有的nacos镜像全部为基于centos发布;(1)编写docker-com
1 需求说明
1.1 目标
在麒麟Arm版本下打包nacos镜像。
1.2 问题
(1) 麒麟根据ubuntu开发,基础镜像最好根据ubuntu发布;
(2) 现有的nacos镜像全部为基于centos发布;
(3) 现有发布为openjdk要改为标准jdk;
(4) 需要使用mysql8版本的数据库;
2 实现过程
2.1 下载基础镜像并设置相关环境
2.1.1 拉取最新镜像
docker pull ubuntu
2.1.2 启动一个容器设置环境
(1) 启动
sudo docker run -it --name ubuntu --privileged -p 10023:22 -p 10081:80 ubuntu /bin/bash
(2) 进入容器设置环境
apt-get update
apt-get upgrade
apt-get install -y wget
(3) 将容器生成为镜像
docker commit -m="apt-get update" -a="itos/jia" ec0857d405a7 itos/ubuntu:v16.04
2.2 制作jdk镜像
根据生成的itos/ubuntu:v16.04来增加jdk
(1) 下载jdk
下载版本为jdk-8u321-linux-aarch64.tar.gz的jdk。
(2) 编写Dockerfile
内容如下
FROM itos/ubuntu:v16.04
MAINTAINER itos/jia
RUN mkdir /usr/local/java
ADD jdk-8u321-linux-aarch64.tar.gz /usr/local/java
RUN ln -s /usr/local/java/jdk1.8.0_321 /usr/local/java/jdk
# set environment variables
ENV JAVA_HOME /usr/local/java/jdk
ENV JRE_HOME ${JAVA_HOME}/jre
ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib
ENV PATH ${JAVA_HOME}/bin:$PATH
注意ln的目录一定要设置对
(3) 执行命令
docker build -t itos/jdk:v1.8.0 .
2.3 制作nacos镜像
(1) 下载nacos-server的最新版本
https://github.com/alibaba/nacos/releases/download/2.1.0/nacos-server-2.1.0.tar.gz
放到一个自己可以快速访问的网站。
(2) 编写Dockerfile
# Nacos Ubuntu with JDK 8
# Author itos/jia
# build a new image with basic ubuntu
FROM itos/jdk:v1.8.0
# who is the author
MAINTAINER itos/jia
# 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/java/jdk" \
NACOS_USER="nacos" \
JAVA="/usr/local/java/jdk/bin/java" \
JVM_XMS="256m" \
JVM_XMX="256m" \
JVM_XMN="256m" \
JVM_MS="128m" \
JVM_MMS="320m" \
NACOS_DEBUG="n" \
TOMCAT_ACCESSLOG_ENABLED="false" \
TIME_ZONE="Asia/Shanghai"
ARG NACOS_VERSION=2.1.0
ARG HOT_FIX_FLAG=""
RUN wget http://192.168.110.101:20000/data/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
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"]
(3) 执行命令
docker build -t itos/nacos-server:v2.1.0 .
2.4 通过docker-compose发布
(1) 编写docker-compose.yaml
version: "3.4"
services:
nacos:
image: itos/nacos-server:v2.1.0
container_name: nacos
env_file:
- ./env/nacos-standlone-mysql.env
volumes:
- /itos/data/nacos/standalone-logs/:/home/nacos/logs
- /itos/data/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties
- /itos/data/nacos/conf:/home/nacos/conf
environment:
- TZ= Asia/Shanghai
ports:
- "38848:8848"
- "39848:9848"
- "39555:9555"
depends_on:
- nacos-mysql
restart: always
nacos-mysql:
container_name: nacos-mysql
image: itos/mysql:v8.0.29-0ubuntu0.22.04.2
env_file:
- ./env/mysql.env
environment:
- TZ= Asia/Shanghai
volumes:
- /itos/data/nacos/mysql/data:/var/lib/mysql
ports:
- "23306:3306"
(2) 修改nacos-standlone-mysql.env
PREFER_HOST_MODE=hostname
MODE=standalone
SPRING_DATASOURCE_PLATFORM=mysql
MYSQL_SERVICE_HOST=nacos-mysql
MYSQL_SERVICE_DB_NAME=nacos_config
MYSQL_SERVICE_PORT=3306
MYSQL_SERVICE_USER=nacos
MYSQL_SERVICE_PASSWORD=nacos
MYSQL_DATABASE_NUM=1
MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=2000&allowPublicKeyRetrieval=true&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai
对于mysql8以上版本必须增加allowPublicKeyRetrieval=true
(3) 拷贝配置文件
将conf的nacos-logback.xml和application.properties拷贝到对应目录
3 测试
http://ip:38848/nacos
默认用户名密码nacos/nacos
录入一个配置看是否成功。
4 参考
https://github.com/nacos-group/nacos-docker
更多推荐
所有评论(0)