Executing bash then running commands in docker

You can execute a bash shell in a docker container by using

sudo docker exec -it container bash

But I want a command that executes a bash shell in the container and then executes more commands in the bash prompt.

  • How to get a docker container to the state: dead for debugging?
  • Docker volumes-from not working when launching container with -H host flat
  • Nvidia Theano docker image not available
  • spring-boot cannot start in docker
  • EFS volume not mounted on Docker container on Elastic Beanstalk
  • Heapster fails to get container stats from Kubelet on Kubernetes cluster
  • A command like this currently works:

    sudo docker exec -it container touch test.txt | bash

    However, the command I want to run in the bash prompt is only available from within the docker container, so I get an error:

    No such file or directory

    Is it possible to execute a command that is local to the docker container using docker exec?

  • Docker Upgrade from v1.11 to v1.12 using apt-get on Ubuntu 14.04.4 LTS
  • MySQL Docker container is not saving data to new image
  • Docker difference in start and stop times
  • Running GUI from a container on a mac resolve in “libGL error: No matching fbConfigs or visuals found”
  • Mount directory using docker-compose or dockerfile (without copying)
  • two docker machine, same web-app, two different IP, but needs to be sync
  • 2 Solutions collect form web for “Executing bash then running commands in docker”

    I suppose I should’ve read the docker docs more!

    docker exec -it container mycommand

    works fine! For some reason I was thinking I had to initiate a bash prompt then use other commands, my mistake.

    Thanks jrbeverly and user2105103 for the explanation that “EVERY command executed via docker exec is inside the container.”

    In case someone is curious how to run multiple commands in a container, I’m using:

    sudo docker exec -it container sh -c "com1 && com2 && com3"

    Try something like this:

    sudo docker exec -it container bash -c "touch test.txt ; <another command>"
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.