获取镜像busybox
# sudo docker pull busybox
latest: Pulling from busybox
56ed16bd6310: Pull complete
bc744c4ab376: Pull complete
Digest: sha256:4a887a2326ec9e0fa90cce7b4764b0e627b5d6afcb81a3f73c85dc29cea00048
Status: Downloaded newer image for busybox:latest
查看本地镜像列表
# sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 7bd023c8937d 25 hours ago 122 MB
busybox latest bc744c4ab376 10 weeks ago 1.113 MB
查看镜像详细信息
# sudo docker inspect bc744c4ab376
[{
"Architecture": "amd64",
"Author": "",
"Comment": "",
......
查找镜像
# sudo docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating s... 3995 [OK]
ubuntu-upstart Upstart is an event-based replacement for ... 63 [OK]
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 27 [OK]
删除本地镜像
- rm Remove one or more containers
- rmi Remove one or more images
# sudo docker rmi bc744c4ab376
Error response from daemon: Conflict, cannot delete bc744c4ab376 because the container 18bf2972ebd8 is using it, use -f to force
FATA[0000] Error: failed to remove one or more images
先删除依赖镜像
# sudo docker rm 18bf2972ebd8
18bf2972ebd8
# sudo docker rmi bc744c4ab376
Untagged: busybox:latest
Deleted: bc744c4ab376115cc45c610d53f529dd2d4249ae6b35e5d6e7a96e58863545aa
Deleted: 56ed16bd6310cca65920c653a9bb22de6b235990dcaa1742ff839867aed730e5
创建镜像
创建镜像有三种方法:
- 基于已有镜像的容器创建
- 基于本地模板导入
- 基于Dockerfile创建
基于已有镜像:使用docker commit命令
# sudo docker run -ti ubuntu:latest /bin/bash
root@9cc317a7ba54:/#
其中9cc317a7ba54为ubuntu运行中容器ID
-m --message = "" 提交消息
-a --authro = "" 作者信息
# sudo docker commit -m "Added a new dir /home/hqi" -a "hqi" 9cc317a7ba54 newbee_docker
8be5ada16b2d908640e018c3b31a2d43a7e5f12b575863dc840316300da39290
基于本地模板导入:推荐OpenVZ提供的模板
存入镜像
# sudo docker save -o ubuntu_0529.tar ubuntu:latest
# ls -l ubuntu_0529.tar
-rw-r--r-- 1 root root 127697408 5?.29 00:49 ubuntu_0529.tar
载入镜像(但是我载入后通过docker images没有查看到)
# sudo docker load < ./ubuntu_0529.tar