I needed to be able to push an image from my CI/CD server. Before I was using docker-hub to host my images and wanted to streamline the process. I would build my code >> build my image >> push to docker-hub >> have my server download the new image from docker-hub >> than update / restart container.
Now:
- CI/CD Build
- Push image to Remote Server
- Stop container / Restart
Things needed:
Docker
Python / PIP
SSH Key
docker-push-ssh (https://github.com/brthor/docker-push-ssh)
Assuming you have docker and python installed, and you have have setup ssh for key access.
Setup docker-push-ssh
0 1 2 |
<code>sudo -H pip install docker-push-ssh</code> |
I followed the guide to add an insecure registry to docker for linux.
0 1 2 3 4 5 6 |
<code>// /etc/docker/daemon.json { "insecure-registries" : [ "localhost:5000" ] }</code> |
0 1 2 3 |
<code>sudo systemctl daemon-reload sudo systemctl restart docker</code> |
Build a test image
Dockerfile
0 1 2 3 4 5 |
<code># vi Dockerfile FROM alpine RUN touch /etc/testimage</code> |
0 1 2 |
<code>docker build -t testimage .</code> |
Push image to remote server
0 1 2 |
<code>docker-push-ssh -i ~/.ssh/id_rsa username@host_ip_or_name testimage</code> |
Fin.
Useful Commands
0 1 2 3 4 5 6 7 8 9 10 11 12 |
<code># list images docker images # list all containers docker ps -a # force remove image docker rmi -f image_id # remove container docker rm container_id</code> |