Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

388
Visualizações
How to docker exec -ti CONTAINER_NAME /bin/bash on deployed docker stack?

I have a deployed docker stack on AWS with swarm:

docker stack deploy --with-registry-auth -c docker-stack.yml pipeline

I want to get an interactive bash session into one of the containers defined in the docker-stack.yml, but the various docker exec -ti CONTAINER_NAME /bin/bash invocations that I have tried all fail.

What is the right method to derive a container name to be passed to:

docker exec -it CONTAINER_NAME /bin/bash

given that:

docker service ps pipeline_django

returns valid service information and:

docker stack ps pipeline

returns valid stack information.

None of the documented methods of deriving the container_name from these commands work when passed to the docker exec -it command. They all fail with:

Error response from daemon: No such container

I've tried the things listed here:

execute a command within docker swarm service

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

The other answers failed, because they no not extract the container it from the task. Swarm wraps a task object around a container:

taskid=$(docker service ps -q ${servicename} |head -1)
containerid=$(docker inspect -f '{{.Status.ContainerStatus.ContainerID}}' ${taskid})
docker exec -it ${containerid} "$*"

Of course, this will only take the first container in the list.

about 4 years ago · Santiago Trujillo Relatório

0

Here is an example on my local macOS.

$ docker stack ls
NAME                SERVICES
gospot_web          1

$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                               PORTS
qigx492p2lbe        gospot_web_web      global              1/1                 gospot/gospot-web:0.1.20.g225306b   *:80->80/tcp, *:443->443/tcp

You can use either container id or container name to access the container.

$ docker ps
CONTAINER ID        IMAGE                               COMMAND                  CREATED             STATUS                 PORTS               NAMES
b3824a85d3c8        gospot/gospot-web:0.1.20.g225306b   "nginx -g 'daemon of…"   2 hours ago         Up 2 hours (healthy)   80/tcp, 443/tcp     gospot_web_web.3cqcd1v22vaon517j7p5h1d9a.wrel676fcllssrm3151ymkse9

$ docker exec -it b3824a85d3c8 sh
/ # ls
bin    etc    lib    mnt    root   sbin   sys    usr
dev    home   media  proc   run    srv    tmp    var
/ #

$ docker exec -it 
gospot_web_web.3cqcd1v22vaon517j7p5h1d9a.wrel676fcllssrm3151ymkse9 sh
/ # ls
bin    dev    etc    home   lib    media  mnt    proc   root   run    
sbin   srv    sys    tmp    usr    var
/ #

If the target service name is unique enough, you can use the following one-liner.

$ docker exec -it $(docker ps | grep gospot_web_web | awk '{print $1}') sh
/ # ls
bin    etc    lib    mnt    root   sbin   sys    usr
dev    home   media  proc   run    srv    tmp    var
/ #

Hope this helps.

about 4 years ago · Santiago Trujillo Relatório

0

You can use below command and replace SERVICE_NAME with your service name:

docker exec -it \
    $(docker stack ps pipeline| grep SERVICE_NAME | cut -d' ' -f1) /bin/bash

this command finds the container id of your service:

docker stack ps pipeline| grep SERVICE_NAME | cut -d' ' -f1
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda