Packaging and Automation of Docker Linux Apps
Step 1: Organize Your Repository Structure
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.mdStep 2: Docker Management Script (Executable)
usr/local/bin/mydockerapp
Step 3: systemd Service Unit
etc/systemd/system/mydockerapp.service
Step 4: Debian Packaging Files
DEBIAN/control
DEBIAN/postinst
DEBIAN/prerm
Optional
DEBIAN/postrm
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:
Debian/Ubuntu clients:
RHEL/CentOS clients:
SUSE/OpenSUSE clients:
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:
Debian/Ubuntu:
RHEL/CentOS/Fedora:
Arch Linux:
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:
RHEL/CentOS/Fedora:
Arch Linux:
Configure the Package Manager to Use Your Repository
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 +xon 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.
References
Last updated