Is it possible to send string into running process inside docker container?

For example i have running docker container with cat (or other process using stdin) defined in CMD Dockerfile option.

I’m trying to send string test\n into running cat (or other process).

  • docker api, attaching container returns extra characters
  • Add Image to my Base Docker Image
  • Listing the tags of a docker image on a Docker hub through the HTTP API
  • How to keep changes inside a container on the host after a docker build?
  • return from docker-compose up in jenkins
  • Docker centos7 image - unable to run apache
  • Is it possible to do this, or I need to find workaround?

    Sum up:
    I’m looking for something like
    echo 'test' | docker run -i --rm alpine command
    for running container.

  • Boot2Docker searching for docker-bootstrap.sock which does not exist
  • Docker ELK stack with docker-py
  • How to install extension for php via docker-php-ext-install?
  • Start supervisor by non root user
  • docker-compose error when I run bundle
  • How would I pass environment into docker using bash?
  • 3 Solutions collect form web for “Is it possible to send string into running process inside docker container?”

    You can pipe to stdin of the container’s process if you start the container with -i. For example;

    echo "foobar" | docker run -i --rm alpine cat

    Keep in mind, that this is done when starting the container. Your question mentioned cat, which is not a long running process, so the container will actually exit after cat completes.

    I solved it by simply pipeing stdin to docker attach, for example:

    $ docker run -i busybox sh -c "while true; do cat /dev/stdin; sleep 1; done;"

    and in another term

    $ echo test | docker attach <containerId>

    Yes as an example see

    you need to open a port, extract from the previous link

    $ docker run -d -t --name=netcat-jessie -p 8182:8182 -p 9192:9192/udp chilcano/netcat:jessie

    and now, you have some examples of communication using those ports
    send traces to open a TCP port

    $ ping | nc -v 8182

    or send traces to an UDP port

    $ ping | nc -vu 9192

    or send traces to an UDP port without netcat

    $ ping > /dev/udp/


    $ tail -f /opt/wiremock/wiremock.log | nc -vu 9192

    or send traces to a TCP port without netcat

    $ tail -f /opt/wso2esb01a/repository/logs/wso2carbon.log > /dev/tcp/

    or send traces to an UDP port without netcat

    $ tail -f /opt/wso2am02a/repository/logs/wso2carbon.log > /dev/udp/
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.