第一章:Docker介绍与安装
第一章:Docker介绍与安装
1.Docker介绍与体系结构


[root@linux-node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oldboy/shop-api latest 2ac83745299f 7 days ago 450 MB
oldboy/shop-api v2 07dd68a9994f 7 days ago 450 MB
<none> <none> 6ab8a9b680b3 7 days ago 450 MB
oldboy/python-ssh latest 42ffd40381a9 7 days ago 445 MB
oldboy/centos-ssh latest 26c40f0d8733 3 weeks ago 288 MB
oldboy/python latest b355734f508c 3 weeks ago 444 MB
oldboy/centos base 213b5013eaee 3 weeks ago 287 MB
mynginx v2 0c2957cf84f1 3 weeks ago 286 MB
oldboy/mynginx v1 88b17e9218ff 3 weeks ago 403 MB
docker.io/nginx latest 7f70b30f2cc6 4 weeks ago 109 MB
docker.io/centos latest 2d194b392dd1 6 weeks ago 195 MB
docker.io/vmware/admiral latest f4de8d3835ad 3 months ago 522 MB
[root@linux-node1 ~]# docker ps -a -q
13c08f008c57
2cab48d10427
f3cae38657d1
64e982c944ff
af2232211e0b
902b7a8743a1
3a858800beca
45cfaca427e8
[root@linux-node1 ~]# docker rm -f $(docker ps -a -q)
13c08f008c57
2cab48d10427
f3cae38657d1
64e982c944ff
af2232211e0b
902b7a8743a1
3a858800beca
45cfaca427e8
[root@linux-node1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@linux-node1 ~]# yum install -y pstree
[root@linux-node1 ~]# docker run -d centos ping baidu.com
519feb41f651724dcfbf0e7e2f6c444518559f7d8c920d66960caa2a3ad6e67f
[root@linux-node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
519feb41f651 centos "ping baidu.com" 26 seconds ago Up 23 seconds determined_blackwell
[root@linux-node1 ~]# ps axjf
1 1649 1649 1649 ? -1 Ssl 0 5:33 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/
1649 33865 33865 33865 ? -1 Ssl 0 1:03 \_ /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcon
33865 89372 89372 33865 ? -1 Sl 0 0:00 \_ /usr/bin/docker-containerd-shim-current 519feb41f651724dcfbf0e7
89372 89390 89390 89390 ? -1 Ss 0 0:01 \_ ping baidu.com
2.docker内部组件、容器和虚拟机区别

[root@linux-node1 ~]# docker exec -it 519feb41f651 sh
sh-4.2# ls
anaconda-post.log bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
sh-4.2# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 13:38 ? 00:00:01 ping baidu.com
root 5 0 1 13:41 ? 00:00:00 sh
root 10 5 0 13:41 ? 00:00:00 ps -ef
sh-4.2# id
uid=0(root) gid=0(root) groups=0(root)
sh-4.2# ifconfig
sh: ifconfig: command not found
sh-4.2# exit
exit
[root@linux-node1 ~]# ll /sys/fs/cgroup/
total 0
drwxr-xr-x 4 root root 0 Mar 28 15:54 blkio
lrwxrwxrwx 1 root root 11 Mar 28 15:54 cpu -> cpu,cpuacct
lrwxrwxrwx 1 root root 11 Mar 28 15:54 cpuacct -> cpu,cpuacct
drwxr-xr-x 4 root root 0 Mar 28 15:54 cpu,cpuacct
drwxr-xr-x 3 root root 0 Mar 28 15:54 cpuset
drwxr-xr-x 4 root root 0 Mar 28 16:42 devices
drwxr-xr-x 3 root root 0 Mar 28 15:54 freezer
drwxr-xr-x 3 root root 0 Mar 28 15:54 hugetlb
drwxr-xr-x 4 root root 0 Mar 28 15:54 memory
lrwxrwxrwx 1 root root 16 Mar 28 15:54 net_cls -> net_cls,net_prio
drwxr-xr-x 3 root root 0 Mar 28 15:54 net_cls,net_prio
lrwxrwxrwx 1 root root 16 Mar 28 15:54 net_prio -> net_cls,net_prio
drwxr-xr-x 3 root root 0 Mar 28 15:54 perf_event
drwxr-xr-x 3 root root 0 Mar 28 15:54 pids
drwxr-xr-x 4 root root 0 Mar 28 15:54 systemd


3.docker应用场景
Docker技术这些应用场景,你知道吗?
http://blog.51cto.com/lizhenliang/1978081

4.linux环境下安装docker
官网:https://docs.docker.com/
Get Docker CE for CentOS
https://docs.docker.com/install/linux/docker-ce/centos/#install-using-the-repository


企业版EE和社区版CE。
[root@linux-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@linux-node1 ~]# uname -a
Linux linux-node1 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
(1)安装依赖软件包:
yum install -y yum-utils device-mapper-persistent-data lvm2
(2)配置官方源:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@linux-node1 ~]# ll /etc/yum.repos.d/docker-ce.repo
-rw-r--r-- 1 root root 2568 Apr 22 00:35 /etc/yum.repos.d/docker-ce.repo
(3)安装社区版、最新版:
yum -y install docker-ce
安装后启动docker服务:
[root@linux-node1 ~]# systemctl start docker
查看详情:
[root@linux-node1 ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.03.0-ce
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfd04396dc68220d1cecbe686a6cc3aa5ce3667c
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-693.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.938GiB
Name: linux-node1
ID: 2LBO:LY5Z:UNVW:MURG:TRWB:7VLQ:7OW2:3VPX:QBVS:O3BB:665R:2IGR
Docker Root Dir: /var/lib/docker //docker工作目录
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/ //默认下载网址
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
[root@linux-node1 ~]# ls /var/lib/docker/
builder containerd containers image network overlay2 plugins runtimes swarm tmp trust volumes
时区不对要调整时区:
[root@linux-node1 ~]# date
Mon Apr 23 20:31:10 CST 2018
[root@linux-node1 ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: ‘/usr/share/zoneinfo/Asia/Shanghai’ and ‘/etc/localtime’ are the same file
[root@linux-node1 ~]# docker pull nginx
//国外镜像下载比较慢,可配置其他镜像源。
Using default tag: latest
latest: Pulling from library/nginx
2a72cbf407d6: Pull complete
04b2d3302d48: Pull complete
e7f619103861: Pull complete
Digest: sha256:18156dcd747677b03968621b2729d46021ce83a5bc15118e5bcced925fb4ebb9
Status: Downloaded newer image for nginx:latest
[root@linux-node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest b175e7467d66 12 days ago 109MB
浙公网安备 33010602011771号