Docker Deployment for remote docker server
2.0K
Secure & Reliable Container Deployment
Extension of docker-remote
This solution provides automated, production-grade Docker container deployment with comprehensive health monitoring and logging. It's designed for secure operations in remote Docker environments with full visibility into the deployment process.
Important Risk Notice:
This deployment strategy follows a replace-in-place pattern. If the deployment fails after stopping existing containers but before successfully starting new ones:
Mitigation Strategies:
For reliable deployment management, always explicitly name your services in both the Docker Compose file and container configurations:
services:
web-app:
container_name: web-app-prod # Explicit container naming
image: my-registry/web-app:1.2.3
restart: unless-stopped
database:
container_name: db-primary
image: postgres:14.1
Before deployment, ensure:
/etc/docker/certs.d| Variable | Description | Required | Default | Example Value |
|---|---|---|---|---|
DOCKER_REMOTE_IP_ADDRESS | IP address of the Docker remote server | Yes | - | 192.168.1.100 |
DOCKER_REGISTRY_HOST | Docker registry hostname | Yes | - | my-registry.example.com |
DOCKER_COMPOSE_FILE | Absolute path to Docker Compose file in container | Yes | - | /opt/docker-compose.yml |
DOCKER_REMOTE_HOSTNAME | Hostname of Docker remote server | Yes | - | docker-prod-01 |
DOCKER_HOST | Docker daemon connection string | No | tcp://${DOCKER_REMOTE_HOSTNAME}:2376 | tcp://docker-remote:2376 |
TIMEOUT | Health check timeout in seconds | No | 300 | 600 |
FORCE | Force container recreation (true/false) | No | false | true |
docker run --rm --name docker-deployment \
-e DOCKER_REMOTE_IP_ADDRESS="172.16.0.10" \
-e DOCKER_REGISTRY_HOST="registry.example.com" \
-e DOCKER_COMPOSE_FILE=/opt/docker-compose.yml \
-e DOCKER_REMOTE_HOSTNAME="docker-prod" \
-e TIMEOUT="600" \
-e FORCE="true" \
-v "${HOME}/docker/certs.d:/etc/docker/certs.d" \
-v "./deployment/docker-compose.yml:/opt/docker-compose.yml" \
eliasmeireles/docker-deployment:latest
graph TD
A[Start Deployment] --> B[Validate Environment Variables]
B --> C[Update /etc/hosts]
C --> D[Log Compose File Contents]
D --> E{Force Recreate?}
E -->|Yes| F[Compose Up with Force]
E -->|No| G[Compose Up Normal]
F --> H[Get Container List]
G --> H
H --> I[Health Check Loop]
I --> J{All Healthy?}
J -->|Yes| K[Output Logs]
J -->|No| L{Timeout Reached?}
L -->|Yes| M[Fail Deployment]
L -->|No| I
K --> N[Successful Deployment]

Connection Failures:
Health Check Timeouts:
Image Pull Errors:
For services requiring custom health checks, add to your compose file:
services:
my-app:
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8080/health" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 5s
After deployment completes:
image: my-app:1.2.3)Post-deployment, immediately verify:
docker ps -adocker statsFor issues not covered in this documentation, please open an issue on GitHub.
Content type
Image
Digest
sha256:9a18fcbf8…
Size
367.3 MB
Last updated
over 1 year ago
docker pull eliasmeireles/docker-deployment