Going to deploy single Docker container to remote server.
Good for all sorts of small projects and pages, like this blog :)
.gitlab-ci.yml file in project root
Deploy script explained line by line
# SSH into server, run last argument as command and disconnect
ssh -t [email protected] ""
# From remote server login into Gitlab registry
# how to get and setup deploy tokens
"docker login -u "$CI_DEPLOY_USER" -p "$CI_DEPLOY_PASSWORD" $CI_REGISTRY"
# Pull new Docker image
docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG &&
# Stop and remove existing container, use ";" instead of &&
# since server does not have this container when deploying first time
docker stop example-name; docker rm example-name;
# Start container in background, expose port 80 to 31227 and name it
docker run -d -p 31227:80 --name example-name $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
Basic Nginx server block for web services
Really basic server block is needed to proxy traffic to Docker container
Location of it is based on your host operating system. For most Debian based OSes it is
/etc/nginx/sites_available/example.com.conf and linked to
For OpenSUSE it is
It does not do any GZIP / caching / certing etc. But it is really easy to enable, based on server block on host machine.
Will write another short post about it in future