Docker Deployment
Pigsty is designed for native Linux, but can also run in Linux containers with systemd. If you don’t have native Linux (e.g., macOS or Windows), use Docker to spin up a local single-node Pigsty for testing.
Quick Start
Enter the docker/ dir in Pigsty source and launch with one command:
cd ~/pigsty/docker
make launch # Start container + generate config + deploy
After deployment, access services:
| Service | URL / Command | Credentials |
|---|---|---|
| SSH | ssh root@localhost -p 2222 | Password: pigsty |
| Web Portal | http://localhost:8080 | - |
| Grafana | http://localhost:8080/ui | admin / pigsty |
| PostgreSQL | psql postgres://dbuser_dba:DBUser.DBA@localhost:5432/postgres | DBUser.DBA |
Web Portal and PostgreSQL are only available after Deployment (./deploy.yml) completes.
Prepare
Docker deployment requires:
| Item | Requirement | Item | Requirement |
|---|---|---|---|
| Docker | Docker 20.10+ (Desktop or CE) | CPU | At least 1 core |
| RAM | At least 2GB | Disk | At least 20GB free |
Ensure default host ports (2222/8080/8443/5432) are available, or edit .env first.
- Quick Pigsty experience on macOS/Windows without native Linux
- Learning and testing Pigsty features, dev and debug
- Quick local PostgreSQL dev environment
- Production: Container perf and stability inferior to native Linux
- HA Clusters: Docker single-node mode can’t achieve multi-node HA
- Large Scale: Use native Linux VMs or physical machines
Image
Pigsty provides an out-of-the-box Docker image on Docker Hub.
| Image | Pull | Size | Contents |
|---|---|---|---|
pgsty/pigsty | ~500MB | 1.3GB | Debian 13 + systemd + SSH + pig + Ansible |
- Supports both amd64 (x86_64) and arm64 (Apple Silicon, AWS Graviton)
- Tags match Pigsty versions:
v4.0.0,latest, etc. - Pre-configured with docker template, ready to run
./deploy.yml
Built on Debian 13 (Trixie), pre-installed with pig CLI and Ansible, Pigsty source already initialized.
Launch
Pigsty provides out-of-the-box Docker support in the docker/ source directory.
Simplest way is make launch, which auto-completes: start container, generate config, and deploy:
cd ~/pigsty/docker
make launch # One-liner: up + config + deploy
Or step by step for inspection at each stage:
cd ~/pigsty/docker
make up # Start container
make exec # Enter container
./configure -c docker -g --ip 127.0.0.1 # Generate config (optional, pre-configured)
./deploy.yml # Execute deployment
To build locally instead of pulling from Docker Hub:
cd ~/pigsty/docker
make build # Build image locally
make launch # Start container + generate config + deploy
Config
Customize image version and port mappings via .env:
PIGSTY_VERSION=v4.0.0 # Image tag, matches Pigsty version
PIGSTY_SSH_PORT=2222 # SSH port
PIGSTY_HTTP_PORT=8080 # Nginx HTTP port
PIGSTY_HTTPS_PORT=8443 # Nginx HTTPS port
PIGSTY_PG_PORT=5432 # PostgreSQL port
Port Mapping:
| Env Var | Default | Container | Description |
|---|---|---|---|
PIGSTY_VERSION | v4.0.0 | - | Image version tag |
PIGSTY_SSH_PORT | 2222 | 22 | SSH access port |
PIGSTY_HTTP_PORT | 8080 | 80 | Nginx HTTP port |
PIGSTY_HTTPS_PORT | 8443 | 443 | Nginx HTTPS port |
PIGSTY_PG_PORT | 5432 | 5432 | PostgreSQL port |
Override via env vars if defaults are occupied:
PIGSTY_HTTP_PORT=8888 docker compose up -d
Commands
Pigsty Docker provides Makefile commands for container and image management.
Docker Compose
Recommended way to run:
make up # Start container
make down # Stop and remove container
make start # Start stopped container
make stop # Stop container
make restart # Restart container
make pull # Pull latest image
make config # Run ./configure in container
make deploy # Run ./deploy.yml in container
make launch # One-liner: up + config + deploy
Container Access
make exec # Enter container bash
make ssh # SSH into container
make log # View container logs
make status # View systemd status
make ps # View process list
make conf # View config file
make pass # View passwords in config
Image Build
make build # Build image locally
make buildnc # Build without cache
make push # Build and push multi-arch image
Image Management
make save # Export image to pigsty-<version>-<arch>.tgz
make load # Import image from tgz file
make rmi # Remove current version's pigsty image
Cleanup
make clean # Stop and remove container
make purge # Remove container and wipe data (prompts)
Manual Run
If you prefer docker run over Docker Compose:
mkdir -p ./data
docker run -d --privileged --name pigsty \
-p 2222:22 -p 8080:80 -p 5432:5432 \
-v ./data:/data \
pgsty/pigsty:v4.0.0
docker exec -it pigsty ./configure -c docker -g --ip 127.0.0.1
docker exec -it pigsty ./deploy.yml
Or use Makefile’s make run:
make run # Start with docker run
make exec # Enter container
make clean # Stop and remove container
make purge # Remove container and wipe data
How It Works
Pigsty Docker image is based on Debian 13 (Trixie) with systemd as init.
Service management inside container stays consistent with native Linux via systemctl.
Key features:
- systemd support: Full systemd for proper service management
- SSH access: Pre-configured SSH, root password is
pigsty - Privileged mode: Requires
--privilegedfor systemd - Data persistence: Via
/datavolume mount - Pre-installed: pig CLI + Ansible, Pigsty source initialized
Image build executes these init steps:
# Install pig CLI
RUN echo "deb [trusted=yes] https://repo.pigsty.io/apt/infra/ generic main" \
> /etc/apt/sources.list.d/pigsty.list \
&& apt-get update && apt-get install -y pig
# Initialize Pigsty source and install Ansible
RUN pig sty init -v ${PIGSTY_VERSION} \
&& pig sty boot \
&& pig sty conf -c docker --ip 127.0.0.1
Running ./configure with -c docker applies the Docker-optimized config template:
- Uses
127.0.0.1as default IP - Tuned for container environment
FAQ
Container won’t start
Ensure Docker is properly installed with sufficient resources. On Docker Desktop, allocate at least 2GB RAM. Check for port conflicts on 2222, 8080, 8443, 5432.
Can’t access services
Web Portal and PostgreSQL only available after deployment. Ensure ./deploy.yml finished successfully.
Use make status to check service status.
Port conflicts
Override via .env or env vars:
PIGSTY_HTTP_PORT=8888 PIGSTY_PG_PORT=5433 docker compose up -d
Data persistence
Container data mounted to ./data. To wipe and start fresh:
make purge # Remove container and wipe data (prompts)
macOS performance
On macOS with Docker Desktop, performance is worse than native Linux due to virtualization overhead. Expected—Docker deployment is for dev/testing. For production, use native Linux installation.
More
- Docker Hub: https://hub.docker.com/r/pgsty/pigsty
- Source Directory: https://github.com/pgsty/pigsty/tree/main/docker
- Quick Start: Native Linux Installation
- Offline Installation: Offline
- Production Deployment: Deployment Guide
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.