Skip to main content

Command Palette

Search for a command to run...

Deploying docker-compose the easy way, without registry or scp

Updated
Deploying docker-compose the easy way, without registry or scp
T

Thomas Schühly’s server-side rendering journey started as a developer trying to make life easier while developing his first bootstrapped product in his free time. Creating Spring ViewComponent enabled him to be the youngest Speaker at the largest European Spring conference and build awesome software full-time with his open-source library at alanda.io. He regularly talks at Java User Groups about htmx and server-side rendering with Spring while contributing to the open-source community. PhotoQuest

Ever wondered how you can deploy your locally running docker-compose project to a remote server? There are several options:

  1. Pushing the images to a container registry like dockerhub, github container registry and pulling them onto your server

  2. Saving the images to a .tar archive and copying it over to your server and loading them there is explained here

There is an easier way using docker remote host:

The only thing you have to make sure is to install docker, docker-compose onto your server and have a valid SSH key

docker-compose.yml

version: '3.9'
services:
  backend:
    build: spring-backend
    container_name: spring-backend
    image: spring-backend:0.0.1
    expose:
      - "8088"
  frontend:
    build: angular-frontend
    image: angular-frontend:0.0.1
    container_name: angular-frontend
    ports:
      - 80:80
    depends_on:
      - backend
    command: [nginx-debug, '-g', 'daemon off;']

deploy.sh

#!/bin/bash

docker-compose build

for img in $(docker-compose config | awk '{if ($1 == "image:") print $2;}'); do
  images="$images $img"
done

echo $images


docker image save $images | docker -H "ssh://user@serverIp" image load
docker-compose -H "ssh://user@serverIp" up --force-recreate -d
docker-compose -H "ssh://user@serverIp" logs -f
read -p "Press any key to continue... " -n1 -s

With a simple deploy.sh you can build your current state, load them onto your server, run them, and attach to the output.

If you want to learn more about HTMX + Spring Boot check out my series Web development without the JavaScript headache with Spring + HTMX.

My side business PhotoQuest is also built with HTMX + JTE

More from this blog

Thomas Schilling | Spring/HTMX/Claude Code

22 posts

Youngest Speaker @Spring I/O & Spring ViewComponent creator.

Passionate about building awesome software with Spring + HTMX. Pushing full-stack development with Spring forward.