Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the output from docker run -i

docker run normally returns the output of the command it runs. I need to pass some data to docker, run a command that processes the data, and return the output. When I use the -i option, no output is returned. Consider this simple example:

echo hello | docker run -i base wc

It returns no output. How can I get the output from docker when using the -i option?

like image 751
Naveed Avatar asked Apr 26 '13 09:04

Naveed


People also ask

Can code be extracted from docker image?

You can use COPY or ADD command within Dockerfile to copy your file/code into the Docker container. The following Dockerfile example shows how to add the current working directory files and folders into the directory /usr/Qxf2_POM of the container image.

What is in docker Run command?

The docker run command creates a container from a given image and starts the container using a given command. It is one of the first commands you should become familiar with when starting to work with Docker.

What is stdout in docker?

STDOUT is usually a command's normal output, and STDERR is typically used to output error messages. By default, docker logs shows the command's STDOUT and STDERR .


1 Answers

The solution I came up with is:

ID=$(echo hello | docker run -i -a stdin base wc)
docker logs $ID

I'm not sure if this is the best way, but it works.

like image 71
Naveed Avatar answered Oct 24 '22 08:10

Naveed