Skip to content

Instantly share code, notes, and snippets.

@robdmc
Last active August 22, 2022 13:45
Show Gist options
  • Save robdmc/00ea09b01a2d3ca349e8 to your computer and use it in GitHub Desktop.
Save robdmc/00ea09b01a2d3ca349e8 to your computer and use it in GitHub Desktop.
Docker Commands
# list images
docker images
# list only image ids
docker images -q
# build an image from a dockerfile with a tag name
docker build -t image_tag_name
# list running containers
docker ps
# list all containers (running or not running)
docker ps -a
# rename container
docker rename old_name new_name
# docker delete image
docker rmi <image-id>
# docker delete container
docker rm <container-id>
# run a container from an image (image_name can be repo_name/tag_name)
docker run -it --name --init <container_name> <image_name> /bin/bash
# run a container while mounting pwd on host (must be under ~) to the /var/shared directory in container
docker run -v $(pwd):/var/shared --name <container_name> --int -it <image_name> /bin/bash
# run a container from an image and delete it when done
docker run -it --init --rm <image_name> /bin/bash
# start an existing container and log in
docker start -ai <container-name>
# log into running container from another shell
docker exec -it <container-name> /bin/bash
# create an image from a container and give it a name
docker commit <image_name>
docker tag <image_id> <new_image_name>
# copy files to and from docker container
docker cp <container>:<path> <localpath>
# delete volumes
docker volume ls -qf dangling=true | xargs -r docker volume rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment