当前位置:   首页安装配置

使用docker build kit构建树莓派上可用的Docker镜像

发布日期:2021-04-28 20:03 | 文章来源:站长之家

Docker安装

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG ${user_name}

build-kit是什么

  • 参考build ARM based Docker Images
  • 简单来说就是扩展docker build的一个实验性的功能

以bind为案例进行构建

docker-bind项目是一个开源的自定义DNS部署服务,但是并没有提供基于linux/aarch64架构的可用镜像,因此需要自己使用buildx命令执行构建操作

在树莓派系统中,执行uname -a来查看自己的目标架构

  • linux/aarch64
  • linux/amd64
  • linux/arm64
  • linux/arm/v7

....

# 在树莓派系统中执行如下命令
git clone https://github.com/sameersbn/docker-bind.git
cd docker-bind
# 修改Dockerfile内容,注意!!此项设置与docker-bind有关,与build-kit的使用无关,仅做演示用
echo 'FROM ubuntu:focal-20200423 AS add-apt-repositories
COPY jcameron-key.asc jcameron-key.asc
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y gnupg \
 && apt-get install -y curl \
 && apt-key adv --fetch-keys https://www.webmin.com/jcameron-key.asc \
 && echo "deb http://download.webmin.com/download/repository sarge contrib" >> /etc/apt/sources.list
FROM ubuntu:focal-20200423
LABEL maintainer="sameer@damagehead.com"
ENV BIND_USER=bind \
  BIND_VERSION=9.16.1 \
  WEBMIN_VERSION=1.970 \
  DATA_DIR=/data
RUN apt-get update \
 && apt-get install -y curl
COPY --from=add-apt-repositories /etc/apt/trusted.gpg /etc/apt/trusted.gpg
COPY --from=add-apt-repositories /etc/apt/sources.list /etc/apt/sources.list
RUN rm -rf /etc/apt/apt.conf.d/docker-gzip-indexes \
 && apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y \
   bind9=1:${BIND_VERSION}* bind9-host=1:${BIND_VERSION}* dnsutils \
   webmin=${WEBMIN_VERSION}* \
 && rm -rf /var/lib/apt/lists/*
COPY entrypoint.sh /sbin/entrypoint.sh
RUN chmod 755 /sbin/entrypoint.sh
EXPOSE 53/udp 53/tcp 10000/tcp
ENTRYPOINT ["/sbin/entrypoint.sh"]
CMD ["/usr/sbin/named"]' > Dockerfile
# 登录到自己的docker仓库
# 自己使用的是阿里云的镜像仓库,也可以使用dockerhub官方仓库
docker login --username=${user_name} registry.cn-hangzhou.aliyuncs.com
docker buildx build --platform linux/aarch64 -t registry.cn-hangzhou.aliyuncs.com/docker-image-lee/bind:aarch64 --no-cache --push .
# 如果是在Mac或Windows上执行构建的话,需要首先执行下述命令
docker buildx create --use

push完成后,就可以在树莓派上拿来用了~

参考

build ARM based Docker Images

docker buildx build

Build Docker Image for Raspberry Pi

到此这篇关于使用docker build kit构建树莓派上可用的Docker镜像的文章就介绍到这了,更多相关docker build kit树莓派Docker镜像内容请搜索本站以前的文章或继续浏览下面的相关文章希望大家以后多多支持本站!

联系我们
关于使用场景和技术架构的更多咨询,请联系我们的销售和技术支持团队。
Yingsoo Host

在线
客服

在线客服:7*24小时在线

客服
热线

400-630-3752
7*24小时客服服务热线

关注
微信

关注官方微信
顶部