Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda