Installing the nacos image in Mac M1

Keywords: Docker Microservices Container ARM macOS

For the windows system I used before, the newly purchased M1 just arrived a few days ago. I encountered some problems when running the nacos container with docker desktop, so I make a record. I also hope my experience can help more people.
First, the nacos image on the docker hub official website does not support the arm architecture. You need to package the nacos image to run.

Self packing

First, download the package project provided by nacos

https://github.com/nacos-group/nacos-docker.git

This project is a project provided by nacos to quickly package the nacos docker image. It provides an example of docker compose arrangement and the source code of docker image production. Here we need to make our docker image according to the image production source code.

Modify dockerfile

Enter the build folder and open the Dockerfile file

FROM centos:7.5.1804
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/lib/jvm/java-1.8.0-openjdk" \
    NACOS_USER="nacos" \
    JAVA="/usr/lib/jvm/java-1.8.0-openjdk/bin/java" \
    JVM_XMS="1g" \
    JVM_XMX="1g" \
    JVM_XMN="512m" \
    JVM_MS="128m" \
    JVM_MMS="320m" \
    NACOS_DEBUG="n" \
    TOMCAT_ACCESSLOG_ENABLED="false" \
    TIME_ZONE="Asia/Shanghai"

ARG NACOS_VERSION=2.0.3
ARG HOT_FIX_FLAG=""
WORKDIR $BASE_DIR

RUN set -x \
    && yum update -y \
    && yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-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

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"]

Here is the source code of nacos image packaging. We need to change part of it for Mac M1 adaptation

  1. Modify mirror system
    The official centos:7.5.1804 system does not support the arm architecture, so we need to use the centos 8 system that supports the arm architecture. Modify the first line of the file FROM centos:7.5.1804 to FROM centos:8.3.2011
    One more thing that needs to be changed is
RUN set -x \
    && yum update -y \
    && yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel wget iputi  ls nc  vim libcurl

Directly packaging the docker image will report errors and dependency conflicts, so we add a sentence here -- allowing, under the modified content map

  RUN set -x \
     && yum update -y \
     && yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel wget iputi ls nc vim libcurl --allowerasing

The changes in the full version are as follows:

FROM centos:8.3.2011
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/lib/jvm/java-1.8.0-openjdk" \
    NACOS_USER="nacos" \
    JAVA="/usr/lib/jvm/java-1.8.0-openjdk/bin/java" \
    JVM_XMS="1g" \
    JVM_XMX="1g" \
    JVM_XMN="512m" \
    JVM_MS="128m" \
    JVM_MMS="320m" \
    NACOS_DEBUG="n" \
    TOMCAT_ACCESSLOG_ENABLED="false" \
    TIME_ZONE="Asia/Shanghai"

ARG NACOS_VERSION=2.0.3
ARG HOT_FIX_FLAG=""

WORKDIR $BASE_DIR

RUN set -x \
    && yum update -y \
    && yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel wget iputils nc  vim libcurl --allowerasing
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
    
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"]

After the changes are completed, we can use the docker build command to package and run the command (don't forget that.)

docker build -t nacos:2.0.3 .

After the packaging is completed, enter docker images and you can see the packaged docker images. Next, let's introduce running the nacos image in an choreographed manner and starting the mysql8 image together.
Enter the example folder and modify the configuration file standalone-mysql-8.yaml
Modifying a nacos image

version: "2"
services:
  nacos:
    image: nacos/nacos-server:${NACOS_VERSION}

The original version uses Nacos / nasoc server: 2.0.3. Here we modify it to the image we just packaged

version: "2"
services:
   nacos:
   image: nacos:2.0.3

Return to the upper layer and modify the nacos-standlone-mysql.env file in the env folder in MySQL_ SERVICE_ DB_ At the end of param attribute, add & AllowPublicKeyRetrieval=True because if the user uses sha256_password authentication: the password must be protected by TLS protocol during transmission, but if the RSA public key is unavailable, the public key provided by the server can be used; You can specify the RSA public key of the server through ServerRSAPublicKeyFile in the connection, or the AllowPublicKeyRetrieval=True parameter to allow the client to obtain the public key from the server; However, it should be noted that AllowPublicKeyRetrieval=True may cause a malicious agent to obtain a plaintext password through man in the middle attack (MITM), so it is turned off by default and must be explicitly turned on.

ps: it should be noted that in the standalone-mysql-8.yaml file, the MySQL directory is used to hang in the / MySQL folder. Systems above Mac OS 10.15 cannot create folders with the directory. Here, you can modify the MySQL hanging in the directory. During the development process, applications also need to create folders with the directory and use them. The author tried to close SIP, It's still not easy to use. It's the last one Create soft connection The directory was successfully created by the method of.

Return to the upper directory
Execute command in directory

docker-compose -f example/standalone-mysql-8.yaml up

After running, the console will output the Nacos startup log for browser access http://localhost:8848/nacos If the login page can pop up, the container with this name will start successfully. The default login account and password of Nacos are all Nacos
So far, nacos has been successfully run on Mac M1 computer.

Posted by chrisdarby on Sun, 28 Nov 2021 08:03:00 -0800