3.3 docker pull && docker push
|
1
|
$ sudo docker pull ubuntu # 下载官方 ubuntu docker 镜像,默认下载所有 ubuntu 官方库镜像
|
|
1
|
$ sudo docker pull ubuntu:14.04 # 下载指定版本 ubuntu 官方镜像
|
|
1
|
$ sudo docker push 192.168.0.100:5000/ubuntu # 推送镜像库到私有源[可注册 docker 官方账户,推送到官方自有账户]
|
|
1
|
$ sudo docker push 192.168.0.100:5000/ubuntu:14.04 # 推送指定镜像到私有源
|
3.4 docker images
|
1
|
$ sudo docker images # 显示当前系统镜像,不包括过渡层镜像
|
|
1
|
$ sudo docker images -a # 显示当前系统所有镜像,包括过渡层镜像
|
|
1
|
$ sudo docker images ubuntu # 显示当前系统 docker ubuntu 库中的所有镜像
|
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 12.04 ebe4be4dd427 4 weeks ago 210.6 MB
ubuntu 14.04 e54ca5efa2e9 4 weeks ago 276.5MB
ubuntu 14.04-ssh 6334d3ac099a 7 weeks ago 383.2 MB
3.5 docker rmi 删除镜像
|
1
|
[root@xiaozuoquan ~]# docker images
|
REPOSITORY TAG IMAGE ID CREATED SIZE
kiwenlau/hadoop 1.0 a96b45d40715 11 days ago 729MB
ubuntu 14.04 c32fae490809 3 weeks ago 188MB
hello-world latest 2cb0d9787c4d 2 months ago 1.85kB
kiwenlau/hadoop <none> a59a34125272 2 years ago 829MB
|
1
|
[root@xiaozuoquan ~]# docker rmi hello-world
|
Untagged: hello-world:latestUntagged: hello-world@sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdcDeleted: sha256:2cb0d9787c4dd17ef9eb03e512923bc4db10add190d3f84af63b744e353a9b34Deleted: sha256:ee83fc5847cb872324b8a1f5dbfd754255367f4280122b4e2d5aee17818e31f5
3.6 docker run
分配名称并分配伪TTY( - name,-it)
|
1
2
3
4
5
6
7
|
$ docker run --name test -it debian
root@d6c0fe130dba:/# exit 13
$ echo $?
13
$ docker ps -a | grep test
d6c0fe130dba debian:7 "/bin/bash" 26 seconds ago Exited (13) 17 seconds ago
|
此示例使用debian:latest镜像运行名为test的容器。 -it指示Docker分配连接到容器stdin的伪TTY; 在容器中创建交互式bash shell。
在该示例中,通过输入exit 13退出bash shell。此退出代码被传递给docker run的调用者,并记录在测试容器的元数据中。
捕获容器ID(--cidfile)
|
1
|
$ docker run --cidfile /tmp/docker_test.cid ubuntu echo "test"
|
这将为控制台创建容器和打印测试。 cidfile标志使Docker尝试创建一个新文件并将容器ID写入其中。
如果文件已存在,Docker将返回错误。 Docker运行退出时,Docker将关闭此文件。
完整的容器功能( - 特权)
|
1
2
3
|
$ docker run -t -i --rm ubuntu bash
root@bc338942ef20:/# mount -t tmpfs none /mnt
mount: permission denied
|
这不起作用,因为默认情况下,大多数潜在危险的内核功能都会被删除;
包括cap_sys_admin(挂载文件系统所需)。 但是,--privileged标志将允许它运行:
|
1
2
3
4
5
|
$ docker run -t -i --privileged ubuntu bash
root@50e3f57e16e6:/# mount -t tmpfs none /mnt
root@50e3f57e16e6:/# df -h
Filesystem Size Used Avail Use% Mounted on
none 1.9G 0 1.9G 0% /mnt
|
-privileged标志为容器提供了所有功能,它还解除了设备cgroup控制器强制执行的所有限制。
换句话说,容器几乎可以完成主机可以执行的所有操作。 此标志存在以允许特殊用例,例如在Docker中运行Docker。
本文详细介绍了Docker的基本操作,包括如何拉取和推送镜像,展示镜像列表,以及如何创建、管理和删除容器。同时,文章还深入探讨了如何使用高级选项如--privileged来增强容器的功能。
582

被折叠的 条评论
为什么被折叠?



