View all commands:
$ docker
Search for images
$ docker search <string>
Download image:
$ docker pull <username>/<repository>
Usually we can specify a container with the first three or four digits of its ID.
Inspect a container:
$ docker inspect <containerid>
Access a running container:
$ docker exec -it <container-name/-id> bash
View logs of a container:
$ docker logs -f <container-id/-name>
View the host port that a container app's port maps:
$ docker port <container_name> <container_app_port>
Run a command from an image/container:
$ docker run <username>/<repository> <command args...>
Run the image on the same network stack of the host:
$ docker run --net=host <username>/<image>
Install things to a Ubuntu image (use -y
flag to disable interactive download mode.)
$ docker run <username>/<ubuntu_image> apt-get install -y <software>
Push an image (you can only push an image under your namespace):
$ docker push <username/repository>
Print image logs (-f
acts like tail -f
):
$ sudo docker logs -f <container_id>
Examine processes running inside a container:
$ docker top <container_name>
Inspect a container:
$ docker inspect <container_name>
$ docker inspect -f '{{ .NetworkSettings.IPAddress }}' <container_name>
(Re)start a container:
$ docker start <container_name>
$ docker restart <container_name>
Find out container id:
$ docker ps --latest
Save this container with a new repository name:
$ docker commit <containerid> <username/new_repo>
Look up container id(s):
$ docker ps -a | grep <image_name>
Stop running the container:
$ docker stop <container_id>
```
Remove container:
``` bash
$ docker rm <container_id>
```
Remove image:
``` bash
$ docker rmi <image_id>
```
### Delete all docker containers
List all docker containers:
``` bash
$ docker ps -a
```
Kill and delete all docker containers:
``` bash
$ docker rm $(docker kill $(docker ps -q))
```
### Delete all docker images
List all installed docker image ids:
``` bash
$ docker images -q
```
Delete all docker images:
``` bash
$ docker rmi $(docker images -q)
```