Docker安装配置教程入门到精通

之前docker很久就写了笔记了。后面因为家里有事,耽搁了一年。 现在把这部分笔记重新上传一下。大家看看。

Docker要求:
lunix内核,要求3.8以上
centos7
Docker是一个进程,一启动就两个进程,一个服务,一个守护进程。占用资源就非常少,启动速度非常快,1s。
一台机器上vm,3到10个实例。docker 100到10000。

1.核心概念:
1)镜像images,事先做好一些基础功能(软件),可以在镜像上在来安装新的内容。
2)容器container
3)数据卷volume,把数据映射到linux磁盘目录,业务把数据写入这个目录,容器重新启动时,自己加载数据卷,数据又恢复了。有问题的。(争论,数据库这种方式需求适不适合docker)
4)仓库repository,maven仓库概念一样

2.java
类(只读) 镜像(只读,不允许修改)
对象(写临时的内容) 容器,在镜像基础上允许用户写数据,临时数据

docker
部署后台系统,
1)linux Centos7
2)安装jdk
3)安装tomcat
4)部署war包
5)启动tomcat,设置端口,访问

docker可以产生基础镜像,每加一层新的内容也形成新的镜像。每个镜像都可以去在加新的内容。变化无穷,复用资源。

加载虚拟机的vm镜像,先不要打开。

然后,设置好虚拟机软件的vm。

NAT模式查询网关配置,上网(注意,设置请根据自己的ip信息进行设置。目的是为了保持网关、子网掩码一致,ip地址网段一致,ip地址不一样)

设置OK后,使用其使设置生效。

重载一下网络配置

centos7 命令发生巨大变化

p addr #查看IP地址 ip add
service network restart #重启网络
systemctl restart network.service #重启网络centos7
vi /etc/hosts #127.0.0.1 dredis
hostname dreids #注意必须修改机器名hostname
ping www.baidu.com #如果出现baidu的ip地址则表示网络连通
1
2
3
4
5
6

1.1.1安装Docker
1.1.1.1第一步:安装工具包

$ sudo yum install -y yum-utils #安装工具包,缺少这些依赖将无法完成
1
执行结果:

Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
update | 3.4 kB 00:00:00
(1/3): epel/7/x86_64/updateinfo | 797 kB 00:00:00
(2/3): epel/7/x86_64/primary_db | 4.7 MB 00:00:00
(3/3): update/7/x86_64/primary_db | 4.8 MB 00:00:00
Loading mirror speeds from cached hostfile
Package yum-utils-1.1.31-40.el7.noarch already installed and latest version
Nothing to do
1
2
3
4
5
6
7
8
9
10
11
1.1.1.2第二步:设置远程仓库

$sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
执行结果:
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
1
2
3
4
5
6
1.1.1.3第三步:安装

$ sudo yum install docker-ce
执行结果:
Loaded plugins: fastestmirror, langpacks
docker-ce-stable | 2.9 kB 00:00:00
docker-ce-stable/x86_64/primary_db | 4.8 kB 00:00:00
Loading mirror speeds from cached hostfile
Resolving Dependencies
–> Running transaction check
—> Package docker-ce.x86_64 0:17.03.1.ce-1.el7.centos will be installed
–> Processing Dependency: docker-ce-selinux >= 17.03.1.ce-1.el7.centos for package: docker-ce-17.03.1.ce-1.el7.centos.x86_64
–> Processing Dependency: libcgroup for package: docker-ce-17.03.1.ce-1.el7.centos.x86_64
–> Processing Dependency: libseccomp.so.2()(64bit) for package: docker-ce-17.03.1.ce-1.el7.centos.x86_64
–> Running transaction check
—> Package docker-ce-selinux.noarch 0:17.03.1.ce-1.el7.centos will be installed
–> Processing Dependency: policycoreutils-python for package: docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch
—> Package libcgroup.x86_64 0:0.41-11.el7 will be installed
—> Package libseccomp.x86_64 0:2.3.1-2.el7 will be installed
–> Running transaction check
—> Package policycoreutils-python.x86_64 0:2.5-11.el7_3 will be installed
–> Processing Dependency: setools-libs >= 3.3.8-1 for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Processing Dependency: libsemanage-python >= 2.5-5 for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64
–> Running transaction check
—> Package audit-libs-python.x86_64 0:2.6.5-3.el7_3.1 will be installed
—> Package checkpolicy.x86_64 0:2.5-4.el7 will be installed
—> Package libsemanage-python.x86_64 0:2.5-5.1.el7_3 will be installed
—> Package python-IPy.noarch 0:0.75-6.el7 will be installed
—> Package setools-libs.x86_64 0:3.3.8-1.1.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================
Package Arch Version Repository Size

Installing:
docker-ce x86_64 17.03.1.ce-1.el7.centos docker-ce-stable 19 M
Installing for dependencies:
audit-libs-python x86_64 2.6.5-3.el7_3.1 update 70 k
checkpolicy x86_64 2.5-4.el7 base 290 k
docker-ce-selinux noarch 17.03.1.ce-1.el7.centos docker-ce-stable 28 k
libcgroup x86_64 0.41-11.el7 base 65 k
libseccomp x86_64 2.3.1-2.el7 base 56 k
libsemanage-python x86_64 2.5-5.1.el7_3 update 104 k
policycoreutils-python x86_64 2.5-11.el7_3 update 445 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.8-1.1.el7 base 612 k

Transaction Summary

Install 1 Package (+9 Dependent packages)

Total download size: 20 M
Installed size: 24 M
Is this ok [y/d/N]: y
Downloading packages:
(1/10): audit-libs-python-2.6.5-3.el7_3.1.x86_64.rpm | 70 kB 00:00:00
(2/10): checkpolicy-2.5-4.el7.x86_64.rpm | 290 kB 00:00:00
(3/10): libseccomp-2.3.1-2.el7.x86_64.rpm | 56 kB 00:00:00
(4/10): libcgroup-0.41-11.el7.x86_64.rpm | 65 kB 00:00:00
(5/10): policycoreutils-python-2.5-11.el7_3.x86_64.rpm | 445 kB 00:00:00
(6/10): setools-libs-3.3.8-1.1.el7.x86_64.rpm | 612 kB 00:00:00
(7/10): libsemanage-python-2.5-5.1.el7_3.x86_64.rpm | 104 kB 00:00:00
(8/10): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm is not installed
(9/10): docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm | 28 kB 00:00:00
(10/10): docker-ce-17.03.1.ce-1.el7.centos.x86_64.rpm | 19 MB 00:00:00

Total 23 MB/s | 20 MB 00:00:00
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : “Docker Release (CE rpm) [email protected]
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libcgroup-0.41-11.el7.x86_64 1/10
Installing : setools-libs-3.3.8-1.1.el7.x86_64 2/10
Installing : checkpolicy-2.5-4.el7.x86_64 3/10
Installing : libsemanage-python-2.5-5.1.el7_3.x86_64 4/10
Installing : audit-libs-python-2.6.5-3.el7_3.1.x86_64 5/10
Installing : python-IPy-0.75-6.el7.noarch 6/10
Installing : policycoreutils-python-2.5-11.el7_3.x86_64 7/10
Installing : docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch 8/10
setsebool: SELinux is disabled.
libsemanage.semanage_direct_install_info: Overriding docker module at lower priority 100 with module at priority 400.
Installing : libseccomp-2.3.1-2.el7.x86_64 9/10
Installing : docker-ce-17.03.1.ce-1.el7.centos.x86_64 10/10
Verifying : libseccomp-2.3.1-2.el7.x86_64 1/10
Verifying : python-IPy-0.75-6.el7.noarch 2/10
Verifying : audit-libs-python-2.6.5-3.el7_3.1.x86_64 3/10
Verifying : libsemanage-python-2.5-5.1.el7_3.x86_64 4/10
Verifying : docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch 5/10
Verifying : libcgroup-0.41-11.el7.x86_64 6/10
Verifying : policycoreutils-python-2.5-11.el7_3.x86_64 7/10
Verifying : docker-ce-17.03.1.ce-1.el7.centos.x86_64 8/10
Verifying : checkpolicy-2.5-4.el7.x86_64 9/10
Verifying : setools-libs-3.3.8-1.1.el7.x86_64 10/10

Installed:
docker-ce.x86_64 0:17.03.1.ce-1.el7.centos

Dependency Installed:
audit-libs-python.x86_64 0:2.6.5-3.el7_3.1 checkpolicy.x86_64 0:2.5-4.el7
docker-ce-selinux.noarch 0:17.03.1.ce-1.el7.centos libcgroup.x86_64 0:0.41-11.el7
libseccomp.x86_64 0:2.3.1-2.el7 libsemanage-python.x86_64 0:2.5-5.1.el7_3
policycoreutils-python.x86_64 0:2.5-11.el7_3 python-IPy.noarch 0:0.75-6.el7
setools-libs.x86_64 0:3.3.8-1.1.el7

Complete!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
1.1.1.4第四步:启动

$ sudo systemctl start docker
或者
$ sudo service docker start
service docker start #启动docker
chkconfig docker on #加入开机启动
1
2
3
4
5
第五步:查看版本

$ sudo docker version
执行结果:
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Mon Mar 27 17:05:44 2017
OS/Arch: linux/amd64
1
2
3
4
5
6
7
8
9
1.1.1.6第六步:校验

$ sudo docker run hello-world
1
执行结果: (注意一下,结果没那么快出来)

Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
  3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1.1.2查看Docker版本

docker --help #帮助
docker –v #简单查看版本
docker version #查看版本

Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64
1
2
3
4
5
6
7
8
9
10
docker info #查看信息

Containers: 0
Images: 2
Storage Driver: devicemapper
Pool Name: docker-253:0-34097258-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 308.3 MB
Data Space Total: 107.4 GB
Data Space Available: 16.08 GB
Metadata Space Used: 782.3 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.107-RHEL7 (2015-10-14)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
CPUs: 4
Total Memory: 985.6 MiB
Name: localhost.localdomain
ID: B5ZW:FJXF:FNUD:OLH7:FCNI:56DJ:XEQY:I6J4:PPHQ:OKRW:CIJK:Y26P
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1.1.3安装其它产品的两种方式

docker安装其它产品有两种方式
方式一:通过拉取事先做好的镜像,例如下面redis的安装方式
方式二:通过Dockerfile来构建新的镜像,例如下面tomcat的安装方式

1.1.4组成结构
docker会自动给docker容器配置一个vip虚拟ip地址
bash-4.1#提示符就代表进入docker容器内部

你可能感兴趣的:(Docker安装配置教程入门到精通)