Cover Art

Basic Docker Commands

DescriptionCommandNotes
Pulls docker image from hub.docker.comdocker pull [image name]
Runs containerdocker run [image name]:[tag]
Run container in “detached” modedocker run -d [image name]:[tag]Running as daemon/background
Run container on port 8000docker run -p 8000:80 [image name]:[tag]Format for port flag is [host:container]
Naming containerdocker run --name container-name [image name]:[tag]
Mounting a volumedocker run -v /path/to/file/host:/where/to/put/file:[ro/rw] [image name]:[tag]
Starting a containerdocker start [container ID/container name]
Stopping a containerdocker stop [container ID/container name]
Lists the processes of docker containersdocker ps
Same as docker psdocker container ls
Lists installed docker imagesdocker imagesDefault
Same as docker imagesdocker image ls
Removing a single containerdocker rm [container ID/container name]
Removing all stopped containersdocker rm $(docker ps -aq)
Removing all containers, regardless of statedocker rm -f $(docker ps -aq)
Builds a Docker imagedocker build -t [new image name]:[tag] .Dockerfile needs to be in current working directory
Interactive shell inside containerdocker exec -it [container ID/container name] [shell]
Outputs container info to JSON formatdocker inspect [container ID/container name]
Outputs log of containerdocker log [container ID/container name]