1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00
dragonflydb-dragonfly/tools/packaging/Dockerfile.alpine-dev
Roman Gershman cec3659b51
fix: named volume permissions in docker (#3518)
Fixes #2917

The problem is described in this "working as intended" issue https://github.com/moby/moby/issues/3124
So the advised approach of using "USER dfly" directive does not really work because it requires
that the host will also define 'dfly' user with the same id. It's unrealistic expectation.

Therefore, we revert the fix done in #1775 and follow valkey approach:
https://github.com/valkey-io/valkey-container/blob/mainline/docker-entrypoint.sh#L12

1. we run the entrypoint in the container as root which later spawns the dragonfly process
2. if we run as root:
   a. we chmod files under /data to dfly.
   b. use setpriv to exec ourselves as dfly.
3. if we do not run as root we execute the docker command.

So even though the process starts as root, the server runs as dfly and only the bootstrap
part has elevated permissions is used to fix the volume access.

While we are at it, we also switched to setpriv following the change of https://github.com/valkey-io/valkey-container/pull/24/files

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-08-22 11:33:29 +03:00

46 lines
1.4 KiB
Text

# syntax=docker/dockerfile:1
FROM gcr.io/cadvisor/cadvisor:v0.46.0 as libpfm_donor
FROM alpine:3 as builder
# "openssl-libs-static" fixes "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the"
RUN apk add autoconf-archive automake bash bison boost-dev cmake coreutils net-tools \
curl ccache git gcc gdb g++ libunwind-dev libtool make ninja \
openssl-dev openssl-libs-static patch zip zstd-static
# This is required to make static linking work
RUN ls -1 /usr/lib/libboost_*.so | while read -r _file; do ln -sfv ${_file} ${_file//.so/.a}; done
# Borrow libpfm from cadvisor, so we don't have to build it ourselves
# https://github.com/google/cadvisor/blob/master/deploy/Dockerfile
COPY --from=libpfm_donor /usr/local/lib/libpfm.so* /usr/local/lib/
WORKDIR /build
COPY . ./
RUN make release
RUN build-release/dragonfly --version
FROM alpine:3
COPY tools/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY tools/docker/healthcheck.sh /usr/local/bin/healthcheck.sh
COPY --from=builder /build/build-release/dragonfly /usr/local/bin/
RUN apk --no-cache add libgcc libstdc++ \
setpriv netcat-openbsd boost-context && ldd /usr/local/bin/dragonfly
RUN addgroup -S -g 1000 dfly && adduser -S -G dfly -u 999 dfly
RUN mkdir /data && chown dfly:dfly /data
VOLUME /data
WORKDIR /data
HEALTHCHECK CMD /usr/local/bin/healthcheck.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 6379
CMD ["dragonfly", "--logtostderr"]