[docker] 初學筆記

常用指令整理.

How to remove old Docker containers

$ docker ps --filter "status=exited" | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm

Run with image

$ docker run -it <image_name> /bin/bash
$ docker run -p 8080:8080 <image_name>

Enter the existed container.

$ docker exec -it <container_id> /bin/bash

List images

$ docker images

List container

$ docker ps -a

Remove container

$ docker rm <container_id>load -i 

Remove images

$ docker rmi <image_id>

Docker info

$ docker info

Docker version

$ docker --version

Export images as file

$ docker save -o <file_name> <image_name>

Import images by file

$ docker load -i -i <file_name>

Start/Stop/Restart container

$docker start <container_id>
$docker stop <container_id>
$docker restart <container_id>

Export container as file

$ docker export <container_id> > <file_name>

Import container as file

$ cat <file_name>| docker import - <image_name>