docker exec command not executing in sh file

When running below command in command line(terminal) this gets executed fine:

$sudo docker exec -it 5570dc09b58 bash

But same results with :

  • Lucee 5, Nginx, and Docker Compose not finding sample index.cfm file
  • Piping docker run container ID to docker exec
  • Deploying ASP.NET 5 app to EC2 in a Docker container
  • Connect two instances of docker-compose
  • How to set hosts in docker for mac
  • How to protect a web application running in a Docker container by username and password?
  • FATA[0000] cannot enable tty mode on non tty input

    Error when running in a shell script file.

  • Docker MySQL no output
  • Is it possible to deploy Docker containers using Netflix's Spinnaker?
  • Launching nvidia-docker containers using Marathon
  • Requests to docker containers failing on chrome for OSX
  • Mock Raspberry Pi SPI device on OS X for Docker app
  • Docker: communication between web container and php container
  • 2 Solutions collect form web for “docker exec command not executing in sh file”

    You are not running docker in a terminal, so you should remove -t from -it:

    sudo docker exec -i 5570dc09b58 bash

    See a more detailed answer here.

    Scripts may be forced to run in interactive mode with the -i option or with a #!/bin/bash -i header.

    So adding shebang to the script with -i option should work:

    #!/bin/bash -i
    docker exec -it ed3d9e46b8ee date

    Run the script as usual:

    chmod +x
    sudo ./ 


    Thu Apr  2 14:06:00 UTC 2015
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.