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 delete all tagged docker images?
  • How to run google chrome headless in docker?
  • How to forward a docker container port to the host
  • django docker-compose --> memcached not working
  • Push images to private docker registry error with 500
  • Boot2docker very slow on Windows without shared folders
  • 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?

  • when we run the hello-world image its throws the connection refused error message
  • Passing Elasticsearch and Kibana config file to docker containers
  • Using dotnet from docker to power Visual Studio C# extension (OmniSharp)
  • Can't connect to dockerized MongoDB instance
  • HTTP port exposed but not responding properly
  • How to fix cadvisor error `devicemapper filesystem stats will not be reported`?
  • 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.