我正在尝试重写一个Dockerfile (https://github.com/orangefoil/rcssserver-docker/blob/master/Dockerfile),这样它就可以使用阿尔卑斯而不是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我试着在高山上做同样的事情,不得不换了一些包:
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 cannot find an existing library),这种情况可能会发生,但我更改为开发包,在那里我可以找到它们,但仍然没有运气。
所以,我现在假设ubuntu已经安装了一些包,我需要在我的高山镜像中添加这些包。我会排除一个代码问题,因为ubuntu版本可以工作。
有什么想法,可能会遗漏什么?我也很乐意了解如何自己比较这些包,但在ubuntu和alpine中,包的名称是不一样的,所以我发现很难弄清楚这一点。
发布于 2020-11-17 09:54:05
您应该使用multi-stage build将其分解。在您现在正在构建的映像中,最终的映像包含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实现存在有据可查的库兼容性问题。
https://stackoverflow.com/questions/64866563
复制相似问题