Solucionado (ver solução)
Solucionado
(ver solução)
40
respostas

postgres não sobe

Olá, o postgres não sobe e consequentemente o worker também não. Já tentei forçar ele a executar numa VM com mais memória, imaginando ser falta de memória, mas mesmo assim não vai. Usei o mesmo código fornecido na aula, mas sem sucesso.

40 respostas

Olá Wanderson, tudo bem?

Imagino que já tenha resolvido o seu problema. Ainda tem alguma dúvida?

Olá, ainda não. O serviço é iniciado, mas dá erro logo em seguida e fica nesse loop.

Dentro do nó que está tentando executar a tarefa, execute o comando docker image pull postgres:9.4 e diz aí se resolveu :)

Usei o mesmo código que tem para download e conferi com vídeo criado e mesmo assim não sobe, dae fiz umas alterações para tentar ver se era falta de memória e diminui o número de réplicas e mesmo assim não deu certo. Vou mostrar meu docker-compose.yml

O que ele exibe ao executar o comando docker service ps no serviço do postgres?

docker@vm5:~$ docker service ps vote_db
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE           ERROR                       PORTS
e3x8qb2r6fxl        vote_db.1           postgres:latest     vm5                 Ready               Ready 4 seconds ago                     
zunjttpumeda         \_ vote_db.1       postgres:latest     vm5                 Shutdown            Failed 4 seconds ago    "task: non-zero exit (1)"
vvnivv0mncij         \_ vote_db.1       postgres:latest     vm5                 Shutdown            Failed 10 seconds ago   "task: non-zero exit (1)"
io4qxyykzj5q         \_ vote_db.1       postgres:latest     vm5                 Shutdown            Failed 16 seconds ago   "task: non-zero exit (1)"
k01m3flyfd8g         \_ vote_db.1       postgres:latest     vm5                 Shutdown            Failed 22 seconds ago   "task: non-zero exit (1)"

Aparentemente está funcionando, o status está Ready.

O que acontece?

Olá Wanderson, tudo bem? Você poderia informar quais os comandos você executou e qual foi os resultados da execução dos mesmos, o resultado de cada comando, para gente poder entender melhor e tentar ajudar, se puder colocar prints do processo que você realizou seria muito interessante pra gente ajudar!

Segue meu docker-compose.yml

  • Eu modifiquei algumas coisas imaginando ser falta de recursos no meu host, que tem 8GB de RAM e um SSD 120GB;
  • Aumentei a RAM da VM5 para 1,5GB pra ver se o problema do DB não subir resolvia .
version: "3"
services:

  redis:
    image: redis:alpine
    networks:
      - frontend
    deploy:
      placement:
        constraints: [node.hostname == vm3]
      replicas: 1
      restart_policy:
        condition: on-failure

  db:
    image: postgres
    volumes:
      - db-data:/var/lib/postgresql/data
    networks:
      - backend
    deploy:
      placement:
        constraints: [node.hostname == vm5]

  vote:
    image: dockersamples/examplevotingapp_vote:before
    ports:
      - 5000:80
    networks:
      - frontend
    depends_on:
      - redis
    deploy:
      placement:
        constraints: [node.role == worker]
      replicas: 1
      restart_policy:
        condition: on-failure

  result:
    image: dockersamples/examplevotingapp_result:before
    ports:
      - 5001:80
    networks:
      - backend
    depends_on:
      - db
    deploy:
      placement:
        constraints: [node.role == worker]
      replicas: 1
      restart_policy:
        condition: on-failure

  worker:
    image: dockersamples/examplevotingapp_worker
    networks:
      - frontend
      - backend
    depends_on:
      - redis
    deploy:
      placement:
        constraints: [node.hostname == vm4]
      mode: replicated
      replicas: 1
      labels: [APP=VOTING]
      restart_policy:
        condition: on-failure

  visualizer:
    image: dockersamples/visualizer:stable
    ports:
      - 8080:8080
    stop_grace_period: 1m30s
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      placement:
        constraints: [node.hostname == vm1]

networks:
  frontend:
  backend:

volumes:
  db-data:

Tirei a dependência do Worker com o DB , já que ele também estava dando erro, mas não teve resultado, continua apresentando o mesmo erro do DB.

docker@vm5:~$ docker service ps vote_worker
ID                  NAME                IMAGE                                          NODE                DESIRED STATE       CURRENT STATE                   ERROR                       PORTS
x9lsbrljrork        vote_worker.1       dockersamples/examplevotingapp_worker:latest   vm4                 Ready               Ready less than a second ago
0u0hmgltcioc         \_ vote_worker.1   dockersamples/examplevotingapp_worker:latest   vm4                 Shutdown            Failed less than a second ago   "task: non-zero exit (1)"
5k9aqj5x4aqv         \_ vote_worker.1   dockersamples/examplevotingapp_worker:latest   vm4                 Shutdown            Failed 7 seconds ago            "task: non-zero exit (1)"
m7kf0mmyyb80         \_ vote_worker.1   dockersamples/examplevotingapp_worker:latest   vm4                 Shutdown            Failed 13 seconds ago           "task: non-zero exit (1)"
51eyi1i9kvjo         \_ vote_worker.1   dockersamples/examplevotingapp_worker:latest   vm4                 Shutdown            Failed 20 seconds ago           "task: non-zero exit (1)"

Wanderson, pela coluna CURRENT STATE, o que parece é que os dois serviços estão funcionando. As outras linhas que indicam falhas aparentemente foram tentativas de iniciar o serviço sem que a imagem tivesse sido baixada ainda.

A execução da aplicação apresenta algum problema?

Daniel, creio já baixou, no visualizer aparece o Worker e DB tentando subir nas VMS 4 e 5, mas aparecem bem rápido com status em vermelho e fecham logo em seguida.

A aplicação não está apurando o resultado da votação.

Você chegou a definir no seu arquivo de composição em algum momento a versão do postgres para 9.4

Sim, eu usei o mesmo docker-compose que vc fez na vídeo aula, mas apresenta o mesmo problema.

Dei stop em todas as VMS e startei elas de novo, mas rola a mesma coisa ainda.

Qual a saída do comando docker image ls nos seus nós?

docker@vm5:~$ docker image ls
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
postgres                                latest              4b59e7d1ba1c        3 days ago          314MB
postgres                                <none>              ed5a45034282        2 months ago        251MB
aluracursos/barbearia                   <none>              acd0cfd82592        6 months ago        156MB
dockersamples/visualizer                <none>              8dbf7c60cf88        2 years ago         148MB
dockersamples/examplevotingapp_result   <none>              e10df791f13c        3 years ago         227MB

Faz o seguinte:

  • remove a stack.

  • altera o arquivo de composição aqui para a usar a versão 9.4 do postgres.

  • executa o comando docker image pull postgres:9.4 na sua vm5.

  • sobe a stack de novo com o com o arquivo de composição usando a versão 9.4 do postgres.

Daniel, Fiz tudo que vc pediu e ainda deletei as images antigas pra forçar a baixar tudo do zero, mas deu a mesma coisa. Trem tá estranho demais kkkkk

Manda o output do comando docker image ls das vms 4 e 5 e do docker service ps de todos os serviços.

docker@vm4:~$ docker image ls
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
redis                                   <none>              5c5637d8a823        3 weeks ago         29.8MB
postgres                                <none>              ed5a45034282        2 months ago        251MB
aluracursos/barbearia                   <none>              acd0cfd82592        6 months ago        156MB
dockersamples/visualizer                <none>              8dbf7c60cf88        2 years ago         148MB
dockersamples/examplevotingapp_worker   <none>              2b1e6048c539        3 years ago         962MB
dockersamples/examplevotingapp_result   <none>              e10df791f13c        3 years ago         227MB
docker@vm5:~$ docker image ls
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
postgres                                <none>              ed5a45034282        2 months ago        251MB
dockersamples/visualizer                <none>              8dbf7c60cf88        2 years ago         148MB
dockersamples/examplevotingapp_result   <none>              e10df791f13c        3 years ago         227MB
docker@vm5:~$ docker service ps vote_db
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE           ERROR                       PORTS
vqwuu1d1y1tt        vote_db.1           postgres:9.4        vm5                 Ready               Ready 2 seconds ago                      
4vt492h6nzvu         \_ vote_db.1       postgres:9.4        vm5                 Shutdown            Failed 3 seconds ago    "task: non-zero exit (1)"
rognr9dcfqdw         \_ vote_db.1       postgres:9.4        vm5                 Shutdown            Failed 8 seconds ago    "task: non-zero exit (1)"
5j3oqxkbzuke         \_ vote_db.1       postgres:9.4        vm5                 Shutdown            Failed 14 seconds ago   "task: non-zero exit (1)"
0lsfpdd6rw2w         \_ vote_db.1       postgres:9.4        vm5                 Shutdown            Failed 20 seconds ago   "task: non-zero exit (1)"
docker@vm5:~$ docker service ps vote_worker
ID                  NAME                IMAGE                                          NODE                DESIRED STATE       CURRENT STATE                     ERROR                       PORTS
lmmmkgg854e3        vote_worker.1       dockersamples/examplevotingapp_worker:latest   vm4                 Running             Starting less than a second ago
dt3q20mgbuwh         \_ vote_worker.1   dockersamples/examplevotingapp_worker:latest   vm4                 Shutdown            Failed 5 seconds ago              "task: non-zero exit (1)"
3pmd61aqt6dz         \_ vote_worker.1   dockersamples/examplevotingapp_worker:latest   vm4                 Shutdown            Failed 12 seconds ago             "task: non-zero exit (1)"
zr6y4i9y803j         \_ vote_worker.1   dockersamples/examplevotingapp_worker:latest   vm4                 Shutdown            Failed 18 seconds ago             "task: non-zero exit (1)"
o463r0nm2mf9         \_ vote_worker.1   dockersamples/examplevotingapp_worker:latest   vm4                 Shutdown            Failed 25 seconds ago             "task: non-zero exit (1)"
docker@vm5:~$ docker service ps vote_redis
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
p3bhs48ybluu        vote_redis.1        redis:alpine        vm3                 Running             Running 32 minutes ago                   
docker@vm5:~$ docker service ps vote_result
ID                  NAME                IMAGE                                          NODE                DESIRED STATE       CURRENT STATE            ERROR                       PORTS
yz1xb3kz9qvc        vote_result.1       dockersamples/examplevotingapp_result:before   vm3                 Running             Running 15 minutes ago
8o24xlszlh6b         \_ vote_result.1   dockersamples/examplevotingapp_result:before   vm3                 Shutdown            Failed 15 minutes ago    "task: non-zero exit (1)"
docker@vm5:~$ docker service ps vote_visualizer
ID                  NAME                IMAGE                             NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
v65ddllpifm8        vote_visualizer.1   dockersamples/visualizer:stable   vm1                 Running             Running 33 minutes ago     
docker@vm5:~$ docker service ps vote_vote
ID                  NAME                IMAGE                                        NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
4uo0q338on1c        vote_vote.1         dockersamples/examplevotingapp_vote:before   vm2                 Running             Running 33 minutes ago

Quando você executa o comando docker image pull postgres:9.4 na sua vm5, qual é o output?

docker@vm5:~$ docker image pull postgres:9.4
9.4: Pulling from library/postgres
Digest: sha256:42a7a6a647a602efa9592edd1f56359800d079b93fa52c5d92244c58ac4a2ab9
Status: Downloaded newer image for postgres:9.4
docker.io/library/postgres:9.4
docker@vm5:~$ docker image pull postgres:9.4
9.4: Pulling from library/postgres
Digest: sha256:42a7a6a647a602efa9592edd1f56359800d079b93fa52c5d92244c58ac4a2ab9
Status: Image is up to date for postgres:9.4
docker.io/library/postgres:9.4

