I want to deploy a docker stack on my own server. I've written a .gitlab-ci.yml file that currently builds the images in my stack and pushes them to my gitlab registry:
build:
stage: build
image: docker:stable
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker info
script:
- docker build -t $DOCKER_IMAGE1_TAG -f dir1/Dockerfile ./dir1
- docker push $DOCKER_IMAGE1_TAG
- docker build -t $DOCKER_IMAGE2_TAG -f dir2/Dockerfile ./dir2
- docker push $DOCKER_IMAGE2_TAG
I'm struggling for a way to run the docker deploy command on my own server with the docker-compose.yml file I've written, that successfully pulls the images from my gitlab registry. I figure I could use sshpass to ssh into my server and then copy the docker-compose.yml file across and run docker deploy from there, but I'm not sure what's the best way to allow my server to access the images now located in my gitlab registry:
# Need to ssh into the server, transfer over docker-stack file and run docker swarm deploy
deploy:
stage: deploy
environment:
name: production
image: trion/ng-cli-karma
before_script:
- apt-get update -qq && apt-get install -y -qq sshpass
- eval $(ssh-agent -s)
This is a section of my docker-compse file:
version: "3.2"
services:
octeditor:
image: image # how to set this to the image in my container registry?
ports:
- "3000:3000"
networks:
- front-tier
deploy:
replicas: 1
update_config:
parallelism: 1
failure_action: rollback
placement:
constraints:
- 'node.role == manager'
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
How can I pull the images from my gitlab registry? Is this the preferred way of creating a docker deployment on a remote server, via gitlab ci?
I equally had this difficulty recently, finally I found out that the solution is just to insert the link to the image in the private registry as is the case for me with gitlab.
version: "3.2"
services:
octeditor:
image: registry.gitlab.com/project-or-group/project-name/image-name:tag
ports:
- "3000:3000"
networks:
- front-tier
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With