DEV Community

Cover image for Deploying docker-compose the easy way, without registry or scp
Thomas Schühly
Thomas Schühly

Posted on

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

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 on your server
  2. Saving the images to a .tar archive and copying it over to your server and loading them there explained here

There is a 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


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

Enter fullscreen mode Exit fullscreen mode


docker-compose build

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

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

Enter fullscreen mode Exit fullscreen mode

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

Top comments (1)

fasihi01 profile image

Hi this is great, but i was running into the following errors:
ERROR: Secsh channel 14 open FAILED: open failed: Connect failed

Solution: On the target host, set the MaxSessions of the sshd to something bigger then the 10-default (20 should be enough).