Skip to content

Instantly share code, notes, and snippets.

@worldofprasanna
Last active March 6, 2017 23:46
Show Gist options
  • Save worldofprasanna/a6ee5df1083a31b1260d991007b77a29 to your computer and use it in GitHub Desktop.
Save worldofprasanna/a6ee5df1083a31b1260d991007b77a29 to your computer and use it in GitHub Desktop.
Docker basic commands for reference
# pull & start the container
docker run busybox
# list all the images
docker images
# to remove all the images
docker rmi $(docker images -q)
# to remove the exited containers
docker rm $(docker ps -a -q -f status=exited)
# to temp run the container and remove it once ran
docker run busybox --rm
# good to get the container id
cid=$(docker run -itd busybox)
# with name, i => Interactive mode, t => attach terminal, d => run as daemon container
docker run --name busybox -itd busybox
# attach or bring the daemon container to foreground using the name
docker attach busybox
# to login to the container
docker exec -it $cid sh
# to kill all the containers (including stopped containers)
# kill will just stop the container. state is still preserved
docker ps -qa | xargs docker kill
# to remove all the containers
# this will delete the containers, it can be started again using docker run cmd. But it ll be new container and all the state would be lost
docker ps -qa | xargs docker rm
# get the properties of container
docker inspect $cid
# mount volume into docker. host /tmp will be mounted as /tmp in container
docker run -itd -v /tmp:/tmp -v /dev:/dev busybox
# mount volumes from other docker container.
docker run -itd --name test2 --volumes-from test1 busybox
# execute one off commands
docker run -itd --name test3 busybox /bin/sh -c 'while true; do echo Docker; sleep 1; done'
# check the logs
docker logs -ft test3
# inspect the particular property
docker inspect --format '{{.Config.Cmd}}' test3
# reference used
https://gist.github.com/botchagalupe/53695f50eebbd3eaa9aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment