Some helpful commands when using docker.
Daily Commands
Command | Description |
---|---|
docker ps | List all running docker images |
docker ps -a | List all running and not running docker images |
docker logs -f <container> | Output docker logs (CTRL-C to exit) |
docker exec -it <container> bash | Log into a docker image |
Information Commands
Command | Description |
---|---|
docker version | Show docker version information |
docker info | Docker info |
docker inspect <container> | Display information about the container. This command will show you the entrypoint and other useful information. |
docker events <container> | Gets events from the container |
docker port <container> | Show public facing port of the container |
docker top <container> | Show top running processes in the container. |
docker stats docker stats <container> | Show containers' resource usage. |
Container Commands
Commands | Description |
---|---|
docker ps -a | List all containers |
docker logs <container_id/name> | Display logs for a container |
docker diff <container_id/name> | Show changes to container |
docker rm <container_id> <container_id> | Remove a docker container |
docker attach <container_id> | Attach to a container. CTR-C to exit |
docker run -d -p <ex_port>:<int_port> <image> ex. docker run -d -p 9001:9001 toke/mosquitto | Create container mapping external port to Internal port. |
docker run --name <name> -d ... <image> | Create container with a name. |
docker start <container_id/name> | Start a container |
docker stop <container_id/name> | Stop a container |
docker rm <container_id/name> | Remove a stopped container |
docker rename <container_name> <new_name> | Rename a container |
docker cp CONTAINER:SRC_PATH DEST_PATH | Copies files or folders between a container and the local filesystem. |
docker export <container> > out.tar | Turns containers filesystem into a tarball archive stream to STDOUT |
Image Commands
Command | Description |
---|---|
docker images | List all docker images |
docker search <patial_image_name> | Searches Repo for images containing the name specified |
docker run -i -t ubuntu:12.10 bash | Download ubuntu 12.10 image and run bash |
docker pull <image> | Download an image from docker repo |
docker inspect <image> | Inspect docker image |
docker rmi <image> <image> | Remove one or more images |
docker login docker push <image> | Submit an image to docker's repo. |
docker build -f Dockerfile . | Build a docker image from a Dockerfile |
docker commit <containerID> <imageName> | Saves the container to an image |
docker save -o image.tar <imageName> | Save an image to a tar file. |
docker load -i image.tar | Load an image from a tar file. |
docker system prune -a | Remove any stopped containers and all unused images |
docker image tag <image> <DOCKER_REPO>/<image> | Tag and push an image to a new container registry. |
System Commands
docker system prune -a | Remove any stopped containers and all unused images |
docker volume prune | Remove volumes |
Advanced Commands
Run Options | Description |
---|---|
-v, --volume=[host-src:]container-dest[:<options>]: ex. docker run -d -p 443:443 --name gitlab --volume=/share/Volume/GITLAB:/var/opt/gitlabgitlab/gitlab-ce | Mount a volume. The comma-delimited `options` are [rw|ro], [z|Z], [[r]shared|[r]slave|[r]private], and [nocopy]. The 'host-src' isan absolute path or a name value. If neither 'rw' or 'ro' is specified then the volume is mounted in read-write mode. The `nocopy` modes is used to disable automatic copying requested volume path in the container to the volume storage location. For named volumes, `copy` is the default mode. Copy modes are not supported for bind-mounted volumes. --volumes-from="": Mount all volumes from the given container(s) |
Installing a set version of Docker
Command | Description |
---|---|
apt-get install -y -q docker-engine=1.11.1-0~trusty | Install a particular version of docker |
References
Reference | URL |
---|---|
Tutorial | https://www.youtube.com/watch?v=JBtWxj9l7zM |
Remove docker images, containers and volumes | https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes |