Skip to content

Instantly share code, notes, and snippets.

@ashokfernandez
Last active August 29, 2015 14:16
Show Gist options
  • Save ashokfernandez/33034d7c841f6df76951 to your computer and use it in GitHub Desktop.
Save ashokfernandez/33034d7c841f6df76951 to your computer and use it in GitHub Desktop.
Build and run a docker image, then open a bash shell inside the running container
#!/bin/bash
docker stop $(docker ps -a -q) # Stop and close any running docker containers
docker rm $(docker ps -a -q)
docker build -t myapp . # Build and run the container
docker run --name mydockerapp -d -p 80:80 myapp
docker exec -it mydockerapp bash # Open a bash terminal on the running container
@ashokfernandez
Copy link
Author

To exit the bash shell just type exit. Next time you run the script the old running container will be shutdown before being rebuilt and started again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment