Mac M1上启动Mysql容器

在M1上拉取mysql镜像会出现以下报错,这是由于M1芯片是arm64架构,也称作aarch64架构,只能运行arm64/aarch64架构的程序,而我们去dockerHub搜索镜像会发现我们的Mysql5.7是amd64加购,也就是Intel CPU的架构,也叫做x86_64,之所以出现这个问题是存在适配型的问题,M1的芯片没有适合的镜像,所以报错。

no matching manifest for linux/arm65/v8 in the manifest list entrie

关于这个问题有以下三种解决方法:

  1. 自己编写Dockerfile
  2. pull别人写好的arm64架构的镜像
  3. pull镜像时加上--platform linux/x86_64参数

自己编写Dockerfile

# Build image cmd: docker build -t debian-mysql-server-5.7 .

FROM debian:sid-slim

# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mysql && useradd -r -g mysql mysql \
  \
  && echo "***** Init bash..." \
  && printf "\nalias ll='ls -l'\nalias l='ls -lA'\n" >> /root/.bashrc \
  # Map Ctrl-Up and Ctrl-Down to history based bash completion
  && printf '"\\e[1;5A": history-search-backward\n"\\e[1;5B": history-search-forward\n"\\e[1;5C": forward-word\n"\\e[1;5D": backward-word' > /etc/inputrc \
  \
  && echo "***** Install packages..." \
  && apt-get update \
  # Install apt-get allowing subsequent package configuration
  && DEBIAN_FRONTEND=noninteractive apt-get install -y apt-utils \
  # Install minimal admin utils
  && DEBIAN_FRONTEND=noninteractive apt-get install -y less nano procps \
  # Install MySQL server
  && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends libpwquality-tools mysql-server-5.7 \
  # Clean cache
  && rm -rf /var/lib/apt/lists/* \
  \
  && echo "***** Config mysql..." \
  && rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \
  && touch /var/log/mysqld.log \
  && chown -R mysql:mysql /var/lib/mysql /var/run/mysqld /var/log/mysqld.log \
  # Ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
  && chmod 777 /var/run/mysqld \
  && chmod 775 /var/log \
  # Disable Debian MySQL config since it overwrites config from volume
  && mv /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.disabled \
  && mv /etc/mysql/conf.d/mysqldump.cnf /etc/mysql/conf.d/mysqldump.cnf.disabled \
  && mv /etc/mysql/conf.d/mysql.cnf /etc/mysql/conf.d/mysql.cnf.disabled \
  # Create placeholder for custom my.cnf
  && touch /etc/mysql/conf.d/my.cnf \
  # Set docker settings, these settings always win
  && printf '[client]\nsocket=/var/lib/mysql/mysql.sock\n\n[server]\nsocket=/var/lib/mysql/mysql.sock\ndatadir=/var/lib/mysql\nsecure-file-priv=/var/lib/mysql-files\nuser=mysql\nskip-host-cache\nskip-name-resolve\n' > /etc/mysql/mysql.conf.d/docker.cnf \
  \
  && mkdir /docker-entrypoint-initdb.d \
  && echo "***** RUN commands finished"

VOLUME /var/lib/mysql

COPY docker-entrypoint.sh /entrypoint.sh
COPY healthcheck.sh /healthcheck.sh
ENTRYPOINT ["/entrypoint.sh"]
HEALTHCHECK CMD /healthcheck.sh
EXPOSE 3306 33060
CMD ["mysqld"]

pull别人写好的arm64架构的镜像

docker pull mysql/mysql-server
or
docker pull ibex/debian-mysql-server-5.7

pull镜像时加上--platform linux/x86_64参数

docker pull --platform linux/x86_64 mysql

参考链接:
https://scito.ch/content/mysql-57-docker-container-raspberry-pi-using-debian-sid
https://blog.csdn.net/zer0_o/article/details/114835667
https://blog.csdn.net/qq_22155255/article/details/118861560

暂无评论

发送评论 编辑评论


				
下一篇