0

I am trying to rewrite a Dockerfile (https://github.com/orangefoil/rcssserver-docker/blob/master/Dockerfile) so that it uses alpine instead of ubuntu. Goal is to reduce the file size.

In the original image the robocup soccer server is built from scratch using g++, flex, bison, etc.

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

I tried to do the same on alpine and had to exchange some packages:

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

Unfortunately, my version doesn't work yet. It fails with

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

From what I found so far, this can happen, if dev packages are not installed (see ld cannot find an existing library), but I changed to dev packages where I could find them and still no luck.

So, my current assumption is that ubuntu has some package installed, that I need to add in my alpine image. I would exclude a code problem, since the ubuntu version works.

Any ideas, what could be missing? I would also be happy to understand how to compare the packages myself, but the package namings are not the same in ubuntu and alpine, so I find it pretty hard to figure this out.

grackkle
  • 776
  • 1
  • 9
  • 26

1 Answers1

1

You should break this up using a multi-stage build. In the image you're building now, the final image contains the C toolchain and all of the development libraries and headers that those -dev packages install; you don't need any of those to actually run the built application. The basic idea is to build the application exactly as you have it now, but then COPY only the built application into a new image with fewer dependencies.

This would look something like this (untested):

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

Compared to the size of the C toolchain, header files, and build-time libraries, the difference between an Alpine and Ubuntu image is pretty small, and Alpine has well-documented library compatibility issues with its minimal libc implementation.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • So you would suggest to drop the alpine idea and directly go with ubuntu? In that case, I can stick directly with https://github.com/orangefoil/rcssserver-docker/blob/master/Dockerfile, since this is a multi-stage build already. – grackkle Nov 17 '20 at 08:32
  • I accepted the answer for 2 reasons: * The compatibility reasons that are probably at work here * The fact that ubuntu for docker is actually ubuntu-minimal right now, which is not massively so different from alpine (still slightly bigger but not relevant). – grackkle Nov 18 '20 at 14:14