Skip to content

Instantly share code, notes, and snippets.

@gwsu2008
Last active March 2, 2023 16:54
Show Gist options
  • Save gwsu2008/dcc70dbe67652845ec70f74abf33deea to your computer and use it in GitHub Desktop.
Save gwsu2008/dcc70dbe67652845ec70f74abf33deea to your computer and use it in GitHub Desktop.
docker-commands
#!/bin/bash +x
* Run the container
docker run -it -e VAR=1 ubuntu_bash -d ashok/pyashokproj /bin/bash
* To start an existing container which is stopped
docker start <container-name/ID>
* To stop a running container
docker stop <container-name/ID>
* Then to login to the interactive shell of a container
docker exec -it <container-name/ID> /bin/bash
* To run a series of commands, you must wrap them in a single command using a shell.
docker exec -it CONTAINER_ID bash -c "command1 && command2 || command3"
* Clean up exited containers
docker rm $(docker ps -a -q -f status=exited)
docker start `docker ps -q -l` # restart it in the background
docker attach `docker ps -q -l` # reattach the terminal & stdin
* Get docker labels and descriptions
docker inspect -f {{.Config.Labels}} image_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment