如何基于可在 ubuntu 上运行的 alpine 构建类似的 docker 映像?

格克尔

我正在尝试重写 Dockerfile ( https://github.com/orangefoil/rcssserver-docker/blob/master/Dockerfile ),以便它使用 alpine 而不是 ubuntu。目标是减小文件大小。

在原始图像中,robocup 足球服务器是使用 g++、flex、bison 等从头开始构建的。

FROM ubuntu:18.04 AS build
ARG VERSION=16.0.0
WORKDIR /root
RUN apt update && \
    apt -y install autoconf bison clang flex libboost-dev libboost-all-dev libc6-dev make wget
RUN wget https://github.com/rcsoccersim/rcssserver/archive/rcssserver-$VERSION.tar.gz && \
    tar xfz rcssserver-$VERSION.tar.gz && \
    cd rcssserver-rcssserver-$VERSION && \
    ./bootstrap && \
    ./configure && \
    make && \
    make install && \
    ldconfig

我尝试在 alpine 上做同样的事情,不得不交换一些包裹:

FROM alpine:latest
ARG VERSION=16.0.0
WORKDIR /root
# Add basics first
RUN apk — no-cache update \
    && apk upgrade \
    && apk add autoconf bison clang-dev flex-dev boost-dev make wget automake libtool-dev g++ build-base
RUN wget https://github.com/rcsoccersim/rcssserver/archive/rcssserver-$VERSION.tar.gz
RUN tar xfz rcssserver-$VERSION.tar.gz
RUN cd rcssserver-rcssserver-$VERSION && \
    ./bootstrap && \
    ./configure && \
    make && \
    make install && \
    ldconfig

不幸的是,我的版本还不能运行。它失败了

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lrcssclangparser

从我目前发现的情况来看,如果未安装开发包(请参阅ld 找不到现有库),就会发生这种情况,但我更改为可以找到它们的开发包,但仍然没有运气。

所以,我目前的假设是 ubuntu 安装了一些软件包,我需要将其添加到我的 alpine 映像中。我会排除代码问题,因为 ubuntu 版本有效。

任何想法,可能缺少什么?我也很乐意了解如何自己比较包,但 ubuntu 和 alpine 中的包命名不一样,所以我发现很难弄清楚这一点。

大卫迷宫

您应该使用多阶段构建来分解它在您现在构建的映像中,最终映像包含 C 工具链以及这些-dev包安装的所有开发库和头文件您不需要任何这些来实际运行构建的应用程序。基本思想是完全按照您现在COPY的方式构建应用程序,然后只将构建的应用程序转换为具有较少依赖项的新映像。

这看起来像这样(未经测试):

FROM ubuntu:18.04 AS build
# ... exactly what's in the original question ...

FROM ubuntu:18.04

# Install the shared libraries you need to run the application,
# but not -dev headers or the full C toolchain.  You may need to
# run `ldd` on the built binary to see what exactly it needs.
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive \
    apt-get install --assume-yes --no-install-recommends \
      libboost-atomic1.65.1 \
      libboost-chrono1.65.1 \
      # ... more libboost-* libraries as required ...

# Get the built application out of the original image.
# Autoconf's default is to install into /usr/local, and in a
# typical Docker base image nothing else will be installed there.
COPY --from=build /usr/local /usr/local
RUN ldconfig

# Describe how to run a container.
EXPOSE 12345
CMD ["/usr/local/bin/rcssserver"]

与 C 工具链、头文件和构建时库的大小相比,Alpine 和 Ubuntu 映像之间的差异非常小,并且 Alpine 具有充分记录的库兼容性问题及其最小的 libc 实现。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Docker / Alpine:如何在Alpine映像上安装NodeJS 4.8.4

在Docker中基于Alpine的映像上安装Redis

如何在基于Alpine的Docker映像中使用bash?

在基于 Alpine Docker 的映像下运行 gitlab-ci.yml 脚本时出错

Docker Node Alpine映像构建在node-gyp上失败

基于Ubuntu的Docker机器映像

如何为Docker Alpine映像构建静态Go二进制文件?

如何在Docker的官方php-fpm-alpine映像上安装XDebug?

在基于Alpine Linux的Docker映像中安装pylint

无法在python3.7-alpine docker映像上安装摆锤

Sh:在 alpine Docker 映像上找不到文件

如何在Ubuntu Docker映像中运行wget?

无法使用 Kaniko 构建运行 docker 映像(基于 Webshpere 自由)

如何使用Docker Hub在特定架构上构建Docker映像?

如何在Nginx Alpine Docker映像中启用本机模块

如何在Docker Ubuntu映像上安装git?

使用虚拟方法在Docker上构建映像并运行自己的代码

我可以在kubernetes中将任何类似的命令作为“ docker run -ti --rm alpine ls /”运行

如何在本地运行此mysql docker映像构建

如何在映像构建时/之后自动运行docker容器?

在Ubuntu Docker映像上录制声音

在Ubuntu上使用gunicorn:最新的Docker映像

如何保持ubuntu映像运行?

构建映像后,如何从.gitlab-ci.yml运行我的docker映像?

如何在Alpine Linux映像上启用busybox httpd

如何在Windows Server 2016上运行Linux Docker映像?

Kubernetes无法在本地运行Docker映像构建

构建映像时无法运行docker

Docker httpd:alpine映像以代码1退出