Docker学习4 - 增删改查
像数据库一样, docker中对于image, instance也有自己的增删改查操作
在前面我们在运行hello world程序的时候,对于大概的流程已经有了一个了解,现在我们大概的总结一下
像数据库一样, docker中对于image, instance也有自己的增删改查操作
增加
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:01
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe11:1/64 Scope:Link
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:24 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2690 (2.6 KB) TX bytes:648 (648.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
64 bytes from 192.168.56.101: icmp_seq=1 ttl=64 time=0.252 ms
64 bytes from 192.168.56.101: icmp_seq=2 ttl=64 time=0.087 ms
64 bytes from 192.168.56.101: icmp_seq=3 ttl=64 time=0.084 ms
^C
--- 192.168.56.101 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.084/0.141/0.252/0.078 ms
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/docker-253:1-201487135-94dc722fc8f8eab8ed720f92efbbc841665f994f7080ea0be21e3bd2c8cd1a63 9.8G 245M 9.0G 3% /
tmpfs 3.9G 0 3.9G 0% /dev
shm 64M 0 64M 0% /dev/shm
tmpfs 3.9G 0 3.9G 0% /run/secrets
/dev/mapper/centos-root 50G 2.6G 48G 6% /etc/hosts
tmpfs 3.9G 0 3.9G 0% /proc/kcore
tmpfs 3.9G 0 3.9G 0% /proc/timer_stats、
root@94dc722fc8f8:/# fdisk -l
Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
root@4d846810260e:/#
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d846810260e ubuntu:latest "/bin/bash" 40 seconds ago Exited (0) 8 seconds ago named_container
9dfadd6cae2dfe204d8ec135300fbaba2637b024c8ae9ca57c9f25a30b685275
Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e4cf01bce7e2 ubuntu:latest "/bin/bash -C 'while 20 seconds ago Exited (127) 19 seconds ago daemon_container
[root@centos7-docker ~]# docker logs daemon_container
hello world
hello world
hello world
hello world
hello world
UID PID PPID C STIME TTY TIME CMD
root 5879 1064 0 15:31 ? 00:00:00 /bin/sh -c while true; do echo hello world; sleep 1; done
root 5985 5879 0 15:32 ? 00:00:00 sleep 1
删除
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker-whale latest beda7d481894 5 days ago 255.5 MB
Untagged: docker-whale:latest
Deleted: beda7d4818948a398cd3526158c2f373ffd4516ca8855f1e03baff2ce09de42d
Deleted: 71517881cee5b6704029758530c1c0e56ded612561cbe90a8b7aa5fefe475cd2
[root@centos7-docker ~]# docker stop determined_morse
determined_morse
停止
[root@centos7-docker ~]# docker kill 94dc722fc8f8
94dc722fc8f8
杀死
[root@centos7-docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c9f942ce05a ubuntu:latest "/bin/bash" 18 hours ago Exited (0) 17 seconds ago determined_morse
94dc722fc8f8 ubuntu:latest "/bin/bash" 4 days ago Exited (137) 4 seconds ago hungry_leakey
更新
查询
[root@centos7-docker ~]# docker images
列出所有的image
[root@centos7-docker ~]# docker ps
列出active的容器
[root@centos7-docker ~]# docker ps -a
列出所有的容器
能看见“CONTAINER ID”,“NAMES”等列
[root@centos7-docker ~]# docker start determined_morse
这里使用的是NAME来标识容器
[root@centos7-docker ~]# docker start 94dc722fc8f8
这里使用UUID来标识容器
[root@centos7-docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c9f942ce05a ubuntu:latest "/bin/bash" 18 hours ago Up 3 minutes determined_morse
94dc722fc8f8 ubuntu:latest "/bin/bash" 4 days ago Up 6 seconds hungry_leakey
这个时候我们可以看见状态都变了
docker重新启动的时候,会沿用docker run命令时指定的参数来运行
[root@centos7-docker ~]# docker attach determined_morse
root@1c9f942ce05a:/#
使用docker attach 也可以重新附着到容器上
[root@centos7-docker ~]# docker restart determined_morse
重启
[root@centos7-docker ~]# docker logs determined_morse
查看容器日志,看容器内部都在干什么
[root@centos7-docker ~]# docker top determined_morse
查看容器内的进程
我们有时候也需要在docker中给容器运行一些进程,可以分成后台任务和交互式任务
[root@centos7-docker ~]# docker exec -d determined_morse touch /tmp/test.txt
touch创建/tmp/test.txt
[root@centos7-docker ~]# docker exec -t -i determined_morse /bin/bash
root@1c9f942ce05a:/#
交互式任务,进入容器打开shell
root@1c9f942ce05a:/# ll /tmp/test.txt
-rw-r--r-- 1 root root 0 Aug 1 03:23 /tmp/test.txt
测试刚才通过后台任务新建的文件
[root@centos7-docker ~]# docker inspect determined_morse
深入获取容器的信息
更多推荐
所有评论(0)