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.

  • docker registry with --insecure-registry and docker 1.5
  • Cannot install docker pkg dependency in Go
  • Symfony app in Docker doesn't work
  • Volumes with docker microsoft/iis
  • Use senecajs with docker
  • Docker - Ubuntu - Nginx - MariaDB - Connection refused
  • 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?

  • Traefik accessLog configuration
  • Can't find Docker data volume on host
  • Seeding a database using Docker Mysql COPY fails
  • Docker error at higher core counts on a multi core machine
  • Docker run with pseudoTTY (-t) gives instant stdout, buffering happens without it
  • jenkins 'execute script' build step Error: /bin/docker: Permission denied
  • 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.