-1

If we've to do some operations(execute commands) inside of docker container, we can go inside it and then execute commands -

docker exec -it <ContainerId> bash   # go inside of container
cd /usr/local/tomcat/bin             # hit command inside of container
./catalina.sh start                  # hit command inside of container

After this we need to hit Ctrl + C to come out of container.

But without going inside of container, can we execute commands inside of it from host directly like -

   // command to attach to container
   // command 1 to execute
   // command 2 to execute
   // no command required to come out of container as above commands directly hit from hosts
Alpha
  • 13,320
  • 27
  • 96
  • 163
  • Does this answer your question? [How do I run a command on an already existing Docker container?](https://stackoverflow.com/questions/26153686/how-do-i-run-a-command-on-an-already-existing-docker-container) – Chris Maes Mar 02 '21 at 13:44

1 Answers1

0

yes you can run your command at once:

docker exec -it <ContainerId> /usr/local/tomcat/bin/catalina.sh start

if you need to run multiple commands, you can pass them straight to bash:

docker exec -it <ContainerId> bash -c 'command1 && command2'
Chris Maes
  • 35,025
  • 12
  • 111
  • 136