Agora tenta executar a stack de novo.

removi a stack e subi de novo, mesma coisa kkkkk eu vou ter que sair agora, amanhã tento de novo. Obrigado!

Daniel, acessei o log do serviço vote_db, segue abaixo:

docker@vm5:~$ docker service logs m6z9w1mpt8bs
vote_db.1.0m7eankykioo@vm5    | Error: Database is uninitialized and superuser password is not specified.
vote_db.1.0m7eankykioo@vm5    |        You must specify POSTGRES_PASSWORD for the superuser. Use
vote_db.1.0m7eankykioo@vm5    |        "-e POSTGRES_PASSWORD=password" to set it in "docker run".
vote_db.1.0m7eankykioo@vm5    |
vote_db.1.0m7eankykioo@vm5    |        You may also use POSTGRES_HOST_AUTH_METHOD=trust to allow all connections
vote_db.1.0m7eankykioo@vm5    |        without a password. This is *not* recommended. See PostgreSQL
vote_db.1.0m7eankykioo@vm5    |        documentation about "trust":
vote_db.1.0m7eankykioo@vm5    |        https://www.postgresql.org/docs/current/auth-trust.html
vote_db.1.rxon72ewy34l@vm5    | Error: Database is uninitialized and superuser password is not specified.
vote_db.1.rxon72ewy34l@vm5    |        You must specify POSTGRES_PASSWORD for the superuser. Use
vote_db.1.rxon72ewy34l@vm5    |        "-e POSTGRES_PASSWORD=password" to set it in "docker run".
vote_db.1.rxon72ewy34l@vm5    |
vote_db.1.rxon72ewy34l@vm5    |        You may also use POSTGRES_HOST_AUTH_METHOD=trust to allow all connections
vote_db.1.rxon72ewy34l@vm5    |        without a password. This is *not* recommended. See PostgreSQL
vote_db.1.rxon72ewy34l@vm5    |        documentation about "trust":
vote_db.1.rxon72ewy34l@vm5    |        https://www.postgresql.org/docs/current/auth-trust.html
vote_db.1.jruxse018qh8@vm5    | Error: Database is uninitialized and superuser password is not specified.
vote_db.1.jruxse018qh8@vm5    |        You must specify POSTGRES_PASSWORD for the superuser. Use
vote_db.1.jruxse018qh8@vm5    |        "-e POSTGRES_PASSWORD=password" to set it in "docker run".
vote_db.1.jruxse018qh8@vm5    |
vote_db.1.jruxse018qh8@vm5    |        You may also use POSTGRES_HOST_AUTH_METHOD=trust to allow all connections
vote_db.1.jruxse018qh8@vm5    |        without a password. This is *not* recommended. See PostgreSQL
vote_db.1.jruxse018qh8@vm5    |        documentation about "trust":
vote_db.1.jruxse018qh8@vm5    |        https://www.postgresql.org/docs/current/auth-trust.html
vote_db.1.fz28472yr1n9@vm5    | Error: Database is uninitialized and superuser password is not specified.
vote_db.1.fz28472yr1n9@vm5    |        You must specify POSTGRES_PASSWORD for the superuser. Use
vote_db.1.fz28472yr1n9@vm5    |        "-e POSTGRES_PASSWORD=password" to set it in "docker run".
vote_db.1.fz28472yr1n9@vm5    |
vote_db.1.fz28472yr1n9@vm5    |        You may also use POSTGRES_HOST_AUTH_METHOD=trust to allow all connections
vote_db.1.fz28472yr1n9@vm5    |        without a password. This is *not* recommended. See PostgreSQL
vote_db.1.fz28472yr1n9@vm5    |        documentation about "trust":
vote_db.1.fz28472yr1n9@vm5    |        https://www.postgresql.org/docs/current/auth-trust.html

