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

425
Visualizações
How to get docker container id when starting container

When writing a bash script that starts a docker container, it is useful to refer to the started docker container. How do you get the specific container id of a docker container when you start it?

P.S. I know that I can use --name to name the container, which I can use to filter the list of containers using docker ps -aqf "name=containername", but this will fail if I ever start the script twice. And then there's the possibility of name conflicts. Besides, what's the point of container IDs if you can't use them?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

When you start a detached container, it returns the container ID. e.g.:

$ docker run -d ubuntu:18.04
71329cf6a02d89cf5f211072dd37716fe212787315ce4503eaee722da6ddf18f

In bash, you can define a new variable from the output like this:

CID=$(docker run -d ubuntu:18.04)

Then, later you can use this variable to refer to your container like this:

docker stop $CID
docker rm $CID
over 4 years ago · Santiago Trujillo Relatório

0

In the documentation for docker run under "capture container id", they advise using the --cidfile flag for this purpose.

--cidfile takes a file name as an argument and will write the long ID of the container to that location. E.g.,

docker run --cidfile /tmp/hello-world.cid hello-world && cat /tmp/hello-world.cid

This is useful when you don't want to run the image in a detached state, but still want access to the ID.

over 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