I needed to spin up services on a remote docker instance; Configure the services and have them running in a minute. I plan to put up a full write-up once I have everything running smoothly… these are just the begining stages to get some processes functioning.
This is the solution I came up with for simply pushing to the remote registry without any fussing with ssl.
This assumes you are fully firewalled (except for port 22) and have ssh tunneling available on the REMOTE side.
Test and build your image on LOCAL. Tag it with the localhost address and registry port (127.0.0.1:5000/)
docker tag imagename:version 127.0.0.1:5000/imagename:version
If a registry is not already running on REMOTE, use something like:
ssh username@remotedocker docker run -d -p 5000:5000 --restart=always --name registry -v /mnt/registry:/var/lib/registry registry:2
Then bind the tunnel from LOCAL to REMOTE:
ssh -L 127.0.0.1:5000:127.0.0.1:5000 username@remotedocker
To run in the background use -fN ### must kill manually ps -ef | grep ssh then kill pid
ssh -L -fN 127.0.0.1:5000:127.0.0.1:5000 username@remotedocker
To connect for a short period and avoid fiddling wiht manually killing the process send a sleep command to hold it open. This works great for scripts that may only need a few seconds to send something.
ssh -L -f 127.0.0.1:5000:127.0.0.1:5000 username@remotedocker sleep 120
To push your LOCAL image to the REMOTE registry, run the docker push command:
docker push 127.0.0.1:5000/imagename:version
This should push your image through the LOCAL port to the REMOTE host’s registry.
Then run commands to deploy to the stack (git the stack.yml/docker-compose.yml on REMOTE and ‘docker stack deploy’…)
ssh username@remotedocker git clone blahblah.git ssh username@remotedocker cd blahblah && docker stack deploy -c stack.yml servicename
ssh username@remotedocker docker run -d --name imagename-version 127.0.0.1:5000/imagename:version