|
| 1 | +#==============================================================# |
| 2 | +# File : Dockerfile |
| 3 | +# Desc : Pigsty Docker Image based on Debian 13 (Trixie) |
| 4 | +# Ctime : 2026-01-27 |
| 5 | +# Mtime : 2026-01-27 |
| 6 | +# License : Apache-2.0 @ https://pigsty.io/docs/about/license |
| 7 | +# Copyright : 2018-2026 Ruohang Feng / Vonng (rh@vonng.com) |
| 8 | +#==============================================================# |
| 9 | +# |
| 10 | +# Two build targets available: |
| 11 | +# |
| 12 | +# base: Pigsty initialized, ready for ./configure && ./deploy.yml |
| 13 | +# full: Pigsty fully deployed, ready to use out of the box |
| 14 | +# |
| 15 | +# Build Commands: |
| 16 | +# docker build -t pigsty:v4.0.0 . # base |
| 17 | +# docker build --target full -t pigsty-full:v4.0.0 . # full |
| 18 | +# |
| 19 | +# Run Command: |
| 20 | +# docker run -d --privileged --name pigsty \ |
| 21 | +# --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ |
| 22 | +# -p 2222:22 -p 8080:80 -p 5432:5432 pigsty:v4.0.0 |
| 23 | +# |
| 24 | +#==============================================================# |
| 25 | + |
| 26 | + |
| 27 | +#--------------------------------------------------------------# |
| 28 | +# Stage 1: Base Image |
| 29 | +#--------------------------------------------------------------# |
| 30 | +# This stage creates a ready-to-deploy Pigsty environment: |
| 31 | +# - Debian 13 (Trixie) with SystemD enabled |
| 32 | +# - SSH server configured (root:pigsty) |
| 33 | +# - pig CLI installed, pigsty source initialized |
| 34 | +# - Ansible and dependencies installed via `pig sty boot` |
| 35 | +# - Default docker config template applied |
| 36 | +# |
| 37 | +# After running this image, execute: |
| 38 | +# ./configure -c docker -i 127.0.0.1 |
| 39 | +# ./deploy.yml |
| 40 | +#--------------------------------------------------------------# |
| 41 | +FROM debian:trixie AS base |
| 42 | + |
| 43 | +LABEL maintainer="Ruohang Feng <rh@vonng.com>" |
| 44 | +LABEL org.opencontainers.image.title="Pigsty" |
| 45 | +LABEL org.opencontainers.image.description="Battery-Included PostgreSQL Distribution" |
| 46 | +LABEL org.opencontainers.image.url="https://pigsty.io" |
| 47 | +LABEL org.opencontainers.image.source="https://github.com/pgsty/pigsty" |
| 48 | +LABEL org.opencontainers.image.version="4.0.0" |
| 49 | + |
| 50 | +ENV container=docker \ |
| 51 | + DEBIAN_FRONTEND=noninteractive \ |
| 52 | + TZ=Asia/Shanghai \ |
| 53 | + LANG=en_US.UTF-8 \ |
| 54 | + LC_ALL=en_US.UTF-8 \ |
| 55 | + PIGSTY_VERSION=v4.0.0 |
| 56 | + |
| 57 | +#--------------------------------------------------------------# |
| 58 | +# Install SystemD and essential packages |
| 59 | +#--------------------------------------------------------------# |
| 60 | +# Core: systemd, dbus (required for systemd in container) |
| 61 | +# SSH: openssh-server/client, sudo |
| 62 | +# I18N: locales, ca-certificates |
| 63 | +# Tool: curl, wget, vim, git, jq, lz4, unzip, bzip2, pv |
| 64 | +# make, patch, bash, lsof, rsync, ncdu |
| 65 | +# Net: procps, iproute2, net-tools, iputils-ping |
| 66 | +# Python: python3 (required by ansible, pip/venv not needed with uv) |
| 67 | +#--------------------------------------------------------------# |
| 68 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 69 | + systemd systemd-sysv dbus dbus-user-session \ |
| 70 | + openssh-server openssh-client sudo \ |
| 71 | + locales ca-certificates curl wget \ |
| 72 | + vim git jq lz4 make bash lsof rsync ncdu \ |
| 73 | + python3 procps iproute2 net-tools iputils-ping \ |
| 74 | + && apt-get clean \ |
| 75 | + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
| 76 | + |
| 77 | +#--------------------------------------------------------------# |
| 78 | +# Configure SystemD for container environment |
| 79 | +#--------------------------------------------------------------# |
| 80 | +# Remove unnecessary systemd units that don't work in containers |
| 81 | +# Keep only essential services for a minimal bootable system |
| 82 | +#--------------------------------------------------------------# |
| 83 | +RUN cd /lib/systemd/system/sysinit.target.wants/ \ |
| 84 | + && rm -f $(ls | grep -v systemd-tmpfiles-setup) \ |
| 85 | + && rm -f /lib/systemd/system/multi-user.target.wants/* \ |
| 86 | + && rm -f /etc/systemd/system/*.wants/* \ |
| 87 | + && rm -f /lib/systemd/system/local-fs.target.wants/* \ |
| 88 | + && rm -f /lib/systemd/system/sockets.target.wants/*udev* \ |
| 89 | + && rm -f /lib/systemd/system/sockets.target.wants/*initctl* \ |
| 90 | + && rm -f /lib/systemd/system/basic.target.wants/* \ |
| 91 | + && rm -f /lib/systemd/system/anaconda.target.wants/* \ |
| 92 | + && rm -f /lib/systemd/system/plymouth* \ |
| 93 | + && rm -f /lib/systemd/system/systemd-update-utmp* \ |
| 94 | + && systemctl set-default multi-user.target |
| 95 | + |
| 96 | +RUN systemctl mask \ |
| 97 | + dev-hugepages.mount \ |
| 98 | + sys-fs-fuse-connections.mount \ |
| 99 | + systemd-update-utmp.service \ |
| 100 | + systemd-tmpfiles-setup.service \ |
| 101 | + console-getty.service |
| 102 | + |
| 103 | +#--------------------------------------------------------------# |
| 104 | +# Configure locale, timezone, SSH, sudo |
| 105 | +#--------------------------------------------------------------# |
| 106 | +RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \ |
| 107 | + && locale-gen en_US.UTF-8 \ |
| 108 | + && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \ |
| 109 | + && echo "${TZ}" > /etc/timezone |
| 110 | + |
| 111 | +RUN mkdir -p /run/sshd /root/.ssh \ |
| 112 | + && chmod 700 /root/.ssh \ |
| 113 | + && ssh-keygen -A \ |
| 114 | + && sed -i 's/#\?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config \ |
| 115 | + && sed -i 's/#\?PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config \ |
| 116 | + && systemctl enable ssh |
| 117 | + |
| 118 | +RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/nopasswd \ |
| 119 | + && chmod 440 /etc/sudoers.d/nopasswd |
| 120 | + |
| 121 | +RUN echo 'root:pigsty' | chpasswd |
| 122 | + |
| 123 | +#--------------------------------------------------------------# |
| 124 | +# Install pig CLI from Pigsty APT repository |
| 125 | +#--------------------------------------------------------------# |
| 126 | +RUN echo "deb [trusted=yes] https://repo.pigsty.cc/apt/infra/ generic main" \ |
| 127 | + > /etc/apt/sources.list.d/pigsty.list \ |
| 128 | + && apt-get update \ |
| 129 | + && apt-get install -y --no-install-recommends pig \ |
| 130 | + && apt-get clean \ |
| 131 | + && rm -rf /var/lib/apt/lists/* |
| 132 | + |
| 133 | +#--------------------------------------------------------------# |
| 134 | +# Initialize Pigsty with pig CLI |
| 135 | +#--------------------------------------------------------------# |
| 136 | +# pig sty init: download and extract pigsty source to ~/pigsty |
| 137 | +# pig sty boot: install ansible and python dependencies |
| 138 | +# cp docker.yml: use docker config template as default config |
| 139 | +#--------------------------------------------------------------# |
| 140 | +RUN pig sty init -v ${PIGSTY_VERSION} \ |
| 141 | + && pig sty boot \ |
| 142 | + && pig sty conf -c docker -i 127.0.0.1 |
| 143 | + |
| 144 | +# Enable profile.d scripts in interactive bash sessions |
| 145 | +RUN printf '\n# Load /etc/profile.d scripts\nif [ -d /etc/profile.d ]; then\n for i in /etc/profile.d/*.sh; do\n if [ -r "$i" ]; then\n . "$i"\n fi\n done\nfi\n' >> /root/.bashrc |
| 146 | + |
| 147 | +#--------------------------------------------------------------# |
| 148 | +# Finalize base image |
| 149 | +#--------------------------------------------------------------# |
| 150 | +RUN mkdir -p /data |
| 151 | +WORKDIR /root/pigsty |
| 152 | +VOLUME ["/sys/fs/cgroup", "/data"] |
| 153 | + |
| 154 | +# Ports: 22=SSH, 80=HTTP, 443=HTTPS, 5432=PostgreSQL |
| 155 | +# Web services (Grafana, etc.) accessed via Nginx reverse proxy |
| 156 | +EXPOSE 22 80 443 5432 |
| 157 | + |
| 158 | +STOPSIGNAL SIGRTMIN+3 |
| 159 | +CMD ["/lib/systemd/systemd"] |
| 160 | + |
| 161 | + |
| 162 | +#--------------------------------------------------------------# |
| 163 | +# Stage 2: Full Image (fully deployed) |
| 164 | +#--------------------------------------------------------------# |
| 165 | +# This stage extends base with a complete Pigsty deployment: |
| 166 | +# - Runs ./configure -c docker -g -i 127.0.0.1 |
| 167 | +# - Runs ./deploy.yml to deploy INFRA + ETCD + PGSQL |
| 168 | +# - PostgreSQL 18 running with default databases/users |
| 169 | +# - Grafana, VictoriaMetrics, Nginx, etc. all configured |
| 170 | +# |
| 171 | +# Use this image for quick demos or testing. Not recommended |
| 172 | +# for production due to large image size and fixed config. |
| 173 | +# |
| 174 | +# Note: Uses ansible local connection (-c local) since SSH |
| 175 | +# is not available during docker build (systemd not running) |
| 176 | +#--------------------------------------------------------------# |
| 177 | +FROM base AS full |
| 178 | + |
| 179 | +# Configure with random passwords and deploy using local connection |
| 180 | +# -c local: use local connection instead of SSH (no systemd during build) |
| 181 | +RUN cd /root/pigsty \ |
| 182 | + && pig sty conf -c docker -g -i 127.0.0.1 \ |
| 183 | + && ./deploy.yml -c local |
0 commit comments