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

209
Visualizações
Capture the output of a program run in Docker

I use docker to run a bash script and I need to capture its output and just its output.

docker run --rm --volume=/tmp/test.sh:/tmp/test.sh:ro --entrypoint=/bin/bash node:4.6.0 -xe /tmp/test.sh

The problem is that I also get the output from docker downloading the image. Thinks like:

Unable to find image 'node:4.6.0' locally
4.6.0: Pulling from library/node
6a5a5368e0c2: Pulling fs layer
7b9457ec39de: Pulling fs layer
ff18e19c2db4: Pulling fs layer
6a3d69edbe90: Pulling fs layer
0ce4b037e17f: Pulling fs layer

Is there a way to only capture the output generated by the bash script run by docker without any additional messages/errors/warnings that docker may output?

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

0

The docker output is sent to stderr so it can be differentiated from your normal script output.

If you need both stderr and stdout from the container use the output from docker logs, which is the safest option but a bit more complex to setup. Note logs only works locally with the default json-file and journald log drivers.

CID=$(docker run -d --volume=/tmp/test.sh:/tmp/test.sh:ro \
        --entrypoint=/bin/bash node:4.6.0 -xe /tmp/test.sh)
docker wait $CID
docker logs $CID
docker rm $CID

If you are only interested in the stdout of your process, redirect stdout to a file. Any error output, along with dockers, will go to screen. The file will only contain stdout data.

docker run --rm --volume=/tmp/test.sh:/tmp/test.sh:ro \
  --entrypoint=/bin/bash node:4.6.0 -xe /tmp/test.sh > output

You could also redirect stderr to stdout inside the container so you only lose the docker stderr output.

docker run -rm --volume=/tmp/test.sh:/tmp/test.sh:ro \
  --entrypoint=/bin/bash node:4.6.0 -xec '/tmp/test.sh 2>&1' > output
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