安装docker18.06.1-ce

1.添加docker-ce yum源

安装扩展yum功能,以便使用yum-config-manager添加docker软件源信息

1
2
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2.查看当前可以安装docker-ce版本

安装指定版本的格式 ,注意3:xxx 请移除3: 我这里使用docker-ce-18.06.1.ce-3.el7

1
2
3
yum list docker-ce --showduplicates | sort -r
yum -y install docker-ce-[VERSION]
yum install -y docker-ce-18.06.1.ce-3.el7

3.启动测试

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
systemctl start docker && systemctl enable docker
docker info

Containers: 15
Running: 12
Paused: 0
Stopped: 3
Images: 26
Server Version: 18.06.1-ce
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: systemd
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: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
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: 2
Total Memory: 7.585GiB
Name: k8s-node3
ID: 5BLO:XOV2:EFX3:5SXB:M2JF:L6D7:TWGR:UQ6E:A56P:MXAZ:TTQR:R2DG
Docker Root Dir: /var/lib/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

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

安装docker-compose

1.下载docker-compose

1
curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

2.赋予docker-compose全局可执行权

1
2
3
4
chmod +x /usr/local/bin/docker-compose && ln -s /usr/local/bin/docker-compose /usr/bin/
docker-compose --version

docker-compose version 1.18.0, build 8dd22a9

docker-compose java项目目录规划

1.环境描述

  • docker:18.06.1-ce
  • docker-comepose:1.18.0
  • vue 2 && npm 14.17.3
  • java1.8

    2.文件目录解释

  • config目录:config目录内放项目运行所需要挂载进容器的配置文件及数据文件
  • import-base-image目录:docker save所保留下的tar归档基础镜像文件,例:java:8、mysql:8、nginx:1.21.3等,还有docker load镜像的脚本
  • java目录:每个java项目在java目录内单独一个目录,目录内放置jar包、Dockerfile、build.sh(打包镜像所用脚本)
  • docker-compose.yml : 我所理解的docker-compose.yml跟k8s内的资源清单一样,就是docker-compose编排配置文件
  • build_java_image.sh:进入到所有java项目目录内,把jar包打入docker镜像内

    3.目录层级展示

    image
    image

docker-compose常用命令

  • docker-compose ps :查看运行容器
  • docker-compose up -d :后台启动容器 && 资源清单有变化镜像有更新可以更新
  • docker-compose down -v : 关闭,下线

docker-compose.yml

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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
version: '3'

networks:
data_security:
ipam:
config:
- subnet: 172.62.0.0/16 #自定义固定容器ip 实现容器间通讯,增强docker-compose项目可移植性

services:
mysql:
image: mysql:8.0.20
container_name: mysql
ports:
- 30306:3306
command:
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
environment:
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
- MYSQL_ROOT_PASSWORD=xxxxxx
privileged: true
restart: always
volumes:
- ./config/mysql/conf/my.cnf:/etc/mysql/my.cnf
- ./config/mysql/logs:/var/log/mysql
- ./config/mysql/data:/var/lib/mysql
- ./config/mysql/init:/docker-entrypoint-initdb.d/
#- ./config/mysql/sql:/opt/sql #初始化sql第一次启动mysql并导入数据可以将注释去掉,导完之后注释掉。
networks:
data_security:
ipv4_address: 172.62.0.5

gateway-service:
image: gateway-service:1.0
container_name: gateway-service
expose:
- 8999
privileged: true
restart: always
environment:
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
networks:
data_security:
ipv4_address: 172.62.0.6

group-module:
image: group-module:1.0
container_name: group-module
expose:
- 8890
privileged: true
restart: always
volumes:
- ./java/xxl-job/:/opt/
environment:
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
networks:
data_security:
ipv4_address: 172.62.0.7

core4ct-module-system:
image: core4ct-module-system:1.0
container_name: core4ct-module-system
expose:
- 8080
- 30201
privileged: true
restart: always
environment:
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
networks:
data_security:
ipv4_address: 172.62.0.8

core4ct-gateway:
image: core4ct-gateway:1.0
container_name: core4ct-gateway
expose:
- 9000
privileged: true
restart: always
environment:
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
networks:
data_security:
ipv4_address: 172.62.0.9

#province-module:
# image: province-module:1.0
# container_name: province-module
# expose:
# - 8888
# privileged: true
# restart: always
# environment:
# - TZ=Asia/Shanghai
# - LANG=en_US.UTF-8
# networks:
# data_security:
# ipv4_address: 172.62.0.10

redis:
image: redis:latest
container_name: redis
hostname: redis
restart: always
ports:
- 6379:6379
volumes:
- ./config/redis/conf/redis.conf:/etc/redis/redis.conf #挂载redis.conf不然后续重启redis密码会失效
- ./config/redis/data:/data
environment:
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
command: ["redis-server","/etc/redis/redis.conf"] #指定配置文件启动redis
networks:
data_security:
ipv4_address: 172.62.0.13

xxl-job-admin:
image: xxl-job-admin:1.0
container_name: xxl-job-admin
ports:
- 30998:8998
#- 30988:9988
restart: always
environment:
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
networks:
data_security:
ipv4_address: 172.62.0.11

nginx:
image: nginx:1.21.3
container_name: nginx-group
ports:
- 30028:80
restart: always
volumes:
- ./config/nginx/:/etc/nginx/
- ./config/html/dist/:/usr/share/nginx/html/
environment:
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
networks:
data_security:
ipv4_address: 172.62.0.12

# nginx-province:
# image: province-frontend:1.20.1
# container_name: nginx-province
# ports:
# - 30029:443
# restart: always
# volumes:
# - ./config/nginx-province/:/etc/nginx/
# - ./config/html-province/dist/:/usr/share/nginx/html/
# environment:
# - TZ=Asia/Shanghai
# - LANG=en_US.UTF-8
# networks:
# data_security:
# ipv4_address: 172.62.0.22
#