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.

  • Public Docker v2 API Endpoints
  • Network path between containers in custom network
  • running iptables with rhel7.2 image with in docker
  • How to enable clustering of RabbitMQ Docker containers
  • Docker: How do I pull a specific build-id?
  • Moving from Vagrant to Vagrant with Docker
  • 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?

  • What's the difference between Docker and Rocket from CoreOS?
  • Docker swarm: How to manually set node names?
  • Share docker socket using user namespaces
  • What is the tar-data.json.gz in /var/lib/docker/graph/<image GUID>
  • EmberJS development in Docker
  • Backing up and restoring mysql database with Laravel/Docker
  • 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.