-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathDockerfile.systemd
98 lines (89 loc) · 4.43 KB
/
Dockerfile.systemd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# This Dockerfile is based upon sysbox example images: https://github.com/nestybox/dockerfiles/
# but with some modifications to have a more generic image.
ARG UBUNTU_VERSION="24.04"
FROM ubuntu:${UBUNTU_VERSION}
ARG UBUNTU_VERSION
ENV DOCKER_VERSION=27.4.1 \
DOCKER_COMPOSE_VERSION=v2.32.0 \
BUILDX_VERSION=v0.19.1
#
# Systemd installation
#
RUN apt-get update && \
apt-get install -y --no-install-recommends \
systemd \
systemd-sysv \
libsystemd0 \
ca-certificates \
dbus \
iptables \
iproute2 \
kmod \
locales \
sudo \
udev && \
\
# Prevents journald from reading kernel messages from /dev/kmsg
echo "ReadKMsg=no" >> /etc/systemd/journald.conf && \
\
# Housekeeping
apt-get clean -y && \
rm -rf \
/var/cache/debconf/* \
/var/lib/apt/lists/* \
/var/log/* \
/tmp/* \
/var/tmp/* \
/usr/share/doc/* \
/usr/share/man/* \
/usr/share/local/* && \
\
# Create default 'admin/admin' user
useradd --create-home --shell /bin/bash admin && echo "admin:admin" | chpasswd && adduser admin sudo
# Disable systemd services/units that are unnecessary within a container.
RUN systemctl mask systemd-udevd.service \
systemd-udevd-kernel.socket \
systemd-udevd-control.socket \
systemd-modules-load.service \
sys-kernel-debug.mount \
sys-kernel-tracing.mount
# Set iptables-legacy for Ubuntu 22.04 and newer
RUN set -eux; \
if [ "${UBUNTU_VERSION}" != "20.04" ]; then \
update-alternatives --set iptables /usr/sbin/iptables-legacy; \
fi
# Install Docker
RUN apt-get update && apt-get install -y wget curl \
&& rm -rf /var/lib/apt/lists/* \
&& curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh --version ${DOCKER_VERSION} \
# Add user "admin" to the Docker group
&& usermod -a -G docker admin \
&& rm get-docker.sh \
&& docker --version
# Install buildx
RUN set -eux; \
arch="$(uname -m)"; \
case "$arch" in \
x86_64) dockerArch='x86_64' ; buildx_arch='linux-amd64' ;; \
armhf) dockerArch='armel' ; buildx_arch='linux-arm-v6' ;; \
armv7) dockerArch='armhf' ; buildx_arch='linux-arm-v7' ;; \
aarch64) dockerArch='aarch64' ; buildx_arch='linux-arm64' ;; \
*) echo >&2 "error: unsupported architecture ($arch)"; exit 1 ;; \
esac && \
wget -O docker-buildx "https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.${buildx_arch}" && \
mkdir -p /usr/local/lib/docker/cli-plugins && \
chmod +x docker-buildx && \
mv docker-buildx /usr/local/lib/docker/cli-plugins/docker-buildx && \
docker buildx version
# Install Docker Compose
RUN curl --retry 5 --retry-max-time 40 \
--write-out "%{http_code}\n" \
-L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose && \
chmod 755 /usr/local/bin/docker-compose && \
mkdir -p /usr/local/lib/docker/cli-plugins && \
ln -s /usr/local/bin/docker-compose /usr/local/lib/docker/cli-plugins/docker-compose
# Make use of stopsignal (instead of sigterm) to stop systemd containers.
STOPSIGNAL SIGRTMIN+3
# Set systemd as entrypoint.
ENTRYPOINT [ "/sbin/init", "--log-level=err" ]