Skip to content

Instantly share code, notes, and snippets.

@carlnc
Last active December 7, 2022 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlnc/348336c7a410ada7fc7a8191a8806984 to your computer and use it in GitHub Desktop.
Save carlnc/348336c7a410ada7fc7a8191a8806984 to your computer and use it in GitHub Desktop.
Docker Commands (for MacOS)

Top level Commands

Docker CLI Reference

Command Comments
docker --version
docker pull <image[:tag]>
docker run -it --rm <image[:tag]> interactive, tty, auto-cleanup
docker run -it --rm <image[:tag]> /bin/bash
docker run -it --rm --endpoint /bin/bash <image[:tag]>
docker ps Short for docker container ls
docker ps -a -a = Include stopped containers
docker ps -aq -q = just container IDs
docker stop <container>
docker start <container>
docker kill <container>
docker rm <container>
docker rmi <image>
docker build -f ./path/to/Dockerfile -t <tag>
docker images same as docker image ls
docker history <image>
docker attach <container>
docker restart <container> stop container, after 10 secs kill, then start again.
docker rename <container> <new name>
docker
docker

Interaction

Command Comments
docker attach <container> Attach local standard input, output, and error streams to a running container.
Use CTRL-p CTRL-q to detach. Must have been started with -t
docker exec -it <container> <command> [...args]
docker
docker
docker

Volume Management

Command Comments
docker volume prune Remove unused volumes (a stopped container = used)
docker cp <container>:<path> <host path> copy out
docker cp <host path> <container>:<path> copy in
docker cp <container>:<path> - print contents to stdout
docker export -o blah.tar <container>
docker import ./file.[tar,.tgz,bzip,...] <imagename:tag>
docker diff <container>
docker checkpoint create <container> <checkpoint> (experimental)
docker checkpoint ls (experimental)
docker start --checkpoint <checkpoint> <container> (experimental)
docker checkpoint remove <container> <checkpoint> (experimental)
``

Network Management

Command Comments
docker network connect <network> <container> Attach network to running container
``
``
``
``

Docker Registry

Command Comments
docker login -u <username> --password-stdin <docker.server.com>
docker commit <container> <repo<:tag>>
docker push
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Sub-system Commands

CI/CLI Commands (ie: for scripts, not general usage)

Command Comments
docker port <container> Get publicly exposed ports
docker port <container> 1234/tcp Find where we exposed the containers port

Debugging

Command Comments
DOCKERDIR=~/Library/Containers/com.docker.docker
socat -dd $DOCKERDIR/Data/debug-shell.sock pty,rawer
screen /dev/ttys001
Screen into linux VM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment