Docker Cheat Sheet
To run a Docker container to support a development workflow, we will do the following:
- Mount our source code into the container
- Install all dependencies, including the “dev” dependencies
- Start nodemon to watch for filesystem changes
Basic usage
docker ps [-all]
list (all) containersdocker stop <container-id>
ordocker stop <container-name>
Stop a containerdocker rm <container-id>
Remove one or more containers that have stoppeddocker rm -f <container-id>
Stop and remove a containerdocker rmi <repository>
Remove one or more imagesdocker run -dp 3000:3000 <container-name>
Start ad
etached container atp
orthttp://localhost:3000
docker attach <container-id/name>
Attach local standard input, output, and error streams to a running container- Pushing and pulling a Docker Image using Docker Hub: see http://localhost/tutorial/sharing-our-app/
The Container’s Filesystem
When a container runs, it uses the various layers from an image for its filesystem. Each container also gets its own “scratch space” to create/update/remove files. Any changes won’t be seen in another container, even if they are using the same image.
docker run <container-id/name> <command>
Run a docker container and execute a commanddocker exec <container-id/name> cat /data.txt
Execute a command (herecat /data.txt
) on a running containter
By default, changes are lost when the container is removed and all changes are isolated to that container.
Docker volumns
Volumes provide the ability to connect specific filesystem paths of the container back to the host machine.
docker volume create <volume-name>
Create a volumedocker volume inspect
Display detailed information on one or more volumes- The
Mountpoint
is the actual location on the disk where the data is stored.
- The
docker volume ls
List volumesdocker volume rm
Remove one or more volumesdocker volume prune
Remove all unused local volumes