chevron-right What this guide includes:hashtag Detailed repo structure with required files for .deb, .rpm, and Arch packages.
Exact example scripts for Docker container lifecycle management.
Systemd service unit for container automatic startup/control.
Debian and RPM packaging metadata and maintainer scripts.
Arch PKGBUILD file with build/install steps.
Hosting repository server setup, HTTPS, and Let’s Encrypt for SSL.
GPG key generation, exporting, signing repository metadata, and client key configuration.
User installation commands for apt, dnf, and pacman.
Complete GitHub Actions and GitLab CI/CD workflows for Docker images and Linux packages.
chevron-right What might be missing or assumed:hashtag Some basic Docker skills (writing a Dockerfile) are assumed before packaging.
Basic Linux command line and shell scripting knowledge.
Details on deployment environments, infrastructure for hosting repos, and how to provision that hardware or cloud VM.
Advanced package signing practices for very secure environments.
How to test installation in clean VMs/containers with specific examples.
Handling multi-architecture builds and cross-building packages.
More in-depth security best practices beyond GPG.
Recommendations for true beginners:
Learn Docker basics separately if unfamiliar.
Familiarize with Linux package management basics on your target distros.
Practice writing Dockerfiles and building images locally.
Set up a simple web server with HTTPS and practice hosting static files.
Read introductory guides on GPG usage, key management, and secure shell scripting.
Step 1: Organize Your Repository Structure
Copy mydockerapp/
├── DEBIAN/ # Debian packaging files
│ ├── control # Package metadata and dependencies
│ ├── postinst # Post-install script pulling docker image, enabling service
│ ├── prerm # Pre-removal script stopping service & container
│ └── postrm # Optional cleanup script
├── rpm/ # RPM packaging files (Fedora, Amazon Linux, CentOS)
│ └── mydockerapp.spec # Spec file for RPM packaging
├── pacman/ # Arch packaging files
│ └── PKGBUILD # Arch package build script
├── usr/local/bin/
│ └── mydockerapp # Executable script to manage Docker container lifecycle
├── etc/systemd/system/
│ └── mydockerapp.service # systemd service unit managing the Docker container lifecycle
├── opt/mydockerapp/
│ ├── README.md # Documentation
│ └── docker-compose.yml # Optional docker-compose file
├── .github/workflows/
│ ├── build-and-push-image.yml # GitHub Actions (Docker image)
│ └── build-packages.yml # GitHub Actions (Linux packages)
├── .gitlab-ci.yml # Optional GitLab CI/CD config
├── LICENSE
└── README.md Step 2: Docker Management Script (Executable)
usr/local/bin/mydockerapp
Step 3: systemd Service Unit
etc/systemd/system/mydockerapp.service
Step 4: Debian Packaging Files
Make executable: chmod +x DEBIAN/*
Step 5: RPM Packaging Files
rpm/mydockerapp.spec
Step 6: Arch Linux PKGBUILD Example
pacman/PKGBUILD
Build with:
Step 7. Package Repository Setup and GPG Key Management Guide
Prerequisite: Install GPG on Client Machines
Before clients can import and verify your repository’s GPG key, they must have GPG installed:
Install Web Server Software on the public-facing linux server
Install Nginx or Apache2 to serve your package repositories:
Open Firewall Ports for HTTP/HTTPS
Create Repository Directory and Set Permissions
Based on your web server:
Apache default: /var/www/html/repo/
Nginx default: /usr/share/nginx/html/repo/
Create directory and set ownership:
Install Repository Management Tools
Generate GPG Key on the Server
If you haven’t created a GPG key yet, generate one now:
List keys and get your key ID:
Export and Publish Your GPG Public Key for Clients
Export your public key as ASCII armor file for client download:
Also create a de-armored binary version for server use, if needed:
Configure Repository Manager to Use GPG for Signing Packages
Create conf/distributions file in your APT repository directory:
Add and sign packages:
For RPM repositories:
Configure the Web Server to Serve Your Repository
Nginx configuration at /etc/nginx/conf.d/repo.conf :
Test and reload Nginx:
Apache configuration at /etc/apache2/sites-available/repo.conf :
Enable site and restart Apache:
Client Configuration for Multiple Linux Distributions
Verify GPG Availability (Usually Preinstalled)
Most Linux distributions include GPG by default. Verify GPG is available by running:
If this command errors, manually install GPG with your package manager:
This step is generally unnecessary on modern systems.
Import the Repository's Public GPG Key
Download the public key from the repository server and import it for package verification.
Debian/Ubuntu (APT)
Create a source list file /etc/apt/sources.list.d/yourrepo.list:
Update package cache and install packages:
RHEL/CentOS/Fedora (YUM/DNF)
Create a repo file /etc/yum.repos.d/yourrepo.repo:
Clean metadata cache and install packages:
Or on Fedora with dnf:
Arch Linux (Pacman)
Add the repository to /etc/pacman.conf:
Update package database and install:
Verify Package Installation
After configuration, you can verify package installation and trust:
Check package signature verification errors (APT/YUM/DNF/Pacman handle this automatically if configured).
Use standard package manager commands to confirm package is correctly installed.
Step 8: User Installation Commands
APT:
DNF/YUM:
Pacman:
Step 9: Automate with GitHub Actions
.github/workflows/build-and-push-image.yml
.github/workflows/build-packages.yml
Step 10: Automate with GitLab CI/CD (Optional)
.gitlab-ci.yml
Final Tips for Beginners
Use chmod +x on all scripts.
Use Let’s Encrypt SSL for hosting repos securely.
Keep GPG private keys secure and only distribute the public key.
Test your packages by installing on clean virtual machines.
Use GitHub/GitLab secrets for storing tokens securely.
Provide clear documentation in your repository’s README.
Last updated 5 months ago