saída dos logs do vote_worker

docker@vm5:~$ docker service logs py3wuw3p4xtc
vote_worker.1.qpwwzm9bruh1@vm4    | System.AggregateException: One or more errors occurred. (No such device or address) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No such device or address
vote_worker.1.qpwwzm9bruh1@vm4    |    at System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult)
vote_worker.1.qpwwzm9bruh1@vm4    |    at System.Net.Dns.EndGetHostAddresses(IAsyncResult asyncResult)
vote_worker.1.qpwwzm9bruh1@vm4    |    at System.Net.Dns.<>c.<GetHostAddressesAsync>b__14_1(IAsyncResult asyncResult)
vote_worker.1.qpwwzm9bruh1@vm4    |    at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
vote_worker.1.qpwwzm9bruh1@vm4    |    --- End of inner exception stack trace ---
vote_worker.1.qpwwzm9bruh1@vm4    |    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
vote_worker.1.qpwwzm9bruh1@vm4    |    at Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
vote_worker.1.qpwwzm9bruh1@vm4    |    at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout)
vote_worker.1.qpwwzm9bruh1@vm4    |    at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)
vote_worker.1.qpwwzm9bruh1@vm4    |    at Npgsql.ConnectorPool.Allocate(NpgsqlConnection conn, NpgsqlTimeout timeout)
vote_worker.1.qpwwzm9bruh1@vm4    |    at Npgsql.NpgsqlConnection.OpenInternal()
vote_worker.1.qpwwzm9bruh1@vm4    |    at Worker.Program.OpenDbConnection(String connectionString) in /code/src/Worker/Program.cs:line 74
vote_worker.1.qpwwzm9bruh1@vm4    |    at Worker.Program.Main(String[] args) in /code/src/Worker/Program.cs:line 19
vote_worker.1.qpwwzm9bruh1@vm4    | ---> (Inner Exception #0) System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No such device or address
vote_worker.1.qpwwzm9bruh1@vm4    |    at System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult)
vote_worker.1.qpwwzm9bruh1@vm4    |    at System.Net.Dns.EndGetHostAddresses(IAsyncResult asyncResult)
vote_worker.1.qpwwzm9bruh1@vm4    |    at System.Net.Dns.<>c.<GetHostAddressesAsync>b__14_1(IAsyncResult asyncResult)
vote_worker.1.qpwwzm9bruh1@vm4    |    at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)<---
vote_worker.1.qpwwzm9bruh1@vm4    |
vote_worker.1.dvutmxvt6al1@vm4    | System.AggregateException: One or more errors occurred. (No such device or address) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No such device or address
vote_worker.1.dvutmxvt6al1@vm4    |    at System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult)
vote_worker.1.dvutmxvt6al1@vm4    |    at System.Net.Dns.EndGetHostAddresses(IAsyncResult asyncResult)
vote_worker.1.dvutmxvt6al1@vm4    |    at System.Net.Dns.<>c.<GetHostAddressesAsync>b__14_1(IAsyncResult asyncResult)
vote_worker.1.dvutmxvt6al1@vm4    |    at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)

Olá Wanderson! O erro:

Error: Database is uninitialized and superuser password is not specified. You must specify POSTGRES_PASSWORD for the superuser. Use "-e POSTGRES_PASSWORD=password" to set it in "docker run".

Pelo que vi na comunidade está acontecendo bastante já que de os mantenedores resolveram tornam o Postgres mais seguro impedindo o acesso sem senha como era antes, você pode ver a discussão aqui, isso está quebrando muito usuários, porém se quisermos continuar acessando sem senha podemos definir no arquivo docker-compose.yml no serviço "postgres", uma nova configuração, deixando a descrição do serviço da seguinte forma:

db:
  image: postgres
  env:
    POSTGRES_HOST_AUTH_METHOD=trust
  volumes:
    - db-data:/var/lib/postgresql/data
  networks:
    - backend
  deploy:
    placement:
      constraints: [node.hostname == vm5]

