tiangolo / dockerswarm.rocks

Docker Swarm mode rocks! Ideas, tools and recipes. Get a production-ready, distributed, HTTPS served, cluster in minutes, not weeks.
https://dockerswarm.rocks/
1.09k stars 126 forks source link

Question on GitLab deployment #61

Closed jamesthesken closed 9 months ago

jamesthesken commented 3 years ago

Hi @tiangolo thank you for this guide, I've gotten a lot better at Docker configurations since reading it!

On the page, GitLab CI runner for CI/CD, I can't get the deploy stage to work for my stack. The build stage works fine, however I receive the error:

this node is not a swarm manager. Use "docker swarm init" or "docker swarm join"
to connect this node to swarm and try again

My .gitlab-ci.yml:

image: docker:19.03.12

services:
    - docker:19.03.12-dind

before_script:
  - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
  - export IMAGE_NAME=$CI_REGISTRY_IMAGE:latest

variables:
    IMAGE_NAME: $CI_REGISTRY_IMAGE:latest

stages:
  - build
  - deploy

build-prod:
  stage: build
  script:
    - cd ./frontend
    - docker build -t $IMAGE_NAME -f Dockerfile.prod .
    - docker push $IMAGE_NAME
  only:
    - nextjs

deploy-prod:
  stage: deploy
  script:
    - docker stack deploy -c nextjs.yml --with-registry-auth nextjs
  only:
    - nextjs

Would it help by using your image, tiangolo/docker-with-compose? Thank you for your help.

jamesthesken commented 3 years ago

Hi @tiangolo , any thoughts?

dorinclisu commented 3 years ago

The CI config uses the docker-in-docker service (docker:19.03.12-dind), which is highly recommended against BTW.

What it means in your case is that any docker commands will get serviced by the inner docker daemon, which is independent and has nothing to do with the outer daemon (the swarm master), hence the error.

If you installed the runner per instructions (and /var/run/docker.sock is bind mounted) then you should simply remove the dind service from the CI yaml and it will probably work.

jamesthesken commented 3 years ago

Hey @dorinclisu thank you for your reply, I was feeling like I couldn't get past this hurdle. I'll give that a try and report back.

Which CI yaml are you referring to? I don't see docker-in-docker service on this page: https://dockerswarm.rocks/gitlab-ci/

dorinclisu commented 3 years ago
services:
    - docker:19.03.12-dind

This is the service I'm talking about, defined in your .gitlab-ci.yml. Delete that.

derek-mba commented 1 year ago

The CI config uses the docker-in-docker service (docker:19.03.12-dind), which is highly recommended against BTW.

Unfortunately, it is not "highly recommended against" by GitLab

If you installed the runner per instructions (and /var/run/docker.sock is bind mounted) then you should simply remove the dind service from the CI yaml and it will probably work.

If you installed the runner "per instructions" you probably are running the docker-in-docker service! It does mention socket binding, but there's a note "If you bind the Docker socket and you are using GitLab Runner 11.11 or later, you can no longer use docker:20.10.16-dind as a service.", which seems to imply this is a bad thing. Having now read your reference, I can see I have zero need for the dind service, but I sure wish GitLab would make that clear.

tiangolo commented 10 months ago

Thanks for the patience!

I should let you know, that I had to deprecate this website and ideas, I would no longer recommend Docker Swarm Mode for new projects: https://dockerswarm.rocks/swarm-or-kubernetes/ 🥲

github-actions[bot] commented 9 months ago

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

HongQuan195 commented 4 months ago

have same issue. here is my ci pipeline. Build stage is fine but deploy get issue related to swarm master node. I remove services as [dorinclisu] recommend but still not working. It stuck in curl -kvv step .gitlab-ci.yml

variables:

before_script:

stages:

include:

script/ci-build.yml

BUILD: stage: build image: docker:dind tags:

script/ci-staging.yml STA - DEPLOY: stage: deploy image: docker:dind tags:

HongQuan195 commented 4 months ago

this node is not a swarm manager. Use "docker swarm init"

Hi @dorinclisu @tiangolo have any suggest for this problem?