Isso deve está acontecendo porque na instrução image: postgres não indicamos a versão e essa mudança aconteceu recentemente. Tenta fazer isso, e verificar se o Postgres fica funcionando normalmente, e depois podemos verificar o problema do serviço vote_worker!

Jonilson, blz?

então, fiz isso, mas retornou o seguinte:

docker@vm5:~$ docker stack deploy --compose-file docker-compose.yml vote
env Additional property enviroment is not allowed

troquei o env por environment e retornou isso:

docker@vm5:~$ docker stack deploy --compose-file docker-compose.yml vote
services.db.environment must be a mapping

Wanderson, você poderia colocar o conteúdo do seu arquivo docker-compose.yml (já com o environment) aqui para gente poder verificar isso geralmente acontece por causa do espaçamento.

Segue abaixo:

version: "3"
services:

  redis:
    image: redis:alpine
    networks:
      - frontend
    deploy:
      placement:
        constraints: [node.hostname == vm3]
      replicas: 1
      restart_policy:
        condition: on-failure

  db:
    image: postgres
    environment:
      POSTGRES_HOST_AUTH_METHOD=trust
    volumes:
      - db-data:/var/lib/postgresql/data
    networks:
      - backend
    deploy:
      placement:
        constraints: [node.hostname == vm5]

  vote:
    image: dockersamples/examplevotingapp_vote:before
    ports:
      - 5000:80
    networks:
      - frontend
    depends_on:
      - redis
    deploy:
      placement:
        constraints: [node.role == worker]
      replicas: 1
      restart_policy:
        condition: on-failure

  result:
    image: dockersamples/examplevotingapp_result:before
    ports:
      - 5001:80
    networks:
      - backend
    depends_on:
      - db
    deploy:
      placement:
        constraints: [node.role == worker]
      replicas: 1
      restart_policy:
        condition: on-failure

  worker:
    image: dockersamples/examplevotingapp_worker
    networks:
      - frontend
      - backend
    depends_on:
      - redis
      - db
    deploy:
      placement:
        constraints: [node.hostname == vm4]
      mode: replicated
      replicas: 1
      labels: [APP=VOTING]
      restart_policy:
        condition: on-failure

  visualizer:
    image: dockersamples/visualizer:stable
    ports:
      - 8080:8080
    stop_grace_period: 1m30s
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      placement:
        constraints: [node.hostname == vm1]

networks:
  frontend:
  backend:

volumes:
  db-data:
solução!

Wanderson, tenta executar com esse conteúdo:

version: "3"
services:

  redis:
    image: redis:alpine
    networks:
      - frontend
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure

  db:
    image: postgres:9.5.21
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    networks:
      - backend
    deploy:
      placement:
        constraints: [node.role == manager]

  vote:
    image: dockersamples/examplevotingapp_vote:before
    ports:
      - 5000:80
    networks:
      - frontend
    depends_on:
      - redis
    deploy:
      replicas: 2
      restart_policy:
        condition: on-failure

  result:
    image: dockersamples/examplevotingapp_result:before
    ports:
      - 5001:80
    networks:
      - backend
    depends_on:
      - db
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure

  worker:
    image: dockersamples/examplevotingapp_worker
    networks:
      - frontend
      - backend
    depends_on:
      - db
      - redis
    deploy:
      mode: replicated
      replicas: 1
      labels: [APP=VOTING]
      restart_policy:
        condition: on-failure
      placement:
        constraints: [node.role == worker]

  visualizer:
    image: dockersamples/visualizer:stable
    ports:
      - 8080:8080
    stop_grace_period: 1m30s
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      placement:
        constraints: [node.role == manager]

networks:
  frontend:
  backend:

volumes:
  db-data:

E fala pra gente o resultado!

Funcionou com essas alterações no DB. Rolou tanto com o seu código quanto com meu modificado também.