跟着狂神学Docker(精髓篇)

容器数据卷

什么是容器数据卷

docker的理念回顾

将应用和环境打包成一个镜像!

数据?如果数据都在容器中,那么我们容器删除,数据就会丢失!需求:数据可以持久化

MySQL,容器删除了,删库跑路!需求:MySQL数据可以存储在本地!

容器之间可以有一个数据共享的技术!Docker容器中产生的数据,同步到本地!

这就是卷技术!目录的挂载,将我们容器内的目录,挂载到Linux上面!

跟着狂神学Docker(精髓篇)_第1张图片
总结一句话:容器的持久化和同步操作!容器间也是可以数据共享的!

使用数据卷

方式一 :直接使用命令挂载 -v

-v, --volume list                    Bind mount a volume

docker run -it -v 主机目录:容器内目录  -p 主机端口:容器内端口
# /home/ceshi:主机home目录下的ceshi文件夹  映射:centos容器中的/home
[root@localhost home]# docker run -it -v /home/ceshi:/home centos /bin/bash
#这时候主机的/home/ceshi文件夹就和容器的/home文件夹关联了,二者可以实现文件或数据同步了
#这里解答一下这不是同步 这是 在磁盘上使用同一个分区物理地址是一个

#新的窗口
#通过 docker inspect 容器id 查看
[root@localhost home]# docker inspect 5b1e64d8bbc0

跟着狂神学Docker(精髓篇)_第2张图片
跟着狂神学Docker(精髓篇)_第3张图片

这里解答一下这不是同步 这是 在磁盘上使用同一个分区物理地址是一个

再来测试!

1、停止容器

2、宿主机修改文件

3、启动容器

4、容器内的数据依旧是同步的
跟着狂神学Docker(精髓篇)_第4张图片
好处:我们以后修改只需要在本地修改即可,容器内会自动同步!

实战:安装MySQL

Docker商店

https://hub.docker.com/

思考:MySQL的数据持久化的问题

# 获取mysql镜像
[root@localhost home]# docker pull mysql:5.7
# 运行容器,需要做数据挂载 #安装启动mysql,需要配置密码的,这是要注意点!
# 参考官网hub 
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

#启动我们得
-d 后台运行
-p 端口映射
-v 卷挂载
-e 环境配置
-- name 容器名字
[root@localhost home]#  docker run -d -p 3306:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:5.7

# 启动成功之后,我们在本地使用sqlyog来测试一下
# sqlyog-连接到服务器的3306--和容器内的3306映射 

# 在本地测试创建一个数据库,查看一下我们映射的路径是否ok!

[root@localhost home]# ls
ceshi  huang.java  huangjialin  huang.txt  mylinux  mysql  test.java  testTmp
[root@localhost home]# cd mysql
[root@localhost mysql]# ls
conf  data
[root@localhost mysql]# cd data/
[root@localhost data]# ls
auto.cnf    client-cert.pem  ibdata1      ibtmp1              private_key.pem  server-key.pem
ca-key.pem  client-key.pem   ib_logfile0  mysql               public_key.pem   sys
ca.pem      ib_buffer_pool   ib_logfile1  performance_schema  server-cert.pem

跟着狂神学Docker(精髓篇)_第5张图片

新建数据库

跟着狂神学Docker(精髓篇)_第6张图片

多了test文件

[root@localhost data]# ls
auto.cnf    client-cert.pem  ibdata1      ibtmp1              private_key.pem  server-key.pem
ca-key.pem  client-key.pem   ib_logfile0  mysql               public_key.pem   sys
ca.pem      ib_buffer_pool   ib_logfile1  performance_schema  server-cert.pem  test

假设我们把容器删除

[root@localhost data]# docker rm -f mysql01
mysql01
[root@localhost data]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
5b1e64d8bbc0   centos    "/bin/bash"   56 minutes ago   Up 39 minutes             keen_leavitt
[root@localhost data]# docker ps -a

跟着狂神学Docker(精髓篇)_第7张图片

[root@localhost home]# ls
ceshi  huang.java  huangjialin  huang.txt  mylinux  mysql  test.java  testTmp
[root@localhost home]# cd mysql
[root@localhost mysql]# ls
conf  data
[root@localhost mysql]# cd data/
[root@localhost data]# ls
auto.cnf    client-cert.pem  ibdata1      ibtmp1              private_key.pem  server-key.pem
ca-key.pem  client-key.pem   ib_logfile0  mysql               public_key.pem   sys
ca.pem      ib_buffer_pool   ib_logfile1  performance_schema  server-cert.pem

发现,我们挂载到本地的数据卷依旧没有丢失,这就实现了容器数据持久化功能。

具名和匿名挂载

# 匿名挂载
-v 容器内路径!
[root@localhost home]# docker run -d -P --name nginx01 -v /etc/nginx nginx

# 查看所有的volume(卷)的情况
[root@localhost home]# docker volume ls    
DRIVER              VOLUME NAME # 容器内的卷名(匿名卷挂载)
local               21159a8518abd468728cdbe8594a75b204a10c26be6c36090cde1ee88965f0d0
local               b17f52d38f528893dd5720899f555caf22b31bf50b0680e7c6d5431dbda2802c
         
# 这里发现,这种就是匿名挂载,我们在 -v只写了容器内的路径,没有写容器外的路径!

# 具名挂载 -P:表示随机映射端口
[root@localhost home]# docker run -d -P --name nginx01 -v /etc/nginx nginx
a35688cedc667161695f56bd300c12a6468312558c63a634d136bf8e73db4680

# 查看所有的volume(卷)的情况
[root@localhost home]# docker volume ls
DRIVER    VOLUME NAME
local     8bef6b16668574673c31978a4d05c212609add5b4ca5ea2f09ff8680bdd304a6
local     a564a190808af4cdca228f6a0ea3664dd14e34fee81811ed7fbae39158337141

# 具名挂载
[root@localhost home]# ls
ceshi  huang.java  huangjialin  huang.txt  mylinux  mysql  test.java  testTmp
[root@localhost home]# docker run -d -P --name nginx02 -v juming-nginx:/etc/nginx nginx	#具名挂载
330f5a75c39945c6bed44292925219ed0d8d37adc0b1bc37b37784aae405b520
[root@localhost home]# docker volume ls
DRIVER    VOLUME NAME
local     8bef6b16668574673c31978a4d05c212609add5b4ca5ea2f09ff8680bdd304a6
local     a564a190808af4cdca228f6a0ea3664dd14e34fee81811ed7fbae39158337141
local     juming-nginx	# 具名挂载

# 通过 -v 卷名:查看容器内路径
# 查看一下这个卷
[root@localhost home]# docker volume inspect juming-nginx
[
    {
        "CreatedAt": "2021-04-12T06:53:09-07:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/juming-nginx/_data",
        "Name": "juming-nginx",
        "Options": null,
        "Scope": "local"
    }
]

跟着狂神学Docker(精髓篇)_第8张图片
所有的docker容器内的卷,没有指定目录的情况下都是在**/var/lib/docker/volumes/自定义的卷名/_data**下,
我们通过具名挂载可以方便的找到我们的一个卷,大多数情况在使用的具名挂载

[root@localhost home]# cd /var/lib/docker
[root@localhost docker]# ls
buildkit  containers  image  network  overlay2  plugins  runtimes  swarm  tmp  trust  volumes
[root@localhost docker]# cd volumes/
[root@localhost volumes]# ls
8bef6b16668574673c31978a4d05c212609add5b4ca5ea2f09ff8680bdd304a6  backingFsBlockDev  metadata.db
a564a190808af4cdca228f6a0ea3664dd14e34fee81811ed7fbae39158337141  juming-nginx
[root@localhost volumes]# cd juming-nginx/
[root@localhost juming-nginx]# ls
_data
[root@localhost juming-nginx]# cd _data/
[root@localhost _data]# ls
conf.d  fastcgi_params  koi-utf  koi-win  mime.types  modules  nginx.conf  scgi_params  uwsgi_params  win-utf
[root@localhost _data]# cat nginx.conf 

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

如果指定了目录,docker volume ls 是查看不到的。

区分三种挂载方式

# 三种挂载: 匿名挂载、具名挂载、指定路径挂载
-v 容器内路径			#匿名挂载
-v 卷名:容器内路径		  #具名挂载
-v /宿主机路径:容器内路径 #指定路径挂载 docker volume ls 是查看不到的

拓展:

# 通过 -v 容器内路径: ro rw 改变读写权限
ro #readonly 只读
rw #readwrite 可读可写

# 一旦这个设置了容器权限,容器对我们挂载出来的内容就有限定了!
[root@localhost home]# docker run -d -P --name nginx05 -v juming:/etc/nginx:ro nginx
[root@localhost home]# docker run -d -P --name nginx05 -v juming:/etc/nginx:rw nginx

# ro 只要看到ro就说明这个路径只能通过宿主机来操作,容器内部是无法操作!

初始Dockerfile

Dockerfile 就是用来构建docker镜像的构建文件!命令脚本!先体验一下!
通过这个脚本可以生成镜像,镜像是一层一层的,脚本是一个个的命令,每个命令都是一层!

[root@localhost /]# cd /home
[root@localhost home]# ls
ceshi  huang.java  huangjialin  huang.txt  mylinux  mysql  test.java  testTmp
[root@localhost home]# mkdir docker-test-volume
[root@localhost home]# ls
ceshi  docker-test-volume  huang.java  huangjialin  huang.txt  mylinux  mysql  test.java  testTmp
[root@localhost home]# cd docker-test-volume/
[root@localhost docker-test-volume]# pwd
/home/docker-test-volume

#通过这个脚本可以生成镜像
[root@localhost docker-test-volume]# vim dockerfile1	

# 创建一个dockerfile文件,名字可以随便 建议Dockerfile
# 文件中的内容: 指令(大写) + 参数
[root@localhost docker-test-volume]# vim dockerfile1
    FROM centos 					# 当前这个镜像是以centos为基础的

    VOLUME ["volume01","volume02"] 	# 挂载卷的卷目录列表(多个目录)

    CMD echo "-----end-----"		# 输出一下用于测试
    CMD /bin/bash					# 默认走bash控制台

[root@localhost docker-test-volume]# cat dockerfile1 
FROM centos

VOLUME ["volume01","volume02"]

CMD echo "-----end-----"
CMD /bin/bash


# 这里的每个命令,就是镜像的一层!
# 构建出这个镜像 
-f dockerfile1 			# f代表file,指这个当前文件的地址(这里是当前目录下的dockerfile1)
-t caoshipeng/centos 	# t就代表target,指目标目录(注意caoshipeng镜像名前不能加斜杠‘/’)
. 						# 表示生成在当前目录下

[root@localhost docker-test-volume]# docker build -f dockerfile1 -t huangjialin/centos:1.0 .
Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM centos
 ---> 300e315adb2f
Step 2/4 : VOLUME ["volume01","volume02"] 			# 卷名列表
 ---> Running in 2d8ae11d9994
Removing intermediate container 2d8ae11d9994
 ---> 5893b2c78edd
Step 3/4 : CMD echo "-----end-----"					# 输出 脚本命令
 ---> Running in 2483f0e77b68
Removing intermediate container 2483f0e77b68
 ---> 30bf0ad14072
Step 4/4 : CMD /bin/bash
 ---> Running in 8fee073c961b
Removing intermediate container 8fee073c961b
 ---> 74f0e59c6da4
Successfully built 74f0e59c6da4
Successfully tagged huangjialin/centos:1.0

# 查看自己构建的镜像
[root@localhost docker-test-volume]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED              SIZE
huangjialin/centos    1.0       74f0e59c6da4   About a minute ago   209MB

跟着狂神学Docker(精髓篇)_第9张图片

[root@localhost docker-test-volume]# docker run -it 74f0e59c6da4 /bin/bash
[root@0be9ef3e0f75 /]# ls -l
total 0
lrwxrwxrwx.   1 root root   7 Nov  3 15:22 bin -> usr/bin
drwxr-xr-x.   5 root root 360 Apr 12 14:38 dev
drwxr-xr-x.   1 root root  66 Apr 12 14:38 etc
drwxr-xr-x.   2 root root   6 Nov  3 15:22 home
lrwxrwxrwx.   1 root root   7 Nov  3 15:22 lib -> usr/lib
lrwxrwxrwx.   1 root root   9 Nov  3 15:22 lib64 -> usr/lib64
drwx------.   2 root root   6 Dec  4 17:37 lost+found
drwxr-xr-x.   2 root root   6 Nov  3 15:22 media
drwxr-xr-x.   2 root root   6 Nov  3 15:22 mnt
drwxr-xr-x.   2 root root   6 Nov  3 15:22 opt
dr-xr-xr-x. 253 root root   0 Apr 12 14:38 proc
dr-xr-x---.   2 root root 162 Dec  4 17:37 root
drwxr-xr-x.  11 root root 163 Dec  4 17:37 run
lrwxrwxrwx.   1 root root   8 Nov  3 15:22 sbin -> usr/sbin
drwxr-xr-x.   2 root root   6 Nov  3 15:22 srv
dr-xr-xr-x.  13 root root   0 Apr  7 10:09 sys
drwxrwxrwt.   7 root root 145 Dec  4 17:37 tmp
drwxr-xr-x.  12 root root 144 Dec  4 17:37 usr
drwxr-xr-x.  20 root root 262 Dec  4 17:37 var
drwxr-xr-x.   2 root root   6 Apr 12 14:38 volume01
drwxr-xr-x.   2 root root   6 Apr 12 14:38 volume02

跟着狂神学Docker(精髓篇)_第10张图片
这个卷和外部一定有一个同步的目录!

跟着狂神学Docker(精髓篇)_第11张图片

[root@0be9ef3e0f75 /]# exit
exit
[root@localhost docker-test-volume]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED             STATUS             PORTS                   NAMES
330f5a75c399   nginx     "/docker-entrypoint.…"   54 minutes ago      Up 54 minutes      0.0.0.0:49154->80/tcp   nginx02
a35688cedc66   nginx     "/docker-entrypoint.…"   About an hour ago   Up About an hour   0.0.0.0:49153->80/tcp   nginx01
[root@localhost docker-test-volume]# docker run -it 74f0e59c6da4 /bin/bash
[root@f8bd9a180286 /]# cd volume01
[root@f8bd9a180286 volume01]# touch container.txt
[root@f8bd9a180286 volume01]# ls
container.txt

查看一下卷挂载的路径

# docker inspect 容器id
$ docker inspect ca3b45913df5

# 另一个窗口
[root@localhost home]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED          SIZE
huangjialin/centos    1.0       74f0e59c6da4   18 minutes ago   209MB
tomcat02.1.0          latest    f5946bde7e99   5 hours ago      672MB
tomcat                8         926c7fd4777e   35 hours ago     533MB
tomcat                latest    bd431ca8553c   35 hours ago     667MB
nginx                 latest    519e12e2a84a   2 days ago       133MB
mysql                 5.7       450379344707   2 days ago       449MB
portainer/portainer   latest    580c0e4e98b0   3 weeks ago      79.1MB
hello-world           latest    d1165f221234   5 weeks ago      13.3kB
centos                latest    300e315adb2f   4 months ago     209MB
elasticsearch         7.6.2     f29a1ee41030   12 months ago    791MB
[root@localhost home]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED             STATUS             PORTS                   NAMES
f8bd9a180286   74f0e59c6da4   "/bin/bash"              3 minutes ago       Up 3 minutes                               gifted_mccarthy
330f5a75c399   nginx          "/docker-entrypoint.…"   59 minutes ago      Up 59 minutes      0.0.0.0:49154->80/tcp   nginx02
a35688cedc66   nginx          "/docker-entrypoint.…"   About an hour ago   Up About an hour   0.0.0.0:49153->80/tcp   nginx01
[root@localhost home]# docker inspect f8bd9a180286

跟着狂神学Docker(精髓篇)_第12张图片
测试一下刚才的文件是否同步出去了!

[root@localhost home]# cd /var/lib/docker/volumes/52912f4f30befa6a7039dc04b92de15a32ec5de39d3a9db3521f58212e85543d/_data
[root@localhost _data]# ls
container.txt

这种方式使用的十分多,因为我们通常会构建自己的镜像!
假设构建镜像时候没有挂载卷,要手动镜像挂载 -v 卷名:容器内路径!

数据卷容器

多个MySQL同步数据!

命名的容器挂载数据卷!

跟着狂神学Docker(精髓篇)_第13张图片

# 测试 启动3个容器,通过刚才自己写的镜像启动

[root@localhost _data]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
huangjialin/centos    1.0       74f0e59c6da4   2 hours ago     209MB
tomcat02.1.0          latest    f5946bde7e99   6 hours ago     672MB
tomcat                8         926c7fd4777e   37 hours ago    533MB
tomcat                latest    bd431ca8553c   37 hours ago    667MB
nginx                 latest    519e12e2a84a   2 days ago      133MB
mysql                 5.7       450379344707   2 days ago      449MB
portainer/portainer   latest    580c0e4e98b0   3 weeks ago     79.1MB
hello-world           latest    d1165f221234   5 weeks ago     13.3kB
centos                latest    300e315adb2f   4 months ago    209MB
elasticsearch         7.6.2     f29a1ee41030   12 months ago   791MB



# 创建docker01:因为我本机是最新版,故这里用latest,狂神老师用的是1.0如下图
[root@localhost _data]#  docker run -it --name docker01 huangjialin/centos:1.0

# 查看容器docekr01内容
[root@8e2660858dca /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  volume01	volume02



# 不关闭该容器退出
CTRL + Q + P  

# 创建docker02: 并且让docker02 继承 docker01
[root@localhost /]# docker run -it --name docker02 --volumes-from docker01 huangjialin/centos:1.0

# 查看容器docker02内容
[root@465894e34af8 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  volume01	volume02


# 进入docker01
[root@localhost /]# docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS     NAMES
465894e34af8   huangjialin/centos:1.0   "/bin/sh -c /bin/bash"   2 minutes ago   Up 2 minutes             docker02
8e2660858dca   huangjialin/centos:1.0   "/bin/sh -c /bin/bash"   3 minutes ago   Up 3 minutes             docker01
[root@localhost /]# docker attach 8e2660858dca
[root@8e2660858dca /]# ls -l
total 0
lrwxrwxrwx.   1 root root   7 Nov  3 15:22 bin -> usr/bin
drwxr-xr-x.   5 root root 360 Apr 13 05:47 dev
drwxr-xr-x.   1 root root  66 Apr 13 05:47 etc
drwxr-xr-x.   2 root root   6 Nov  3 15:22 home
lrwxrwxrwx.   1 root root   7 Nov  3 15:22 lib -> usr/lib
lrwxrwxrwx.   1 root root   9 Nov  3 15:22 lib64 -> usr/lib64
drwx------.   2 root root   6 Dec  4 17:37 lost+found
drwxr-xr-x.   2 root root   6 Nov  3 15:22 media
drwxr-xr-x.   2 root root   6 Nov  3 15:22 mnt
drwxr-xr-x.   2 root root   6 Nov  3 15:22 opt
dr-xr-xr-x. 242 root root   0 Apr 13 05:47 proc
dr-xr-x---.   2 root root 162 Dec  4 17:37 root
drwxr-xr-x.  11 root root 163 Dec  4 17:37 run
lrwxrwxrwx.   1 root root   8 Nov  3 15:22 sbin -> usr/sbin
drwxr-xr-x.   2 root root   6 Nov  3 15:22 srv
dr-xr-xr-x.  13 root root   0 Apr 13 05:27 sys
drwxrwxrwt.   7 root root 145 Dec  4 17:37 tmp
drwxr-xr-x.  12 root root 144 Dec  4 17:37 usr
drwxr-xr-x.  20 root root 262 Dec  4 17:37 var
drwxr-xr-x.   2 root root   6 Apr 13 05:47 volume01
drwxr-xr-x.   2 root root   6 Apr 13 05:47 volume02
# 创建文件
[root@8e2660858dca /]# cd volume01
[root@8e2660858dca volume01]# ls
[root@8e2660858dca volume01]# touch docker01

# 进入docker02
[root@localhost /]# docker attach 465894e34af8
[root@465894e34af8 /]# ls  -l
total 0
lrwxrwxrwx.   1 root root   7 Nov  3 15:22 bin -> usr/bin
drwxr-xr-x.   5 root root 360 Apr 13 05:48 dev
drwxr-xr-x.   1 root root  66 Apr 13 05:48 etc
drwxr-xr-x.   2 root root   6 Nov  3 15:22 home
lrwxrwxrwx.   1 root root   7 Nov  3 15:22 lib -> usr/lib
lrwxrwxrwx.   1 root root   9 Nov  3 15:22 lib64 -> usr/lib64
drwx------.   2 root root   6 Dec  4 17:37 lost+found
drwxr-xr-x.   2 root root   6 Nov  3 15:22 media
drwxr-xr-x.   2 root root   6 Nov  3 15:22 mnt
drwxr-xr-x.   2 root root   6 Nov  3 15:22 opt
dr-xr-xr-x. 241 root root   0 Apr 13 05:48 proc
dr-xr-x---.   2 root root 162 Dec  4 17:37 root
drwxr-xr-x.  11 root root 163 Dec  4 17:37 run
lrwxrwxrwx.   1 root root   8 Nov  3 15:22 sbin -> usr/sbin
drwxr-xr-x.   2 root root   6 Nov  3 15:22 srv
dr-xr-xr-x.  13 root root   0 Apr 13 05:27 sys
drwxrwxrwt.   7 root root 145 Dec  4 17:37 tmp
drwxr-xr-x.  12 root root 144 Dec  4 17:37 usr
drwxr-xr-x.  20 root root 262 Dec  4 17:37 var
drwxr-xr-x.   2 root root  22 Apr 13 05:55 volume01
drwxr-xr-x.   2 root root   6 Apr 13 05:47 volume02
# 发现docker01创建的文件
[root@465894e34af8 /]# cd volume01
[root@465894e34af8 volume01]# ls
docker01

跟着狂神学Docker(精髓篇)_第14张图片
跟着狂神学Docker(精髓篇)_第15张图片
各个容器之间的数据共享
亲测删除也会同步

# 再新建一个docker03同样继承docker01
$ docker run -it --name docker03 --volumes-from docker01 caoshipeng/centos:latest
$ cd volume01	#进入volume01 查看是否也同步docker01的数据
$ ls 
docker01.txt

# 测试:可以删除docker01,查看一下docker02和docker03是否可以访问这个文件
# 测试发现:数据依旧保留在docker02和docker03中没有被删除

跟着狂神学Docker(精髓篇)_第16张图片
多个mysql实现数据共享

$ docker run -d -p 3306:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:5.7

$ docker run -d -p 3310:3306 -e MYSQL_ROOT_PASSWORD=123456 --name mysql02 --volumes-from mysql01  mysql:5.7

# 这个时候,可以实现两个容器数据同步!

结论

容器之间的配置信息的传递,数据卷容器的生命周期一直持续到没有容器使用为止。

但是一旦你持久化到了本地,这个时候,本地的数据是不会删除的!

DockerFile

DockerFile介绍

dockerfile是用来构建docker镜像的文件!命令参数脚本!

构建步骤:

1、 编写一个dockerfile文件

2、 docker build 构建称为一个镜像

3、 docker run运行镜像

4、 docker push发布镜像(DockerHub 、阿里云仓库)

跟着狂神学Docker(精髓篇)_第17张图片
点击链接跳转到GitHub

跟着狂神学Docker(精髓篇)_第18张图片
很多官方镜像都是基础包,很多功能没有,我们通常会自己搭建自己的镜像!

官方既然可以制作镜像,那我们也可以!

DockerFile构建过程

基础知识:

1、每个保留关键字(指令)都是必须是大写字母

2、执行从上到下顺序

3、#表示注释

4、每一个指令都会创建提交一个新的镜像层,并提交!
跟着狂神学Docker(精髓篇)_第19张图片
Dockerfile是面向开发的,我们以后要发布项目,做镜像,就需要编写dockerfile文件,这个文件十分简单!

Docker镜像逐渐成企业交付的标准,必须要掌握!

步骤:开发、部署、运维缺一不可

DockerFile:构建文件,定义了一切的步骤,源代码

DockerImages:通过DockerFile构建生成的镜像,最终发布和运行产品。

Docker容器:容器就是镜像运行起来提供服务。

DockerFile的指令

FROM				# from:基础镜像,一切从这里开始构建
MAINTAINER			# maintainer:镜像是谁写的, 姓名+邮箱
RUN					# run:镜像构建的时候需要运行的命令
ADD					# add:步骤,tomcat镜像,这个tomcat压缩包!添加内容 添加同目录
WORKDIR				# workdir:镜像的工作目录
VOLUME				# volume:挂载的目录
EXPOSE				# expose:保留端口配置
CMD					# cmd:指定这个容器启动的时候要运行的命令,只有最后一个会生效,可被替代
ENTRYPOINT			# entrypoint:指定这个容器启动的时候要运行的命令,可以追加命令
ONBUILD				# onbuild:当构建一个被继承DockerFile这个时候就会运行onbuild的指令,触发指令
COPY				# copy:类似ADD,将我们文件拷贝到镜像中
ENV					# env:构建的时候设置环境变量!

跟着狂神学Docker(精髓篇)_第20张图片

实战测试

scratch 镜像

FROM scratch
ADD centos-7-x86_64-docker.tar.xz /

LABEL \
    org.label-schema.schema-version="1.0" \
    org.label-schema.name="CentOS Base Image" \
    org.label-schema.vendor="CentOS" \
    org.label-schema.license="GPLv2" \
    org.label-schema.build-date="20200504" \
    org.opencontainers.image.title="CentOS Base Image" \
    org.opencontainers.image.vendor="CentOS" \
    org.opencontainers.image.licenses="GPL-2.0-only" \
    org.opencontainers.image.created="2020-05-04 00:00:00+01:00"

CMD ["/bin/bash"]

Docker Hub 中 99%的镜像都是从这个基础镜像过来的 FROM scratch,然后配置需要的软件和配置来进行构建。

创建一个自己的centos

# 1./home下新建dockerfile目录
[root@localhost /]# cd home
[root@localhost home]# mkdir dockerfile

# 2. dockerfile目录下新建mydockerfile-centos文件
[root@localhost home]# cd dockerfile/

[root@localhost dockerfile]# vim mydockerfile-centos

# 3.编写Dockerfile配置文件
FROM centos							# 基础镜像是官方原生的centos
MAINTAINER huangjialin<2622046365@qq.com>	# 作者

ENV MYPATH /usr/local				# 配置环境变量的目录 
WORKDIR $MYPATH						# 将工作目录设置为 MYPATH

RUN yum -y install vim				# 给官方原生的centos 增加 vim指令
RUN yum -y install net-tools		# 给官方原生的centos 增加 ifconfig命令

EXPOSE 80							# 暴露端口号为80

CMD echo $MYPATH					# 输出下 MYPATH 路径
CMD echo "-----end----"				
CMD /bin/bash						# 启动后进入 /bin/bash

# 4.通过这个文件构建镜像
# 命令: docker build -f 文件路径 -t 镜像名:[tag] .
[root@localhost dockerfile]# docker build -f mydockerfile-centos -t mysentos:0.1 .

# 5.出现下图后则构建成功
Successfully built 2315251fefdd
Successfully tagged mysentos:0.1

跟着狂神学Docker(精髓篇)_第21张图片

[root@localhost home]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED          SIZE
mysentos              0.1       2315251fefdd   52 seconds ago   291MB
huangjialin/centos    1.0       74f0e59c6da4   18 hours ago     209MB
tomcat02.1.0          latest    f5946bde7e99   22 hours ago     672MB
tomcat                8         926c7fd4777e   2 days ago       533MB
tomcat                latest    bd431ca8553c   2 days ago       667MB
nginx                 latest    519e12e2a84a   3 days ago       133MB
mysql                 5.7       450379344707   3 days ago       449MB
portainer/portainer   latest    580c0e4e98b0   3 weeks ago      79.1MB
hello-world           latest    d1165f221234   5 weeks ago      13.3kB
centos                latest    300e315adb2f   4 months ago     209MB
elasticsearch         7.6.2     f29a1ee41030   12 months ago    791MB

# 6.测试运行
[root@localhost home]# docker run -it mysentos:0.1		# 注意带上版本号,否则每次都回去找最新版latest

[root@468db5f02628 local]# pwd	
/usr/local							# 与Dockerfile文件中 WORKDIR 设置的 MYPATH 一致
[root@468db5f02628 local]# vim								# vim 指令可以使用
[root@468db5f02628 local]# ifconfig     						# ifconfig 指令可以使用

# docker history 镜像id 查看镜像构建历史步骤
[root@localhost home]# docker history 2315251fefdd
IMAGE          CREATED         CREATED BY                                      SIZE      COMMENT
2315251fefdd   6 minutes ago   /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "/bin…   0B        
be99d496b25c   6 minutes ago   /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "echo…   0B        
34fd97cceb13   6 minutes ago   /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "echo…   0B        
baa95b2530ae   6 minutes ago   /bin/sh -c #(nop)  EXPOSE 80                    0B        
ef9b50de0b5b   6 minutes ago   /bin/sh -c yum -y install net-tools             23.4MB    
071ef8153ad4   6 minutes ago   /bin/sh -c yum -y install vim                   58.1MB    
d6a38a2948f3   7 minutes ago   /bin/sh -c #(nop) WORKDIR /usr/local            0B        
98bd16198bff   7 minutes ago   /bin/sh -c #(nop)  ENV MYPATH=/usr/local        0B        
53816b10cd26   7 minutes ago   /bin/sh -c #(nop)  MAINTAINER huangjialin<26…   0B        
300e315adb2f   4 months ago    /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B        
      4 months ago    /bin/sh -c #(nop)  LABEL org.label-schema.sc…   0B        
      4 months ago    /bin/sh -c #(nop) ADD file:bd7a2aed6ede423b7…   209MB     


之前的

跟着狂神学Docker(精髓篇)_第22张图片

之后的

跟着狂神学Docker(精髓篇)_第23张图片

变更历史

我们平时拿到一个镜像,可以用 “docker history 镜像id” 研究一下是什么做的

CMD 和 ENTRYPOINT区别

CMD					# 指定这个容器启动的时候要运行的命令,只有最后一个会生效,可被替代。
ENTRYPOINT			# 指定这个容器启动的时候要运行的命令,可以追加命令

测试CMD

# 编写dockerfile文件
[root@localhost dockerfile]# vim dockerfile-test-cmd
FROM centos
CMD ["ls","-a"]					# 启动后执行 ls -a 命令

# CMD [] :要运行的命令是存放在一个数组结构中的。

# 构建镜像
[root@localhost dockerfile]# docker build -f dockerfile-test-cmd -t cmd-test:0.1 .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM centos
 ---> 300e315adb2f
Step 2/2 : CMD ["ls","-a"]
 ---> Running in 3d990f51fd5a
Removing intermediate container 3d990f51fd5a
 ---> 0e927777d383
Successfully built 0e927777d383
Successfully tagged cmd-test:0.1

# 运行镜像
[root@localhost dockerfile]# docker run 0e927777d383		# 由结果可得,运行后就执行了 ls -a 命令
.
..
.dockerenv
bin
dev
etc
home
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var


# 想追加一个命令  -l 成为ls -al:展示列表详细数据
[root@localhost dockerfile]# docker run cmd-test:0.1 -l
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"-l\":
executable file not found in $PATH": unknown.
ERRO[0000] error waiting for container: context canceled 

# cmd的情况下 -l 替换了CMD["ls","-l"] 而 -l  不是命令所以报错

[root@localhost dockerfile]# docker run 0e927777d383 ls -al
total 0
drwxr-xr-x.   1 root root   6 Apr 13 08:38 .
drwxr-xr-x.   1 root root   6 Apr 13 08:38 ..
-rwxr-xr-x.   1 root root   0 Apr 13 08:38 .dockerenv
lrwxrwxrwx.   1 root root   7 Nov  3 15:22 bin -> usr/bin
drwxr-xr-x.   5 root root 340 Apr 13 08:38 dev
drwxr-xr-x.   1 root root  66 Apr 13 08:38 etc
drwxr-xr-x.   2 root root   6 Nov  3 15:22 home
lrwxrwxrwx.   1 root root   7 Nov  3 15:22 lib -> usr/lib
lrwxrwxrwx.   1 root root   9 Nov  3 15:22 lib64 -> usr/lib64
drwx------.   2 root root   6 Dec  4 17:37 lost+found
drwxr-xr-x.   2 root root   6 Nov  3 15:22 media
drwxr-xr-x.   2 root root   6 Nov  3 15:22 mnt
drwxr-xr-x.   2 root root   6 Nov  3 15:22 opt
dr-xr-xr-x. 247 root root   0 Apr 13 08:38 proc
dr-xr-x---.   2 root root 162 Dec  4 17:37 root
drwxr-xr-x.  11 root root 163 Dec  4 17:37 run
lrwxrwxrwx.   1 root root   8 Nov  3 15:22 sbin -> usr/sbin
drwxr-xr-x.   2 root root   6 Nov  3 15:22 srv
dr-xr-xr-x.  13 root root   0 Apr 13 05:27 sys
drwxrwxrwt.   7 root root 145 Dec  4 17:37 tmp
drwxr-xr-x.  12 root root 144 Dec  4 17:37 usr
drwxr-xr-x.  20 root root 262 Dec  4 17:37 var

测试ENTRYPOINT

# 编写dockerfile文件
$ vim dockerfile-test-entrypoint
FROM centos
ENTRYPOINT ["ls","-a"]

# 构建镜像
$ docker build  -f dockerfile-test-entrypoint -t cmd-test:0.1 .

# 运行镜像
$ docker run entrypoint-test:0.1
.
..
.dockerenv
bin
dev
etc
home
lib
lib64
lost+found ...

# 我们的命令,是直接拼接在我们得ENTRYPOINT命令后面的
$ docker run entrypoint-test:0.1 -l
total 56
drwxr-xr-x   1 root root 4096 May 16 06:32 .
drwxr-xr-x   1 root root 4096 May 16 06:32 ..
-rwxr-xr-x   1 root root    0 May 16 06:32 .dockerenv
lrwxrwxrwx   1 root root    7 May 11  2019 bin -> usr/bin
drwxr-xr-x   5 root root  340 May 16 06:32 dev
drwxr-xr-x   1 root root 4096 May 16 06:32 etc
drwxr-xr-x   2 root root 4096 May 11  2019 home
lrwxrwxrwx   1 root root    7 May 11  2019 lib -> usr/lib
lrwxrwxrwx   1 root root    9 May 11  2019 lib64 -> usr/lib64 ....

Dockerfile中很多命令都十分的相似,我们需要了解它们的区别,我们最好的学习就是对比他们然后测试效果!

实战:Tomcat镜像

1、准备镜像文件

准备tomcat 和 jdk 到当前目录,编写好README

[root@localhost /]# cd /home
[root@localhost home]# ls
ceshi  dockerfile  docker-test-volume  huang.java  huangjialin  huang.txt  mylinux  mysql  test.java  testTmp
[root@localhost home]# cd huangjialin
[root@localhost huangjialin]# ls
datas  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
# 创建目录
[root@localhost huangjialin]# mkdir -vp build/tomcat
mkdir: created directory ‘build’
mkdir: created directory ‘build/tomcat’
[root@localhost huangjialin]# ls
build  datas  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
[root@localhost huangjialin]# cd build
[root@localhost build]# cd tomcat
# 根据下图导入数据包
[root@localhost tomcat]# ls
apache-tomcat-9.0.45.tar.gz  jdk-8u221-linux-x64.tar.gz

跟着狂神学Docker(精髓篇)_第24张图片
在这里插入图片描述

2、编写dokerfile

官方命名Dockerfile,build会自动寻找这个文件,就不需要-f指定了!

[root@localhost tomcat]# ls
apache-tomcat-9.0.45.tar.gz  jdk-8u221-linux-x64.tar.gz
[root@localhost tomcat]# touch readme.txt
[root@localhost tomcat]# vim Dockerfile

FROM centos 										# 基础镜像centos
MAINTAINER huangjialin<2622046365@qq.com>					# 作者
COPY readme.txt /usr/local/readme.txt						# 复制README文件
ADD jdk-8u221-linux-x64.tar.gz /usr/local/ 			# 添加jdk,ADD 命令会自动解压
ADD apache-tomcat-9.0.45.tar.gz /usr/local/ 		# 添加tomcat,ADD 命令会自动解压
RUN yum -y install vim								# 安装 vim 命令
ENV MYPATH /usr/local 								# 环境变量设置 工作目录
WORKDIR $MYPATH

ENV JAVA_HOME /usr/local/jdk1.8.0_221 				# 环境变量: JAVA_HOME环境变量
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.45 	# 环境变量: tomcat环境变量
ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.45

# 设置环境变量 分隔符是:
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin 	

EXPOSE 8080 										# 设置暴露的端口

CMD /usr/local/apache-tomcat-9.0.45/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.45/logs/catalina.out 					# 设置默认命令


跟着狂神学Docker(精髓篇)_第25张图片

3、构建镜像

# 因为Dockerfile命名使用默认命名 因此不用使用-f 指定文件
[root@localhost tomcat]# docker build -t diytomcat .

运行成功

[root@localhost tomcat]# docker build -t diytomcat .
Sending build context to Docker daemon  206.6MB
Step 1/15 : FROM centos
 ---> 300e315adb2f
Step 2/15 : MAINTAINER huangjialin<2622046365@qq.com>
 ---> Using cache
 ---> 53816b10cd26
Step 3/15 : COPY readme.txt /usr/local/readme.txt
 ---> b17277a321e4
Step 4/15 : ADD jdk-8u221-linux-x64.tar.gz /usr/local/
 ---> bf206090dd5b
Step 5/15 : ADD apache-tomcat-9.0.45.tar.gz /usr/local/
 ---> e7e5d7cb0c43
Step 6/15 : RUN yum -y install vim
 ---> Running in 7984f5e786a8
CentOS Linux 8 - AppStream                      791 kB/s | 6.3 MB     00:08    
CentOS Linux 8 - BaseOS                         1.2 MB/s | 2.3 MB     00:01    
CentOS Linux 8 - Extras                          18 kB/s | 9.6 kB     00:00    
Last metadata expiration check: 0:00:01 ago on Tue Apr 13 11:41:15 2021.
Dependencies resolved.
================================================================================
 Package             Arch        Version                   Repository      Size
================================================================================
Installing:
 vim-enhanced        x86_64      2:8.0.1763-15.el8         appstream      1.4 M
Installing dependencies:
 gpm-libs            x86_64      1.20.7-15.el8             appstream       39 k
 vim-common          x86_64      2:8.0.1763-15.el8         appstream      6.3 M
 vim-filesystem      noarch      2:8.0.1763-15.el8         appstream       48 k
 which               x86_64      2.21-12.el8               baseos          49 k

Transaction Summary
================================================================================
Install  5 Packages

Total download size: 7.8 M
Installed size: 30 M
Downloading Packages:
(1/5): gpm-libs-1.20.7-15.el8.x86_64.rpm        187 kB/s |  39 kB     00:00    
(2/5): vim-filesystem-8.0.1763-15.el8.noarch.rp 402 kB/s |  48 kB     00:00    
(3/5): which-2.21-12.el8.x86_64.rpm             106 kB/s |  49 kB     00:00    
(4/5): vim-enhanced-8.0.1763-15.el8.x86_64.rpm  500 kB/s | 1.4 MB     00:02    
(5/5): vim-common-8.0.1763-15.el8.x86_64.rpm    599 kB/s | 6.3 MB     00:10    
--------------------------------------------------------------------------------
Total                                           672 kB/s | 7.8 MB     00:11     
warning: /var/cache/dnf/appstream-02e86d1c976ab532/packages/gpm-libs-1.20.7-15.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS Linux 8 - AppStream                      107 kB/s | 1.6 kB     00:00    
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) "
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : which-2.21-12.el8.x86_64                               1/5 
  Installing       : vim-filesystem-2:8.0.1763-15.el8.noarch                2/5 
  Installing       : vim-common-2:8.0.1763-15.el8.x86_64                    3/5 
  Installing       : gpm-libs-1.20.7-15.el8.x86_64                          4/5 
  Running scriptlet: gpm-libs-1.20.7-15.el8.x86_64                          4/5 
  Installing       : vim-enhanced-2:8.0.1763-15.el8.x86_64                  5/5 
  Running scriptlet: vim-enhanced-2:8.0.1763-15.el8.x86_64                  5/5 
  Running scriptlet: vim-common-2:8.0.1763-15.el8.x86_64                    5/5 
  Verifying        : gpm-libs-1.20.7-15.el8.x86_64                          1/5 
  Verifying        : vim-common-2:8.0.1763-15.el8.x86_64                    2/5 
  Verifying        : vim-enhanced-2:8.0.1763-15.el8.x86_64                  3/5 
  Verifying        : vim-filesystem-2:8.0.1763-15.el8.noarch                4/5 
  Verifying        : which-2.21-12.el8.x86_64                               5/5 

Installed:
  gpm-libs-1.20.7-15.el8.x86_64         vim-common-2:8.0.1763-15.el8.x86_64    
  vim-enhanced-2:8.0.1763-15.el8.x86_64 vim-filesystem-2:8.0.1763-15.el8.noarch
  which-2.21-12.el8.x86_64             

Complete!
Removing intermediate container 7984f5e786a8
 ---> 5e55934a1698
Step 7/15 : ENV MYPATH /usr/local
 ---> Running in 1c27b1556650
Removing intermediate container 1c27b1556650
 ---> bf7676c461b7
Step 8/15 : WORKDIR $MYPATH
 ---> Running in ea7b376828ee
Removing intermediate container ea7b376828ee
 ---> 829e13be0dd2
Step 9/15 : ENV JAVA_HOME /usr/local/jdk1.8.0_221
 ---> Running in e870347689db
Removing intermediate container e870347689db
 ---> 9addfa9f2af9
Step 10/15 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
 ---> Running in 35be0d0d1e87
Removing intermediate container 35be0d0d1e87
 ---> 2b8399db457f
Step 11/15 : ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.45
 ---> Running in 6268510dbb10
Removing intermediate container 6268510dbb10
 ---> f587d0e0d7b1
Step 12/15 : ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.45
 ---> Running in 584842f44cb2
Removing intermediate container 584842f44cb2
 ---> 9352b4a38800
Step 13/15 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
 ---> Running in 3882c79944b1
Removing intermediate container 3882c79944b1
 ---> 2189e809aa16
Step 14/15 : EXPOSE 8080
 ---> Running in 2fdcc0bb062d
Removing intermediate container 2fdcc0bb062d
 ---> 2ada2912e565
Step 15/15 : CMD /usr/local/apache-tomcat-9.0.45/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.45/logs/catalina.out
 ---> Running in b5253d274a87
Removing intermediate container b5253d274a87
 ---> 62c96b0fe815
Successfully built 62c96b0fe815
Successfully tagged diytomcat:latest

4、run镜像

# -d:后台运行 -p:暴露端口 --name:别名 -v:绑定路径 
[root@localhost tomcat]# docker run -d -p 9090:8080 --name diytomcat -v /home/huangjialin/build/tomcat/test:/usr/local/apache-tomcat-9.0.45/webapps/test -v /home/huangjialin/build/tomcat/tomcatlogs/:/usr/local/apache-tomcat-9.0.45/logs diytomcat
eefdce2320da80a26d04951fa62ead9155260c9ec2fc7195fb5d78332e70b20e
[root@localhost tomcat]# docker exec -it eefdce2320da80a2 /bin/bash
[root@eefdce2320da local]# ls
apache-tomcat-9.0.45  bin  etc	games  include	jdk1.8.0_221  lib  lib64  libexec  readme.txt  sbin  share  src
[root@eefdce2320da local]# pwd
/usr/local
[root@eefdce2320da local]# ls -l
total 0
drwxr-xr-x. 1 root root  45 Apr 13 11:40 apache-tomcat-9.0.45
drwxr-xr-x. 2 root root   6 Nov  3 15:22 bin
drwxr-xr-x. 2 root root   6 Nov  3 15:22 etc
drwxr-xr-x. 2 root root   6 Nov  3 15:22 games
drwxr-xr-x. 2 root root   6 Nov  3 15:22 include
drwxr-xr-x. 7   10  143 245 Jul  4  2019 jdk1.8.0_221
drwxr-xr-x. 2 root root   6 Nov  3 15:22 lib
drwxr-xr-x. 3 root root  17 Dec  4 17:37 lib64
drwxr-xr-x. 2 root root   6 Nov  3 15:22 libexec
-rw-r--r--. 1 root root   0 Apr 13 11:24 readme.txt
drwxr-xr-x. 2 root root   6 Nov  3 15:22 sbin
drwxr-xr-x. 5 root root  49 Dec  4 17:37 share
drwxr-xr-x. 2 root root   6 Nov  3 15:22 src
[root@eefdce2320da local]# cd apache-tomcat-9.0.45/
[root@eefdce2320da apache-tomcat-9.0.45]# ls
BUILDING.txt  CONTRIBUTING.md  LICENSE	NOTICE	README.md  RELEASE-NOTES  RUNNING.txt  bin  conf  lib  logs  temp  webapps  work
[root@eefdce2320da apache-tomcat-9.0.45]# ls -l
total 128
-rw-r-----. 1 root root 18984 Mar 30 10:29 BUILDING.txt
-rw-r-----. 1 root root  5587 Mar 30 10:29 CONTRIBUTING.md
-rw-r-----. 1 root root 57092 Mar 30 10:29 LICENSE
-rw-r-----. 1 root root  2333 Mar 30 10:29 NOTICE
-rw-r-----. 1 root root  3257 Mar 30 10:29 README.md
-rw-r-----. 1 root root  6898 Mar 30 10:29 RELEASE-NOTES
-rw-r-----. 1 root root 16507 Mar 30 10:29 RUNNING.txt
drwxr-x---. 2 root root  4096 Mar 30 10:29 bin
drwx------. 1 root root    22 Apr 13 12:34 conf
drwxr-x---. 2 root root  4096 Mar 30 10:29 lib
drwxr-xr-x. 2 root root   197 Apr 13 12:34 logs
drwxr-x---. 2 root root    30 Mar 30 10:29 temp
drwxr-x---. 1 root root    18 Apr 13 12:34 webapps
drwxr-x---. 1 root root    22 Apr 13 12:34 work


# 另一个窗口
[root@localhost tomcat]# curl localhost:9090
<!DOCTYPE html>
"en">
    
        "UTF-8" />
        Apache Tomcat<span class="token operator">/</span>9<span class="token punctuation">.</span>0<span class="token punctuation">.</span>45<<span class="token operator">/</span>title>
        <link href=<span class="token string">"favicon.ico"</span> rel=<span class="token string">"icon"</span> <span class="token function">type</span>=<span class="token string">"image/x-icon"</span> <span class="token operator">/</span>>
        <link href=<span class="token string">"tomcat.css"</span> rel=<span class="token string">"stylesheet"</span> <span class="token function">type</span>=<span class="token string">"text/css"</span> <span class="token operator">/</span>>
    <<span class="token operator">/</span>head>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
</code></pre> 
  <h4>5、访问测试</h4> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it 自定义容器的id /bin/bash</span>

<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># cul localhost:9090</span>

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/b887794666b4403a8eebaa369d887424.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/b887794666b4403a8eebaa369d887424.jpg" alt="跟着狂神学Docker(精髓篇)_第26张图片" width="650" height="412" style="border:1px solid black;"></a></p> 
  <h4>6、发布项目</h4> 
  <p>(由于做了卷挂载,我们直接在本地编写项目就可以发布了!)</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># ls</span>
apache<span class="token operator">-</span>tomcat<span class="token operator">-</span>9<span class="token punctuation">.</span>0<span class="token punctuation">.</span>45<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz  Dockerfile  jdk<span class="token operator">-</span>8u221<span class="token operator">-</span>linux<span class="token operator">-</span>x64<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz  readme<span class="token punctuation">.</span>txt  test  tomcatlogs
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># cd test/</span>
<span class="token namespace">[root@localhost test]</span><span class="token comment"># pwd</span>
<span class="token operator">/</span>home<span class="token operator">/</span>huangjialin<span class="token operator">/</span>build<span class="token operator">/</span>tomcat<span class="token operator">/</span>test
<span class="token namespace">[root@localhost test]</span><span class="token comment"># mkdir WEB-INF</span>
<span class="token namespace">[root@localhost test]</span><span class="token comment"># ls</span>
WEB<span class="token operator">-</span>INF
<span class="token namespace">[root@localhost test]</span><span class="token comment"># cd WEB-INF/</span>
<span class="token namespace">[root@localhost WEB-INF]</span><span class="token comment"># vim web.xml</span>
<span class="token namespace">[root@localhost WEB-INF]</span><span class="token comment"># cd ../</span>
<span class="token namespace">[root@localhost test]</span><span class="token comment"># vim index.jsp</span>

</code></pre> 
  <p>参考链接 https://segmentfault.com/a/1190000011404088</p> 
  <blockquote> 
   <p>web.xml</p> 
  </blockquote> 
  <pre><code class="prism language-powershell">  <?xml version=<span class="token string">"3.0"</span> encoding=<span class="token string">"UTF-8"</span>?>
  <web<span class="token operator">-</span>app xmlns=<span class="token string">"http://java.sun.com/xml/ns/javaee"</span>
           xmlns:xsi=<span class="token string">"http://www.w3.org/2001/XMLSchema-instance"</span>
           xsi:schemaLocation=<span class="token string">"http://java.sun.com/xml/ns/javaee
                               http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"</span>
           version=<span class="token string">"3.0"</span>>

  <<span class="token operator">/</span>web<span class="token operator">-</span>app>
</code></pre> 
  <p>参考链接 https://www.runoob.com/jsp/jsp-syntax.html</p> 
  <blockquote> 
   <p>index.jsp</p> 
  </blockquote> 
  <pre><code class="prism language-powershell"><<span class="token operator">%</span>@ page language=<span class="token string">"java"</span> contentType=<span class="token string">"text/html; charset=UTF-8"</span>
    pageEncoding=<span class="token string">"UTF-8"</span><span class="token operator">%</span>>
<<span class="token operator">!</span>DOCTYPE html>
<html>
<head>
<meta charset=<span class="token string">"utf-8"</span>>
<title>huangjialin<span class="token operator">-</span>菜鸟教程<span class="token punctuation">(</span>runoob<span class="token punctuation">.</span>com<span class="token punctuation">)</span><<span class="token operator">/</span>title>
<<span class="token operator">/</span>head>
<body>
Hello World<span class="token operator">!</span><br<span class="token operator">/</span>>
<<span class="token operator">%</span>
System<span class="token punctuation">.</span>out<span class="token punctuation">.</span>println<span class="token punctuation">(</span><span class="token string">"你的 IP 地址 "</span> <span class="token operator">+</span> request<span class="token punctuation">.</span>getRemoteAddr<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token operator">%</span>>
<<span class="token operator">/</span>body>
<<span class="token operator">/</span>html>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/9d1f5059fe724121aad2dcced7ccf25d.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/9d1f5059fe724121aad2dcced7ccf25d.jpg" alt="跟着狂神学Docker(精髓篇)_第27张图片" width="650" height="202" style="border:1px solid black;"></a><br> 发现:项目部署成功,可以直接访问!</p> 
  <p>我们以后开发的步骤:需要掌握<code>Dockerfile</code>的编写!我们之后的一切都是使用<code>docker</code>镜像来发布运行!</p> 
  <h3>发布自己的镜像</h3> 
  <h4>发布到 Docker Hub</h4> 
  <p>1、地址 https://hub.docker.com/</p> 
  <p>2、确定这个账号可以登录</p> 
  <p>3、登录</p> 
  <p><a href="http://img.e-com-net.com/image/info8/6fe87273bd0240e8ad4f86fdf898e038.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/6fe87273bd0240e8ad4f86fdf898e038.jpg" alt="跟着狂神学Docker(精髓篇)_第28张图片" width="650" height="341" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/414a63bc6f664d62ac746e26af041e55.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/414a63bc6f664d62ac746e26af041e55.jpg" alt="跟着狂神学Docker(精髓篇)_第29张图片" width="650" height="369" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker login --help</span>
Usage:  docker login <span class="token namespace">[OPTIONS]</span> <span class="token namespace">[SERVER]</span>

Log in to a Docker registry<span class="token punctuation">.</span>
<span class="token keyword">If</span> no server is specified<span class="token punctuation">,</span> the default is defined by the daemon<span class="token punctuation">.</span>

Options:
  <span class="token operator">-</span>p<span class="token punctuation">,</span> <span class="token operator">--</span>password string   Password
      <span class="token operator">--</span>password<span class="token operator">-</span>stdin    Take the password <span class="token keyword">from</span> stdin
  <span class="token operator">-</span>u<span class="token punctuation">,</span> <span class="token operator">--</span>username string   Username

<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker login -u 你的用户名 -p 你的密码</span>

</code></pre> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker login -u yanghuihui520</span>
Password: 
WARNING<span class="token operator">!</span> Your password will be stored unencrypted in <span class="token operator">/</span>root<span class="token operator">/</span><span class="token punctuation">.</span>docker<span class="token operator">/</span>config<span class="token punctuation">.</span>json<span class="token punctuation">.</span>
Configure a credential helper to remove this warning<span class="token punctuation">.</span> See
https:<span class="token operator">/</span><span class="token operator">/</span>docs<span class="token punctuation">.</span>docker<span class="token punctuation">.</span>com<span class="token operator">/</span>engine<span class="token operator">/</span>reference<span class="token operator">/</span>commandline<span class="token operator">/</span>login<span class="token operator">/</span><span class="token comment">#credentials-store</span>

Login Succeeded

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/372757f072b640bc96703032998d3d58.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/372757f072b640bc96703032998d3d58.jpg" alt="跟着狂神学Docker(精髓篇)_第30张图片" width="650" height="128" style="border:1px solid black;"></a><br> 4、提交 push镜像<br> <a href="http://img.e-com-net.com/image/info8/9953bab29fbd4c3c97c3b746250a2c84.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/9953bab29fbd4c3c97c3b746250a2c84.jpg" alt="跟着狂神学Docker(精髓篇)_第31张图片" width="650" height="162" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-powershell"><span class="token comment"># 会发现push不上去,因为如果没有前缀的话默认是push到 官方的library</span>
<span class="token comment"># 解决方法:</span>
<span class="token comment"># 第一种 build的时候添加你的dockerhub用户名,然后在push就可以放到自己的仓库了</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker build -t kuangshen/mytomcat:0.1 .</span>

<span class="token comment"># 第二种 使用docker tag #然后再次push</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker tag 容器id kuangshen/mytomcat:1.0</span>
<span class="token comment">#然后再次push</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker push kuangshen/mytomcat:1.0</span>

</code></pre> 
  <p><mark>必须对应账号名正解</mark></p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker tag 62c96b0fe815 yanghuihui520/tomcat:1.0</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker images</span>
REPOSITORY             TAG       IMAGE ID       CREATED         SIZE
huangjialin<span class="token operator">/</span>tomcat     1<span class="token punctuation">.</span>0       62c96b0fe815   3 hours ago     690MB
。。。
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker push yanghuihui520/tomcat:1.0</span>
The push refers to repository <span class="token namespace">[docker.io/yanghuihui520/tomcat]</span>
a7b8bb209ca2: Pushing <span class="token punctuation">[</span>==========>                                        <span class="token punctuation">]</span>  12<span class="token punctuation">.</span>47MB<span class="token operator">/</span>58<span class="token punctuation">.</span>05MB
5ba6c0e6c8ff: Pushing <span class="token punctuation">[</span>==========>                                        <span class="token punctuation">]</span>  3<span class="token punctuation">.</span>186MB<span class="token operator">/</span>15<span class="token punctuation">.</span>9MB
b3f3595d4705: Pushing <span class="token punctuation">[</span>>                                                  <span class="token punctuation">]</span>  3<span class="token punctuation">.</span>277MB<span class="token operator">/</span>406<span class="token punctuation">.</span>7MB
50c4c2648dca: Layer already exists 
2653d992f4ef: Pushing <span class="token punctuation">[</span>=>                                                 <span class="token punctuation">]</span>  7<span class="token punctuation">.</span>676MB<span class="token operator">/</span>209<span class="token punctuation">.</span>3MB



</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/c7325d138a274104aa6f9b406613af6d.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/c7325d138a274104aa6f9b406613af6d.jpg" alt="在这里插入图片描述" width="650" height="96"></a></p> 
  <h4>发布到 阿里云镜像服务上</h4> 
  <p>看官网 很详细https://cr.console.aliyun.com/repository/</p> 
  <pre><code class="prism language-powershell">$ sudo docker login <span class="token operator">--</span>username=zchengx registry<span class="token punctuation">.</span>cn<span class="token operator">-</span>shenzhen<span class="token punctuation">.</span>aliyuncs<span class="token punctuation">.</span>com
$ sudo docker tag <span class="token namespace">[ImageId]</span> registry<span class="token punctuation">.</span>cn<span class="token operator">-</span>shenzhen<span class="token punctuation">.</span>aliyuncs<span class="token punctuation">.</span>com<span class="token operator">/</span>dsadxzc<span class="token operator">/</span>cheng:<span class="token punctuation">[</span>镜像版本号<span class="token punctuation">]</span>

<span class="token comment"># 修改id 和 版本</span>
sudo docker tag a5ef1f32aaae registry<span class="token punctuation">.</span>cn<span class="token operator">-</span>shenzhen<span class="token punctuation">.</span>aliyuncs<span class="token punctuation">.</span>com<span class="token operator">/</span>dsadxzc<span class="token operator">/</span>cheng:1<span class="token punctuation">.</span>0
<span class="token comment"># 修改版本</span>
$ sudo docker push registry<span class="token punctuation">.</span>cn<span class="token operator">-</span>shenzhen<span class="token punctuation">.</span>aliyuncs<span class="token punctuation">.</span>com<span class="token operator">/</span>dsadxzc<span class="token operator">/</span>cheng:<span class="token punctuation">[</span>镜像版本号<span class="token punctuation">]</span>

</code></pre> 
  <h3>小结</h3> 
  <p><a href="http://img.e-com-net.com/image/info8/a5b82f5e94cd43cf9a5d3ce895306b8d.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/a5b82f5e94cd43cf9a5d3ce895306b8d.jpg" alt="跟着狂神学Docker(精髓篇)_第32张图片" width="650" height="526" style="border:1px solid black;"></a></p> 
  <h2>Docker 网络</h2> 
  <h3>理解Docker0</h3> 
  <p>学习之前清空下前面的<code>docker</code> 镜像、容器</p> 
  <pre><code class="prism language-powershell"><span class="token comment"># 删除全部容器</span>
$ docker <span class="token function">rm</span> <span class="token operator">-</span>f $<span class="token punctuation">(</span>docker <span class="token function">ps</span> <span class="token operator">-</span>aq<span class="token punctuation">)</span>

<span class="token comment"># 删除全部镜像</span>
$ docker rmi <span class="token operator">-</span>f $<span class="token punctuation">(</span>docker images <span class="token operator">-</span>aq<span class="token punctuation">)</span>

</code></pre> 
  <p>测试<br> <a href="http://img.e-com-net.com/image/info8/3f43304420a3490887867e1f4baed5e8.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/3f43304420a3490887867e1f4baed5e8.jpg" alt="跟着狂神学Docker(精髓篇)_第33张图片" width="650" height="165" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># ip addr</span>
1: lo: <LOOPBACK<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">/</span>8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1<span class="token operator">/</span>128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc pfifo_fast state UP <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>ether 00:0c:29:1a:80:de brd ff:ff:ff:ff:ff:ff
    inet 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>254<span class="token punctuation">.</span>133<span class="token operator">/</span>24 brd 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>254<span class="token punctuation">.</span>255 scope global noprefixroute dynamic ens33
       valid_lft 1365sec preferred_lft 1365sec
    inet6 fe80::78ba:483e:9794:f6c2<span class="token operator">/</span>64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0: <NO<span class="token operator">-</span>CARRIER<span class="token punctuation">,</span>BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP> mtu 1500 qdisc noqueue state DOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>ether 52:54:00:a2:05:5a brd ff:ff:ff:ff:ff:ff
    inet 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>1<span class="token operator">/</span>24 brd 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0<span class="token operator">-</span>nic: <BROADCAST<span class="token punctuation">,</span>MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>ether 52:54:00:a2:05:5a brd ff:ff:ff:ff:ff:ff
5: docker0: <NO<span class="token operator">-</span>CARRIER<span class="token punctuation">,</span>BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP> mtu 1500 qdisc noqueue state DOWN <span class="token function">group</span> default 
    link<span class="token operator">/</span>ether 02:42:2a:09:31:67 brd ff:ff:ff:ff:ff:ff
    inet 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">/</span>16 brd 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>255<span class="token punctuation">.</span>255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:2aff:fe09:3167<span class="token operator">/</span>64 scope link 
       valid_lft forever preferred_lft forever

</code></pre> 
  <h3>三个网络</h3> 
  <p>问题: docker 是如果处理容器网络访问的?</p> 
  <p><a href="http://img.e-com-net.com/image/info8/5f69978d6028449eb252b23e5c77cd1b.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/5f69978d6028449eb252b23e5c77cd1b.jpg" alt="跟着狂神学Docker(精髓篇)_第34张图片" width="650" height="101" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-powershell"><span class="token comment"># 测试  运行一个tomcat</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker run -d -P --name tomcat01 tomcat</span>

<span class="token comment"># 查看容器内部网络地址</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it 容器id ip add</span>

<span class="token comment"># 发现容器启动的时候会得到一个 eth0@if91 ip地址,docker分配!</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat01 ip addr</span>
1: lo: <LOOPBACK<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">/</span>8 scope host lo
       valid_lft forever preferred_lft forever
36: eth0@if37: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc noqueue state UP <span class="token function">group</span> default 
    link<span class="token operator">/</span>ether 02:42:<span class="token function">ac</span>:11:00:02 brd ff:ff:ff:ff:ff:ff link<span class="token operator">-</span>netnsid 0
    inet 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token operator">/</span>16 brd 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>255<span class="token punctuation">.</span>255 scope global eth0
       valid_lft forever preferred_lft forever

       
<span class="token comment"># 思考? linux能不能ping通容器内部! 可以 容器内部可以ping通外界吗? 可以!</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># ping 172.17.0.2</span>
PING 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2 <span class="token punctuation">(</span>172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">)</span> 56<span class="token punctuation">(</span>84<span class="token punctuation">)</span> bytes of <span class="token keyword">data</span><span class="token punctuation">.</span>
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=1 ttl=64 time=19<span class="token punctuation">.</span>5 ms
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=2 ttl=64 time=0<span class="token punctuation">.</span>105 ms
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=3 ttl=64 time=0<span class="token punctuation">.</span>051 ms
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=4 ttl=64 time=0<span class="token punctuation">.</span>071 ms
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=5 ttl=64 time=0<span class="token punctuation">.</span>124 ms
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=6 ttl=64 time=0<span class="token punctuation">.</span>052 ms
。。。

</code></pre> 
  <h3>原理</h3> 
  <p>1、我们每启动一个<code>docker</code>容器,<code>docker</code>就会给<code>docker</code>容器分配一个<code>ip</code>,我们只要按照了<code>docker</code>,就会有一个<code>docker0</code>桥接模式,使用的技术是<code>veth-pair</code>技术!</p> 
  <p>https://www.cnblogs.com/bakari/p/10613710.html</p> 
  <p>再次测试 ip addr</p> 
  <pre><code class="prism language-powershell"><span class="token comment"># 多了一个网卡</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># ip addr</span>
1: lo: <LOOPBACK<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">/</span>8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1<span class="token operator">/</span>128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc pfifo_fast state UP <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>ether 00:0c:29:1a:80:de brd ff:ff:ff:ff:ff:ff
    inet 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>254<span class="token punctuation">.</span>133<span class="token operator">/</span>24 brd 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>254<span class="token punctuation">.</span>255 scope global noprefixroute dynamic ens33
       valid_lft 1499sec preferred_lft 1499sec
    inet6 fe80::78ba:483e:9794:f6c2<span class="token operator">/</span>64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0: <NO<span class="token operator">-</span>CARRIER<span class="token punctuation">,</span>BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP> mtu 1500 qdisc noqueue state DOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>ether 52:54:00:a2:05:5a brd ff:ff:ff:ff:ff:ff
    inet 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>1<span class="token operator">/</span>24 brd 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0<span class="token operator">-</span>nic: <BROADCAST<span class="token punctuation">,</span>MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>ether 52:54:00:a2:05:5a brd ff:ff:ff:ff:ff:ff
5: docker0: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc noqueue state UP <span class="token function">group</span> default 
    link<span class="token operator">/</span>ether 02:42:2a:09:31:67 brd ff:ff:ff:ff:ff:ff
    inet 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">/</span>16 brd 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>255<span class="token punctuation">.</span>255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:2aff:fe09:3167<span class="token operator">/</span>64 scope link 
       valid_lft forever preferred_lft forever
37: veth8f89171@if36: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP <span class="token function">group</span> default 
    link<span class="token operator">/</span>ether f2:72:f8:7d:6e:7b brd ff:ff:ff:ff:ff:ff link<span class="token operator">-</span>netnsid 0
    inet6 fe80::f072:f8ff:fe7d:6e7b<span class="token operator">/</span>64 scope link 
       valid_lft forever preferred_lft forever

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/a06279b12ec441a4b80f49a0a031da09.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/a06279b12ec441a4b80f49a0a031da09.jpg" alt="跟着狂神学Docker(精髓篇)_第35张图片" width="650" height="309" style="border:1px solid black;"></a><br> 2 、再启动一个容器测试,发现又多了一对网络</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker run -d -P --name tomcat02 tomcat</span>
781895f439c26dfd5fd489bf1316ab52d0d747d7a5c4f214656ea8ab9bc7d760
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># ip addr</span>
1: lo: <LOOPBACK<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">/</span>8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1<span class="token operator">/</span>128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc pfifo_fast state UP <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>ether 00:0c:29:1a:80:de brd ff:ff:ff:ff:ff:ff
    inet 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>254<span class="token punctuation">.</span>133<span class="token operator">/</span>24 brd 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>254<span class="token punctuation">.</span>255 scope global noprefixroute dynamic ens33
       valid_lft 1299sec preferred_lft 1299sec
    inet6 fe80::78ba:483e:9794:f6c2<span class="token operator">/</span>64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0: <NO<span class="token operator">-</span>CARRIER<span class="token punctuation">,</span>BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP> mtu 1500 qdisc noqueue state DOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>ether 52:54:00:a2:05:5a brd ff:ff:ff:ff:ff:ff
    inet 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>1<span class="token operator">/</span>24 brd 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0<span class="token operator">-</span>nic: <BROADCAST<span class="token punctuation">,</span>MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>ether 52:54:00:a2:05:5a brd ff:ff:ff:ff:ff:ff
5: docker0: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc noqueue state UP <span class="token function">group</span> default 
    link<span class="token operator">/</span>ether 02:42:2a:09:31:67 brd ff:ff:ff:ff:ff:ff
    inet 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">/</span>16 brd 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>255<span class="token punctuation">.</span>255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:2aff:fe09:3167<span class="token operator">/</span>64 scope link 
       valid_lft forever preferred_lft forever
37: veth8f89171@if36: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP <span class="token function">group</span> default 
    link<span class="token operator">/</span>ether f2:72:f8:7d:6e:7b brd ff:ff:ff:ff:ff:ff link<span class="token operator">-</span>netnsid 0
    inet6 fe80::f072:f8ff:fe7d:6e7b<span class="token operator">/</span>64 scope link 
       valid_lft forever preferred_lft forever
39: veth701a9f4@if38: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP <span class="token function">group</span> default 
    link<span class="token operator">/</span>ether 0a:c9:02:a1:57:a9 brd ff:ff:ff:ff:ff:ff link<span class="token operator">-</span>netnsid 1
    inet6 fe80::8c9:2ff:fea1:57a9<span class="token operator">/</span>64 scope link 
       valid_lft forever preferred_lft forever
<span class="token comment">#查看tomcat02容器地址</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat02 ip addr</span>
1: lo: <LOOPBACK<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN <span class="token function">group</span> default qlen 1000
    link<span class="token operator">/</span>loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">/</span>8 scope host lo
       valid_lft forever preferred_lft forever
38: eth0@if39: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc noqueue state UP <span class="token function">group</span> default 
    link<span class="token operator">/</span>ether 02:42:<span class="token function">ac</span>:11:00:03 brd ff:ff:ff:ff:ff:ff link<span class="token operator">-</span>netnsid 0
    inet 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token operator">/</span>16 brd 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>255<span class="token punctuation">.</span>255 scope global eth0
       valid_lft forever preferred_lft forever

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/f31a3ca1adad4f77b0cd385afe08afff.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/f31a3ca1adad4f77b0cd385afe08afff.jpg" alt="跟着狂神学Docker(精髓篇)_第36张图片" width="650" height="229" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-powershell"><span class="token comment"># 我们发现这个容器带来网卡,都是一对对的</span>
<span class="token comment"># veth-pair 就是一对的虚拟设备接口,他们都是成对出现的,一端连着协议,一端彼此相连</span>
<span class="token comment"># 正因为有这个特性 veth-pair 充当一个桥梁,连接各种虚拟网络设备的</span>
<span class="token comment"># OpenStac,Docker容器之间的连接,OVS的连接,都是使用veth-pair技术</span>

</code></pre> 
  <p>3、我们来测试下tomcat01和tomcat02是否可以ping通</p> 
  <pre><code class="prism language-powershell"><span class="token comment"># 获取tomcat01的ip 172.17.0.2</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat01 ip addr  </span>
550: eth0@if551: <BROADCAST<span class="token punctuation">,</span>MULTICAST<span class="token punctuation">,</span>UP<span class="token punctuation">,</span>LOWER_UP> mtu 1500 qdisc noqueue state UP <span class="token function">group</span> default 
    link<span class="token operator">/</span>ether 02:42:<span class="token function">ac</span>:11:00:02 brd ff:ff:ff:ff:ff:ff link<span class="token operator">-</span>netnsid 0
    inet 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token operator">/</span>16 brd 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>255<span class="token punctuation">.</span>255 scope global eth0
       valid_lft forever preferred_lft forever
       
<span class="token comment"># 让tomcat02 ping tomcat01       </span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat02 ping 172.17.0.2</span>
PING 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2 <span class="token punctuation">(</span>172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">)</span> 56<span class="token punctuation">(</span>84<span class="token punctuation">)</span> bytes of <span class="token keyword">data</span><span class="token punctuation">.</span>
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=1 ttl=64 time=9<span class="token punctuation">.</span>07 ms
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=2 ttl=64 time=0<span class="token punctuation">.</span>145 ms
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=3 ttl=64 time=0<span class="token punctuation">.</span>153 ms
64 bytes <span class="token keyword">from</span> 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2: icmp_seq=4 ttl=64 time=0<span class="token punctuation">.</span>104 ms


<span class="token comment"># 结论:容器和容器之间是可以互相ping通</span>

</code></pre> 
  <h3>网络模型图</h3> 
  <p><a href="http://img.e-com-net.com/image/info8/d9c6d71bcd67454fb3d26cd5d5dfd8a0.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/d9c6d71bcd67454fb3d26cd5d5dfd8a0.jpg" alt="跟着狂神学Docker(精髓篇)_第37张图片" width="650" height="416" style="border:1px solid black;"></a></p> 
  <p>结论:<code>tomcat01</code>和<code>tomcat02</code>公用一个路由器,<code>docker0</code>。</p> 
  <p>所有的容器不指定网络的情况下,都是<code>docker0</code>路由的,<code>docker</code>会给我们的容器分配一个默认的可用ip。</p> 
  <h3>小结</h3> 
  <p><code>Docker</code>使用的是<code>Linux</code>的桥接,宿主机是一个<code>Docker</code>容器的网桥 <code>docker0</code><br> <a href="http://img.e-com-net.com/image/info8/e29eddf479ec45ab998149d9b2f7edc4.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/e29eddf479ec45ab998149d9b2f7edc4.jpg" alt="跟着狂神学Docker(精髓篇)_第38张图片" width="650" height="481" style="border:1px solid black;"></a><br> <code>Docker</code>中所有网络接口都是虚拟的,虚拟的转发效率高(内网传递文件)<br> 只要容器删除,对应的网桥一对就没了!</p> 
  <p>思考一个场景:我们编写了一个微服务,<code>database url=ip</code>: 项目不重启,数据ip换了,我们希望可以处理这个问题,可以通过名字来进行访问容器?</p> 
  <p><a href="http://img.e-com-net.com/image/info8/9c7927a1080c468b9717b85edc219203.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/9c7927a1080c468b9717b85edc219203.jpg" alt="跟着狂神学Docker(精髓篇)_第39张图片" width="650" height="242" style="border:1px solid black;"></a></p> 
  <h3>–link</h3> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat02 ping tomca01   # ping不通</span>
ping: tomca01: Name or service not known

<span class="token comment"># 运行一个tomcat03 --link tomcat02 </span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker run -d -P --name tomcat03 --link tomcat02 tomcat</span>
5f9331566980a9e92bc54681caaac14e9fc993f14ad13d98534026c08c0a9aef

<span class="token comment"># 3连接2</span>
<span class="token comment"># 用tomcat03 ping tomcat02 可以ping通</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat03 ping tomcat02</span>
PING tomcat02 <span class="token punctuation">(</span>172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span> 56<span class="token punctuation">(</span>84<span class="token punctuation">)</span> bytes of <span class="token keyword">data</span><span class="token punctuation">.</span>
64 bytes <span class="token keyword">from</span> tomcat02 <span class="token punctuation">(</span>172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span>: icmp_seq=1 ttl=64 time=12<span class="token punctuation">.</span>6 ms
64 bytes <span class="token keyword">from</span> tomcat02 <span class="token punctuation">(</span>172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span>: icmp_seq=2 ttl=64 time=1<span class="token punctuation">.</span>07 ms
64 bytes <span class="token keyword">from</span> tomcat02 <span class="token punctuation">(</span>172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span>: icmp_seq=3 ttl=64 time=0<span class="token punctuation">.</span>365 ms
64 bytes <span class="token keyword">from</span> tomcat02 <span class="token punctuation">(</span>172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span>: icmp_seq=4 ttl=64 time=0<span class="token punctuation">.</span>185 ms
64 bytes <span class="token keyword">from</span> tomcat02 <span class="token punctuation">(</span>172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span>: icmp_seq=5 ttl=64 time=0<span class="token punctuation">.</span>169 ms


<span class="token comment"># 2连接3</span>
<span class="token comment"># 用tomcat02 ping tomcat03 ping不通</span>

</code></pre> 
  <h3>探究:</h3> 
  <pre><code class="prism language-powershell"><span class="token comment"># docker network inspect 网络id 网段相同</span>
</code></pre> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network ls</span>
NETWORK ID     NAME      DRIVER    SCOPE
4b16ee2d6925   bridge    bridge    local
eedd07789e82   host      host      local
48629cdb554a   none      null      local
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network inspect 4b16ee2d6925</span>
<span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
        <span class="token string">"Name"</span>: <span class="token string">"bridge"</span><span class="token punctuation">,</span>
        <span class="token string">"Id"</span>: <span class="token string">"4b16ee2d6925c9a209b44a0451b7b51c12b530d748cc1162e5184ed12e279de6"</span><span class="token punctuation">,</span>
        <span class="token string">"Created"</span>: <span class="token string">"2021-04-12T22:31:55.809338504-07:00"</span><span class="token punctuation">,</span>
        <span class="token string">"Scope"</span>: <span class="token string">"local"</span><span class="token punctuation">,</span>
        <span class="token string">"Driver"</span>: <span class="token string">"bridge"</span><span class="token punctuation">,</span>
        <span class="token string">"EnableIPv6"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"IPAM"</span>: <span class="token punctuation">{</span>
            <span class="token string">"Driver"</span>: <span class="token string">"default"</span><span class="token punctuation">,</span>
            <span class="token string">"Options"</span>: null<span class="token punctuation">,</span>
            <span class="token string">"Config"</span>: <span class="token punctuation">[</span>
                <span class="token punctuation">{</span>
                    <span class="token string">"Subnet"</span>: <span class="token string">"172.17.0.0/16"</span><span class="token punctuation">,</span>
                    <span class="token string">"Gateway"</span>: <span class="token string">"172.17.0.1"</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">]</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/9c7927a1080c468b9717b85edc219203.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/9c7927a1080c468b9717b85edc219203.jpg" alt="跟着狂神学Docker(精髓篇)_第40张图片" width="650" height="242" style="border:1px solid black;"></a></p> 
  <p><a href="http://img.e-com-net.com/image/info8/19be5492a0f5475198843e7c4a9755bc.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/19be5492a0f5475198843e7c4a9755bc.jpg" alt="跟着狂神学Docker(精髓篇)_第41张图片" width="650" height="286" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-powershell"><span class="token comment"># docker inspect tomcat03</span>

<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker inspect tomcat03 | grep tomcat02</span>
                <span class="token string">"/tomcat02:/tomcat03/tomcat02"</span>


</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/bdce919169864845a6c23a859f2a92b6.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/bdce919169864845a6c23a859f2a92b6.png" alt="在这里插入图片描述" width="523" height="65"></a></p> 
  <p>查看<code>tomcat03</code>里面的<code>/etc/hosts</code>发现有<code>tomcat02</code>的配置</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat03 cat /etc/hosts</span>
127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1	localhost
::1	localhost ip6<span class="token operator">-</span>localhost ip6<span class="token operator">-</span>loopback
fe00::0	ip6<span class="token operator">-</span>localnet
ff00::0	ip6<span class="token operator">-</span>mcastprefix
ff02::1	ip6<span class="token operator">-</span>allnodes
ff02::2	ip6<span class="token operator">-</span>allrouters
172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3	tomcat02 781895f439c2
172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>4	2f3a758730ba

</code></pre> 
  <p><code>--link</code> 本质就是在<code>hosts</code>配置中添加映射</p> 
  <p>现在使用<code>Docker</code>已经不建议使用<code>--link</code>了!</p> 
  <p>自定义网络,不适用<code>docker0</code>!</p> 
  <p><code>docker0</code>问题:不支持容器名连接访问!</p> 
  <h3>自定义网络</h3> 
  <pre><code class="prism language-powershell">docker network
connect     <span class="token operator">--</span> Connect a container to a network
create      <span class="token operator">--</span> Creates a new network with a name specified by the
disconnect  <span class="token operator">--</span> Disconnects a container <span class="token keyword">from</span> a network
inspect     <span class="token operator">--</span> Displays detailed information on a network
<span class="token function">ls</span>          <span class="token operator">--</span> Lists all the networks created by the user
prune       <span class="token operator">--</span> Remove all unused networks
<span class="token function">rm</span>          <span class="token operator">--</span> Deletes one or more networks

</code></pre> 
  <h4>查看所有的docker网络</h4> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network ls</span>
NETWORK ID     NAME      DRIVER    SCOPE
4b16ee2d6925   bridge    bridge    local
eedd07789e82   host      host      local
48629cdb554a   none      null      local

</code></pre> 
  <h4>网络模式</h4> 
  <p><code>bridge</code> :桥接 <code>docker</code>(默认,自己创建也是用bridge模式)</p> 
  <p><code>none</code> :不配置网络,一般不用</p> 
  <p><code>host</code> :和所主机共享网络</p> 
  <p><code>container</code> :容器网络连通(用得少!局限很大)</p> 
  <pre><code class="prism language-powershell"><span class="token comment"># 我们直接启动的命令 --net bridge,而这个就是我们得docker0</span>
<span class="token comment"># bridge就是docker0</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker run -d -P --name tomcat01 tomcat</span>
等价于 => docker run <span class="token operator">-</span>d <span class="token operator">-</span>P <span class="token operator">--</span>name tomcat01 <span class="token operator">--</span>net bridge tomcat

<span class="token comment"># docker0,特点:默认,域名不能访问。 --link可以打通连接,但是很麻烦!</span>
<span class="token comment"># 我们可以 自定义一个网络</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet</span>
9b2a5d2f9fe7f9b9d5c68c20b259fba68e4c510524ade5d0c3afa353a731e92a
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network ls</span>
NETWORK ID     NAME      DRIVER    SCOPE
4b16ee2d6925   bridge    bridge    local
eedd07789e82   host      host      local
9b2a5d2f9fe7   mynet     bridge    local
48629cdb554a   none      null      local


</code></pre> 
  <p>自己的网络创建完成</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network inspect mynet</span>
<span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
        <span class="token string">"Name"</span>: <span class="token string">"mynet"</span><span class="token punctuation">,</span>
        <span class="token string">"Id"</span>: <span class="token string">"9b2a5d2f9fe7f9b9d5c68c20b259fba68e4c510524ade5d0c3afa353a731e92a"</span><span class="token punctuation">,</span>
        <span class="token string">"Created"</span>: <span class="token string">"2021-04-13T22:11:59.671350133-07:00"</span><span class="token punctuation">,</span>
        <span class="token string">"Scope"</span>: <span class="token string">"local"</span><span class="token punctuation">,</span>
        <span class="token string">"Driver"</span>: <span class="token string">"bridge"</span><span class="token punctuation">,</span>
        <span class="token string">"EnableIPv6"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"IPAM"</span>: <span class="token punctuation">{</span>
            <span class="token string">"Driver"</span>: <span class="token string">"default"</span><span class="token punctuation">,</span>
            <span class="token string">"Options"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token string">"Config"</span>: <span class="token punctuation">[</span>
                <span class="token punctuation">{</span>
                    <span class="token string">"Subnet"</span>: <span class="token string">"192.168.0.0/16"</span><span class="token punctuation">,</span>
                    <span class="token string">"Gateway"</span>: <span class="token string">"192.168.0.1"</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">]</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"Internal"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"Attachable"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"Ingress"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"ConfigFrom"</span>: <span class="token punctuation">{</span>
            <span class="token string">"Network"</span>: <span class="token string">""</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"ConfigOnly"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"Containers"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"Options"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"Labels"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">]</span>

</code></pre> 
  <p>启动两个<code>tomcat</code>,再次查看网络情况</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker run -d -P --name tomcat-net-01 --net mynet tomcat</span>
5d0fdad2b907b147c75a10420c172c43f87896db0b82bf9d4b34c889ea43647d
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker run -d -P --name tomcat-net-02 --net mynet tomcat</span>
ac6b288e62f1a8cc764bbdc312b3811936b34fd465a70974d24b67fab7a11566

</code></pre> 
  <p>再次查看自己的网络</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network inspect mynet</span>
<span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
        <span class="token string">"Name"</span>: <span class="token string">"mynet"</span><span class="token punctuation">,</span>
        <span class="token string">"Id"</span>: <span class="token string">"9b2a5d2f9fe7f9b9d5c68c20b259fba68e4c510524ade5d0c3afa353a731e92a"</span><span class="token punctuation">,</span>
        <span class="token string">"Created"</span>: <span class="token string">"2021-04-13T22:11:59.671350133-07:00"</span><span class="token punctuation">,</span>
        <span class="token string">"Scope"</span>: <span class="token string">"local"</span><span class="token punctuation">,</span>
        <span class="token string">"Driver"</span>: <span class="token string">"bridge"</span><span class="token punctuation">,</span>
        <span class="token string">"EnableIPv6"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"IPAM"</span>: <span class="token punctuation">{</span>
            <span class="token string">"Driver"</span>: <span class="token string">"default"</span><span class="token punctuation">,</span>
            <span class="token string">"Options"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token string">"Config"</span>: <span class="token punctuation">[</span>
                <span class="token punctuation">{</span>
                    <span class="token string">"Subnet"</span>: <span class="token string">"192.168.0.0/16"</span><span class="token punctuation">,</span>
                    <span class="token string">"Gateway"</span>: <span class="token string">"192.168.0.1"</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">]</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"Internal"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"Attachable"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"Ingress"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"ConfigFrom"</span>: <span class="token punctuation">{</span>
            <span class="token string">"Network"</span>: <span class="token string">""</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"ConfigOnly"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"Containers"</span>: <span class="token punctuation">{</span>
            <span class="token string">"5d0fdad2b907b147c75a10420c172c43f87896db0b82bf9d4b34c889ea43647d"</span>: <span class="token punctuation">{</span>
                <span class="token string">"Name"</span>: <span class="token string">"tomcat-net-01"</span><span class="token punctuation">,</span>
                <span class="token string">"EndpointID"</span>: <span class="token string">"0cde983fd3f3d3fee2630379d0f149c6e9bd851bd1623f64d08a441e3372606e"</span><span class="token punctuation">,</span>
                <span class="token string">"MacAddress"</span>: <span class="token string">"02:42:c0:a8:00:02"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv4Address"</span>: <span class="token string">"192.168.0.2/16"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv6Address"</span>: <span class="token string">""</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token string">"ac6b288e62f1a8cc764bbdc312b3811936b34fd465a70974d24b67fab7a11566"</span>: <span class="token punctuation">{</span>
                <span class="token string">"Name"</span>: <span class="token string">"tomcat-net-02"</span><span class="token punctuation">,</span>
                <span class="token string">"EndpointID"</span>: <span class="token string">"6119e2fb7bf569b8790af0158710d0bd4db9a2ec4fe63c927c2e28d06c5a4b3c"</span><span class="token punctuation">,</span>
                <span class="token string">"MacAddress"</span>: <span class="token string">"02:42:c0:a8:00:03"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv4Address"</span>: <span class="token string">"192.168.0.3/16"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv6Address"</span>: <span class="token string">""</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"Options"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"Labels"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">]</span>

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/1e0f2fcb806043abba2c1229dbc400e0.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/1e0f2fcb806043abba2c1229dbc400e0.jpg" alt="跟着狂神学Docker(精髓篇)_第42张图片" width="650" height="197" style="border:1px solid black;"></a><br> 再次测试<code>ping</code>链接</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat-net-01 ping 192.168.0.3</span>
PING 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3 <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span> 56<span class="token punctuation">(</span>84<span class="token punctuation">)</span> bytes of <span class="token keyword">data</span><span class="token punctuation">.</span>
64 bytes <span class="token keyword">from</span> 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3: icmp_seq=1 ttl=64 time=0<span class="token punctuation">.</span>177 ms
64 bytes <span class="token keyword">from</span> 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3: icmp_seq=2 ttl=64 time=0<span class="token punctuation">.</span>071 ms
64 bytes <span class="token keyword">from</span> 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3: icmp_seq=3 ttl=64 time=0<span class="token punctuation">.</span>084 ms
64 bytes <span class="token keyword">from</span> 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3: icmp_seq=4 ttl=64 time=0<span class="token punctuation">.</span>080 ms
64 bytes <span class="token keyword">from</span> 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3: icmp_seq=5 ttl=64 time=0<span class="token punctuation">.</span>089 ms
^C
<span class="token operator">--</span><span class="token operator">-</span> 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3 ping statistics <span class="token operator">--</span><span class="token operator">-</span>
5 packets transmitted<span class="token punctuation">,</span> 5 received<span class="token punctuation">,</span> 0<span class="token operator">%</span> packet loss<span class="token punctuation">,</span> time 20ms
rtt min<span class="token operator">/</span>avg<span class="token operator">/</span>max<span class="token operator">/</span>mdev = 0<span class="token punctuation">.</span>071<span class="token operator">/</span>0<span class="token punctuation">.</span>100<span class="token operator">/</span>0<span class="token punctuation">.</span>177<span class="token operator">/</span>0<span class="token punctuation">.</span>039 ms
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat-net-01 ping tomcat-net-02</span>
PING tomcat<span class="token operator">-</span>net<span class="token operator">-</span>02 <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span> 56<span class="token punctuation">(</span>84<span class="token punctuation">)</span> bytes of <span class="token keyword">data</span><span class="token punctuation">.</span>
64 bytes <span class="token keyword">from</span> tomcat<span class="token operator">-</span>net<span class="token operator">-</span>02<span class="token punctuation">.</span>mynet <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span>: icmp_seq=1 ttl=64 time=0<span class="token punctuation">.</span>235 ms
64 bytes <span class="token keyword">from</span> tomcat<span class="token operator">-</span>net<span class="token operator">-</span>02<span class="token punctuation">.</span>mynet <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span>: icmp_seq=2 ttl=64 time=0<span class="token punctuation">.</span>117 ms
64 bytes <span class="token keyword">from</span> tomcat<span class="token operator">-</span>net<span class="token operator">-</span>02<span class="token punctuation">.</span>mynet <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span>: icmp_seq=3 ttl=64 time=0<span class="token punctuation">.</span>066 ms
64 bytes <span class="token keyword">from</span> tomcat<span class="token operator">-</span>net<span class="token operator">-</span>02<span class="token punctuation">.</span>mynet <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>3<span class="token punctuation">)</span>: icmp_seq=4 ttl=64 time=0<span class="token punctuation">.</span>111 ms
^C
<span class="token operator">--</span><span class="token operator">-</span> tomcat<span class="token operator">-</span>net<span class="token operator">-</span>02 ping statistics <span class="token operator">--</span><span class="token operator">-</span>
4 packets transmitted<span class="token punctuation">,</span> 4 received<span class="token punctuation">,</span> 0<span class="token operator">%</span> packet loss<span class="token punctuation">,</span> time 5ms
rtt min<span class="token operator">/</span>avg<span class="token operator">/</span>max<span class="token operator">/</span>mdev = 0<span class="token punctuation">.</span>066<span class="token operator">/</span>0<span class="token punctuation">.</span>132<span class="token operator">/</span>0<span class="token punctuation">.</span>235<span class="token operator">/</span>0<span class="token punctuation">.</span>063 ms

</code></pre> 
  <p>我们自定义的网络<code>docker</code>当我们维护好了对应的关系,推荐我们平时这样使用网络!</p> 
  <h4>好处:</h4> 
  <p><code>redis</code>-不同的集群使用不同的网络,保证集群是安全和健康的</p> 
  <p><code>mysql</code>-不同的集群使用不同的网络,保证集群是安全和健康的<br> <a href="http://img.e-com-net.com/image/info8/73ff83c2967747f3bcfd0de13577e1e2.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/73ff83c2967747f3bcfd0de13577e1e2.jpg" alt="跟着狂神学Docker(精髓篇)_第43张图片" width="650" height="255" style="border:1px solid black;"></a></p> 
  <h3>网络连通</h3> 
  <p><a href="http://img.e-com-net.com/image/info8/7b3d59d526b348b29cec7b328ddccfda.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/7b3d59d526b348b29cec7b328ddccfda.jpg" alt="跟着狂神学Docker(精髓篇)_第44张图片" width="650" height="396" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker ps</span>
CONTAINER ID   IMAGE     COMMAND             CREATED             STATUS             PORTS                     NAMES
ac6b288e62f1   tomcat    <span class="token string">"catalina.sh run"</span>   16 minutes ago      Up 16 minutes      0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:49156<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp   tomcat<span class="token operator">-</span>net<span class="token operator">-</span>02
5d0fdad2b907   tomcat    <span class="token string">"catalina.sh run"</span>   16 minutes ago      Up 16 minutes      0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:49155<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp   tomcat<span class="token operator">-</span>net<span class="token operator">-</span>01
2f3a758730ba   tomcat    <span class="token string">"catalina.sh run"</span>   About an hour ago   Up About an hour   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:49154<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp   tomcat03
781895f439c2   tomcat    <span class="token string">"catalina.sh run"</span>   About an hour ago   Up About an hour   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:49153<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp   tomcat02
4b0e289d67e1   tomcat    <span class="token string">"catalina.sh run"</span>   2 days ago          Up 2 hours         0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:3355<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp    tomcat01
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network --help</span>

Usage:  docker network COMMAND

Manage networks

Commands:
  connect     Connect a container to a network
  create      Create a network
  disconnect  Disconnect a container <span class="token keyword">from</span> a network
  inspect     Display detailed information on one or more networks
  <span class="token function">ls</span>          List networks
  prune       Remove all unused networks
  <span class="token function">rm</span>          Remove one or more networks

Run <span class="token string">'docker network COMMAND --help'</span> <span class="token keyword">for</span> more information on a command<span class="token punctuation">.</span>

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/2e80540511e94f1888f3ea3032474e9c.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/2e80540511e94f1888f3ea3032474e9c.jpg" alt="跟着狂神学Docker(精髓篇)_第45张图片" width="650" height="240" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network connect --help</span>

Usage:  docker network connect <span class="token namespace">[OPTIONS]</span> NETWORK CONTAINER

Connect a container to a network

Options:
      <span class="token operator">--</span>alias strings           Add network<span class="token operator">-</span>scoped alias <span class="token keyword">for</span> the container
      <span class="token operator">--</span>driver<span class="token operator">-</span>opt strings      driver options <span class="token keyword">for</span> the network
      <span class="token operator">--</span>ip string               IPv4 address <span class="token punctuation">(</span>e<span class="token punctuation">.</span>g<span class="token punctuation">.</span><span class="token punctuation">,</span> 172<span class="token punctuation">.</span>30<span class="token punctuation">.</span>100<span class="token punctuation">.</span>104<span class="token punctuation">)</span>
      <span class="token operator">--</span>ip6 string              IPv6 address <span class="token punctuation">(</span>e<span class="token punctuation">.</span>g<span class="token punctuation">.</span><span class="token punctuation">,</span> 2001:db8::33<span class="token punctuation">)</span>
      <span class="token operator">--</span>link list               Add link to another container
      <span class="token operator">--</span>link<span class="token operator">-</span>local<span class="token operator">-</span>ip strings   Add a link<span class="token operator">-</span>local address <span class="token keyword">for</span> the container

</code></pre> 
  <h4>测试打通<code>tomcat01</code>和<code>mynet</code></h4> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network connect mynet tomcat01</span>
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network inspect mynet</span>
<span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
        <span class="token string">"Name"</span>: <span class="token string">"mynet"</span><span class="token punctuation">,</span>
        <span class="token string">"Id"</span>: <span class="token string">"9b2a5d2f9fe7f9b9d5c68c20b259fba68e4c510524ade5d0c3afa353a731e92a"</span><span class="token punctuation">,</span>
        <span class="token string">"Created"</span>: <span class="token string">"2021-04-13T22:11:59.671350133-07:00"</span><span class="token punctuation">,</span>
        <span class="token string">"Scope"</span>: <span class="token string">"local"</span><span class="token punctuation">,</span>
        <span class="token string">"Driver"</span>: <span class="token string">"bridge"</span><span class="token punctuation">,</span>
        <span class="token string">"EnableIPv6"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"IPAM"</span>: <span class="token punctuation">{</span>
            <span class="token string">"Driver"</span>: <span class="token string">"default"</span><span class="token punctuation">,</span>
            <span class="token string">"Options"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token string">"Config"</span>: <span class="token punctuation">[</span>
                <span class="token punctuation">{</span>
                    <span class="token string">"Subnet"</span>: <span class="token string">"192.168.0.0/16"</span><span class="token punctuation">,</span>
                    <span class="token string">"Gateway"</span>: <span class="token string">"192.168.0.1"</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">]</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"Internal"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"Attachable"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"Ingress"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"ConfigFrom"</span>: <span class="token punctuation">{</span>
            <span class="token string">"Network"</span>: <span class="token string">""</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"ConfigOnly"</span>: false<span class="token punctuation">,</span>
        <span class="token string">"Containers"</span>: <span class="token punctuation">{</span>
            <span class="token string">"4b0e289d67e1837e9d0b0ee5d0c021cd5ec0c857883773bab5be9591979fd316"</span>: <span class="token punctuation">{</span>
                <span class="token string">"Name"</span>: <span class="token string">"tomcat01"</span><span class="token punctuation">,</span>
                <span class="token string">"EndpointID"</span>: <span class="token string">"c5dc34f5cb12ce267461147c41a358c286c5ad231fe4557d7bd4c4276779e4be"</span><span class="token punctuation">,</span>
                <span class="token string">"MacAddress"</span>: <span class="token string">"02:42:c0:a8:00:04"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv4Address"</span>: <span class="token string">"192.168.0.4/16"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv6Address"</span>: <span class="token string">""</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token string">"5d0fdad2b907b147c75a10420c172c43f87896db0b82bf9d4b34c889ea43647d"</span>: <span class="token punctuation">{</span>
                <span class="token string">"Name"</span>: <span class="token string">"tomcat-net-01"</span><span class="token punctuation">,</span>
                <span class="token string">"EndpointID"</span>: <span class="token string">"0cde983fd3f3d3fee2630379d0f149c6e9bd851bd1623f64d08a441e3372606e"</span><span class="token punctuation">,</span>
                <span class="token string">"MacAddress"</span>: <span class="token string">"02:42:c0:a8:00:02"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv4Address"</span>: <span class="token string">"192.168.0.2/16"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv6Address"</span>: <span class="token string">""</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token string">"ac6b288e62f1a8cc764bbdc312b3811936b34fd465a70974d24b67fab7a11566"</span>: <span class="token punctuation">{</span>
                <span class="token string">"Name"</span>: <span class="token string">"tomcat-net-02"</span><span class="token punctuation">,</span>
                <span class="token string">"EndpointID"</span>: <span class="token string">"6119e2fb7bf569b8790af0158710d0bd4db9a2ec4fe63c927c2e28d06c5a4b3c"</span><span class="token punctuation">,</span>
                <span class="token string">"MacAddress"</span>: <span class="token string">"02:42:c0:a8:00:03"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv4Address"</span>: <span class="token string">"192.168.0.3/16"</span><span class="token punctuation">,</span>
                <span class="token string">"IPv6Address"</span>: <span class="token string">""</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"Options"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string">"Labels"</span>: <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">]</span>

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/7193ddc4652442c09ee693ef6b0ead5a.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/7193ddc4652442c09ee693ef6b0ead5a.jpg" alt="跟着狂神学Docker(精髓篇)_第46张图片" width="650" height="258" style="border:1px solid black;"></a><br> 连通之后就是将<code>tomcat01</code>放到<code>mynet</code>下</p> 
  <p>一个容器两个ip地址</p> 
  <p><a href="http://img.e-com-net.com/image/info8/7b3d59d526b348b29cec7b328ddccfda.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/7b3d59d526b348b29cec7b328ddccfda.jpg" alt="跟着狂神学Docker(精髓篇)_第47张图片" width="650" height="396" style="border:1px solid black;"></a><br> 测试成功</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it tomcat01 ping tomcat-net-01</span>
PING tomcat<span class="token operator">-</span>net<span class="token operator">-</span>01 <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">)</span> 56<span class="token punctuation">(</span>84<span class="token punctuation">)</span> bytes of <span class="token keyword">data</span><span class="token punctuation">.</span>
64 bytes <span class="token keyword">from</span> tomcat<span class="token operator">-</span>net<span class="token operator">-</span>01<span class="token punctuation">.</span>mynet <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">)</span>: icmp_seq=1 ttl=64 time=0<span class="token punctuation">.</span>368 ms
64 bytes <span class="token keyword">from</span> tomcat<span class="token operator">-</span>net<span class="token operator">-</span>01<span class="token punctuation">.</span>mynet <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">)</span>: icmp_seq=2 ttl=64 time=0<span class="token punctuation">.</span>261 ms
64 bytes <span class="token keyword">from</span> tomcat<span class="token operator">-</span>net<span class="token operator">-</span>01<span class="token punctuation">.</span>mynet <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">)</span>: icmp_seq=3 ttl=64 time=0<span class="token punctuation">.</span>097 ms
64 bytes <span class="token keyword">from</span> tomcat<span class="token operator">-</span>net<span class="token operator">-</span>01<span class="token punctuation">.</span>mynet <span class="token punctuation">(</span>192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">)</span>: icmp_seq=4 ttl=64 time=0<span class="token punctuation">.</span>070 ms

</code></pre> 
  <p><code>tomcat01</code> 已经打通<code>tomcat02</code> 还没打通</p> 
  <h4>结论:</h4> 
  <p>假设要跨网络操作别人,就需要使用<code>docker network connect</code> 连通!</p> 
  <h3>实战:部署Redis集群</h3> 
  <p><a href="http://img.e-com-net.com/image/info8/84745b079b0f4b44ba818aa924b9cdb8.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/84745b079b0f4b44ba818aa924b9cdb8.jpg" alt="跟着狂神学Docker(精髓篇)_第48张图片" width="650" height="396" style="border:1px solid black;"></a></p> 
  <h4>前期准备</h4> 
  <p>先停掉所有容器</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker ps</span>
CONTAINER ID   IMAGE     COMMAND             CREATED       STATUS       PORTS                     NAMES
ac6b288e62f1   tomcat    <span class="token string">"catalina.sh run"</span>   2 hours ago   Up 2 hours   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:49156<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp   tomcat<span class="token operator">-</span>net<span class="token operator">-</span>02
5d0fdad2b907   tomcat    <span class="token string">"catalina.sh run"</span>   2 hours ago   Up 2 hours   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:49155<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp   tomcat<span class="token operator">-</span>net<span class="token operator">-</span>01
2f3a758730ba   tomcat    <span class="token string">"catalina.sh run"</span>   3 hours ago   Up 3 hours   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:49154<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp   tomcat03
781895f439c2   tomcat    <span class="token string">"catalina.sh run"</span>   3 hours ago   Up 3 hours   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:49153<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp   tomcat02
4b0e289d67e1   tomcat    <span class="token string">"catalina.sh run"</span>   2 days ago    Up 3 hours   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:3355<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp    tomcat01
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker rm -f $(docker ps -aq)</span>
ac6b288e62f1
5d0fdad2b907
2f3a758730ba
781895f439c2
cc4db8053534
4d38084a7c0b
b77396e55db3
468db5f02628
8a02b6fddfe3
465894e34af8
8e2660858dca
f8bd9a180286
0be9ef3e0f75
330f5a75c399
a35688cedc66
5b1e64d8bbc0
7589b4d9d9a1
efbb2086dd82
9da019832a38
57700a38b6e2
4d5c745133e4
04c3a127d159
e846cffc9d72
3f00b72dfde0
4b0e289d67e1
ff130a73542d
872a5b63a024
1682649bdcf0
497d37843c8c
e7f19736f3db
56f47d6d2f36
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker images</span>
REPOSITORY             TAG       IMAGE ID       CREATED         SIZE
yanghuihui520<span class="token operator">/</span>tomcat   1<span class="token punctuation">.</span>0       62c96b0fe815   19 hours ago    690MB
huangjialin<span class="token operator">/</span>tomcat     1<span class="token punctuation">.</span>0       62c96b0fe815   19 hours ago    690MB
diytomcat              latest    62c96b0fe815   19 hours ago    690MB
cmd<span class="token operator">-</span>test               0<span class="token punctuation">.</span>1       0e927777d383   22 hours ago    209MB
mysentos               0<span class="token punctuation">.</span>1       2315251fefdd   23 hours ago    291MB
huangjialin<span class="token operator">/</span>centos     1<span class="token punctuation">.</span>0       74f0e59c6da4   40 hours ago    209MB
tomcat02<span class="token punctuation">.</span>1<span class="token punctuation">.</span>0           latest    f5946bde7e99   45 hours ago    672MB
tomcat                 8         926c7fd4777e   3 days ago      533MB
tomcat                 latest    bd431ca8553c   3 days ago      667MB
nginx                  latest    519e12e2a84a   3 days ago      133MB
mysql                  5<span class="token punctuation">.</span>7       450379344707   4 days ago      449MB
portainer<span class="token operator">/</span>portainer    latest    580c0e4e98b0   3 weeks ago     79<span class="token punctuation">.</span>1MB
hello<span class="token operator">-</span>world            latest    d1165f221234   5 weeks ago     13<span class="token punctuation">.</span>3kB
centos                 latest    300e315adb2f   4 months ago    209MB
elasticsearch          7<span class="token punctuation">.</span>6<span class="token punctuation">.</span>2     f29a1ee41030   12 months ago   791MB
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker ps</span>
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

</code></pre> 
  <h4>设置redis集群网卡及查看</h4> 
  <pre><code class="prism language-powershell">docker network create redis <span class="token operator">--</span>subnet 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token operator">/</span>16
docker network <span class="token function">ls</span>
docker network inspect redis


</code></pre> 
  <h4>redis节点创建及设置</h4> 
  <pre><code class="prism language-powershell"><span class="token keyword">for</span> port in $<span class="token punctuation">(</span>seq 1 6<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">do</span>
mkdir <span class="token operator">-</span>p <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span>conf
touch <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
<span class="token function">cat</span> << EOF ><span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
port 6379
bind 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0
cluster<span class="token operator">-</span>enabled yes
cluster<span class="token operator">-</span>config<span class="token operator">-</span>file nodes<span class="token punctuation">.</span>conf
cluster<span class="token operator">-</span>node<span class="token operator">-</span>timeout 5000
cluster<span class="token operator">-</span>announce<span class="token operator">-</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1$<span class="token punctuation">{</span>port<span class="token punctuation">}</span>
cluster<span class="token operator">-</span>announce<span class="token operator">-</span>port 6379
cluster<span class="token operator">-</span>announce<span class="token operator">-</span>bus<span class="token operator">-</span>port 16379
appendonly yes
EOF
done 


</code></pre> 
  <h4>拉取redis镜像并启动redis节点</h4> 
  <pre><code class="prism language-powershell"><span class="token comment"># 通过脚本运行六个redis</span>
<span class="token keyword">for</span> port in $<span class="token punctuation">(</span>seq 1 6<span class="token punctuation">)</span><span class="token punctuation">;</span>\
docker run <span class="token operator">-</span>p 637$<span class="token punctuation">{</span>port<span class="token punctuation">}</span>:6379 <span class="token operator">-</span>p 1667$<span class="token punctuation">{</span>port<span class="token punctuation">}</span>:16379 <span class="token operator">--</span>name redis<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span> \
<span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
<span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
<span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1$<span class="token punctuation">{</span>port<span class="token punctuation">}</span> redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
docker exec <span class="token operator">-</span>it redis<span class="token operator">-</span>1 <span class="token operator">/</span>bin<span class="token operator">/</span>sh <span class="token comment">#redis默认没有bash</span>
redis<span class="token operator">-</span><span class="token function">cli</span> <span class="token operator">--</span>cluster create 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379  <span class="token operator">--</span>cluster<span class="token operator">-</span>replicas 1

</code></pre> 
  <pre><code class="prism language-powershell">/<span class="token operator">/</span>模板
docker run <span class="token operator">-</span>p 637$<span class="token punctuation">{</span>port<span class="token punctuation">}</span>:6379 <span class="token operator">-</span>p 1667$<span class="token punctuation">{</span>port<span class="token punctuation">}</span>:16379 <span class="token operator">--</span>name redis<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span> \
<span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
<span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
<span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1$<span class="token punctuation">{</span>port<span class="token punctuation">}</span> redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf

</code></pre> 
  <pre><code class="prism language-powershell">/<span class="token operator">/</span>节点1
docker run <span class="token operator">-</span>p 6371:6379 <span class="token operator">-</span>p 16371:16379 <span class="token operator">--</span>name redis<span class="token operator">-</span>1 \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>1<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>1<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
 <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf

</code></pre> 
  <pre><code class="prism language-powershell">/<span class="token operator">/</span>节点2
docker run <span class="token operator">-</span>p 6372:6379 <span class="token operator">-</span>p 16372:16379 <span class="token operator">--</span>name redis<span class="token operator">-</span>2 \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>2<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>2<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
 <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf

</code></pre> 
  <pre><code class="prism language-powershell">/<span class="token operator">/</span>节点3
docker run <span class="token operator">-</span>p 6373:6379 <span class="token operator">-</span>p 16373:16379 <span class="token operator">--</span>name redis<span class="token operator">-</span>3 \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>3<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>3<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
 <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf

</code></pre> 
  <pre><code class="prism language-powershell">/<span class="token operator">/</span>节点4
docker run <span class="token operator">-</span>p 6374:6379 <span class="token operator">-</span>p 16374:16379 <span class="token operator">--</span>name redis<span class="token operator">-</span>4 \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>4data:<span class="token operator">/</span><span class="token keyword">data</span> \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>4<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
 <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf

</code></pre> 
  <pre><code class="prism language-powershell">/<span class="token operator">/</span>节点5
docker run <span class="token operator">-</span>p 6375:6379 <span class="token operator">-</span>p 16375:16379 <span class="token operator">--</span>name redis<span class="token operator">-</span>5 \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>5<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>5<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
 <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf

</code></pre> 
  <pre><code class="prism language-powershell">/<span class="token operator">/</span>节点6
docker run <span class="token operator">-</span>p 6376:6379 <span class="token operator">-</span>p 16376:16379 <span class="token operator">--</span>name redis<span class="token operator">-</span>6 \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>6<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
 <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>6<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
 <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf


</code></pre> 
  <h4>以交互模式进入redis节点内</h4> 
  <pre><code class="prism language-powershell">docker exec <span class="token operator">-</span>it redis<span class="token operator">-</span>1 <span class="token operator">/</span>bin<span class="token operator">/</span>sh

</code></pre> 
  <h4>创建redis集群</h4> 
  <pre><code class="prism language-powershell">redis<span class="token operator">-</span><span class="token function">cli</span> <span class="token operator">--</span>cluster create 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379 \
172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379 \
172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379 <span class="token operator">--</span>cluster<span class="token operator">-</span>replicas 1

</code></pre> 
  <h4>运行成功界面如下,(主从复制)集群创建成功</h4> 
  <pre><code class="prism language-powershell"><span class="token operator">/</span><span class="token keyword">data</span> <span class="token comment"># redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 \</span>
> 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379 \
> 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379 <span class="token operator">--</span>cluster<span class="token operator">-</span>replicas 1
>>> Performing hash slots allocation on 6 nodes<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
Master<span class="token punctuation">[</span>0<span class="token punctuation">]</span> <span class="token operator">-</span>> Slots 0 <span class="token operator">-</span> 5460
Master<span class="token punctuation">[</span>1<span class="token punctuation">]</span> <span class="token operator">-</span>> Slots 5461 <span class="token operator">-</span> 10922
Master<span class="token punctuation">[</span>2<span class="token punctuation">]</span> <span class="token operator">-</span>> Slots 10923 <span class="token operator">-</span> 16383
Adding replica 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379 to 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379
Adding replica 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379 to 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379
Adding replica 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379 to 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379
M: af21836f327964924ddfd99eadd0f86c4be2b998 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379
   slots:<span class="token punctuation">[</span>0<span class="token operator">-</span>5460<span class="token punctuation">]</span> <span class="token punctuation">(</span>5461 slots<span class="token punctuation">)</span> master
M: b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379
   slots:<span class="token punctuation">[</span>5461<span class="token operator">-</span>10922<span class="token punctuation">]</span> <span class="token punctuation">(</span>5462 slots<span class="token punctuation">)</span> master
M: c040bae27420e3fe503d79cad47816123462262a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379
   slots:<span class="token punctuation">[</span>10923<span class="token operator">-</span>16383<span class="token punctuation">]</span> <span class="token punctuation">(</span>5461 slots<span class="token punctuation">)</span> master
S: 24bf6f3296119d93f82232555784bbdb1a72697e 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379
   replicates c040bae27420e3fe503d79cad47816123462262a
S: 20a534198c68dd48b5a533b0ee4b1d447cc6b1f6 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379
   replicates af21836f327964924ddfd99eadd0f86c4be2b998
S: 65d83f48f4884e26dc986a60cc03aa33e22dd48a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379
   replicates b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62
Can I <span class="token function">set</span> the above configuration? <span class="token punctuation">(</span><span class="token function">type</span> <span class="token string">'yes'</span> to accept<span class="token punctuation">)</span>: yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting <span class="token keyword">for</span> the cluster to join
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
>>> Performing Cluster Check <span class="token punctuation">(</span><span class="token keyword">using</span> node 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379<span class="token punctuation">)</span>
M: af21836f327964924ddfd99eadd0f86c4be2b998 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379
   slots:<span class="token punctuation">[</span>0<span class="token operator">-</span>5460<span class="token punctuation">]</span> <span class="token punctuation">(</span>5461 slots<span class="token punctuation">)</span> master
   1 additional replica<span class="token punctuation">(</span>s<span class="token punctuation">)</span>
S: 20a534198c68dd48b5a533b0ee4b1d447cc6b1f6 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379
   slots: <span class="token punctuation">(</span>0 slots<span class="token punctuation">)</span> slave
   replicates af21836f327964924ddfd99eadd0f86c4be2b998
S: 65d83f48f4884e26dc986a60cc03aa33e22dd48a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379
   slots: <span class="token punctuation">(</span>0 slots<span class="token punctuation">)</span> slave
   replicates b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62
S: 24bf6f3296119d93f82232555784bbdb1a72697e 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379
   slots: <span class="token punctuation">(</span>0 slots<span class="token punctuation">)</span> slave
   replicates c040bae27420e3fe503d79cad47816123462262a
M: b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379
   slots:<span class="token punctuation">[</span>5461<span class="token operator">-</span>10922<span class="token punctuation">]</span> <span class="token punctuation">(</span>5462 slots<span class="token punctuation">)</span> master
   1 additional replica<span class="token punctuation">(</span>s<span class="token punctuation">)</span>
M: c040bae27420e3fe503d79cad47816123462262a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379
   slots:<span class="token punctuation">[</span>10923<span class="token operator">-</span>16383<span class="token punctuation">]</span> <span class="token punctuation">(</span>5461 slots<span class="token punctuation">)</span> master
   1 additional replica<span class="token punctuation">(</span>s<span class="token punctuation">)</span>
<span class="token namespace">[OK]</span> All nodes agree about slots configuration<span class="token punctuation">.</span>
>>> Check <span class="token keyword">for</span> open slots<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
>>> Check slots coverage<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token namespace">[OK]</span> All 16384 slots covered<span class="token punctuation">.</span>
</code></pre> 
  <h4>创建集群成功后,可以进一步查看集群配置,并进行测试</h4> 
  <pre><code class="prism language-powershell"><span class="token operator">/</span><span class="token keyword">data</span> <span class="token comment"># redis-cli -c   //-c表示集群</span>

127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1:6379> cluster info  <span class="token operator">/</span><span class="token operator">/</span>集群配置
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:613
cluster_stats_messages_pong_sent:614
cluster_stats_messages_sent:1227
cluster_stats_messages_ping_received:609
cluster_stats_messages_pong_received:613
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:1227

127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1:6379> cluster nodes <span class="token operator">/</span><span class="token operator">/</span>集群节点信息
887c5ded66d075b6d29602f89a6adc7d1471d22c 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379@16379 myself<span class="token punctuation">,</span>master <span class="token operator">-</span> 0 1598439359000 1 connected 0<span class="token operator">-</span>5460
e6b5521d86abc96fe2e51e40be8fbb1f23da9fe7 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379@16379 slave 887c5ded66d075b6d29602f89a6adc7d1471d22c 0 1598439359580 5 connected
d75a9db032f13d9484909b2d0d4724f44e3f1c23 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379@16379 slave db3caa7ba307a27a8ef30bf0b26ba91bfb89e932 0 1598439358578 4 connected
b6add5e06fd958045f90f29bcbbf219753798ef6 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379@16379 slave 7684dfd02929085817de59f334d241e6cbcd1e99 0 1598439358578 6 connected
7684dfd02929085817de59f334d241e6cbcd1e99 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379@16379 master <span class="token operator">-</span> 0 1598439360082 2 connected 5461<span class="token operator">-</span>10922
db3caa7ba307a27a8ef30bf0b26ba91bfb89e932 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379@16379 master <span class="token operator">-</span> 0 1598439359079 3 connected 10923<span class="token operator">-</span>16383

</code></pre> 
  <h4>关于redis集群高可用的简单测试</h4> 
  <pre><code class="prism language-powershell">127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1:6379> <span class="token function">set</span> msg <span class="token string">"I Love YHH"</span>	<span class="token operator">/</span><span class="token operator">/</span>设置值
<span class="token operator">-</span>> Redirected to slot <span class="token punctuation">[</span>6257<span class="token punctuation">]</span> located at 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379
OK
172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379> get msg	<span class="token operator">/</span><span class="token operator">/</span>取值
<span class="token string">"I Love YHH"</span>

<span class="token operator">/</span><span class="token operator">/</span>新开窗口
<span class="token operator">/</span><span class="token operator">/</span>用docker stop模拟存储msg值的redis主机宕机
<span class="token namespace">[root@localhost /]</span><span class="token comment"># docker ps</span>
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                                              NAMES
430f29b7fdd2   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   12 minutes ago   Up 12 minutes   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6376<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16376<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>6
343b4d098652   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   12 minutes ago   Up 12 minutes   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6375<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16375<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>5
f2ce7d2db9ba   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   12 minutes ago   Up 12 minutes   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6374<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16374<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>4
7411b8f6c7d5   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   12 minutes ago   Up 12 minutes   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6373<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16373<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>3
b7a12d144758   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   12 minutes ago   Up 12 minutes   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6372<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16372<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>2
d7ce020b171e   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   13 minutes ago   Up 13 minutes   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6371<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16371<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>1

<span class="token namespace">[root@localhost /]</span><span class="token comment"># docker stop redis-2</span>
redis<span class="token operator">-</span>2

<span class="token operator">/</span><span class="token operator">/</span>重新进入集群交互界面,并尝试获取msg消息
172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379> get msg
Could not connect to Redis at 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379: Host is unreachable
<span class="token punctuation">(</span>7<span class="token punctuation">.</span>10s<span class="token punctuation">)</span>
not connected> <span class="token keyword">exit</span>
<span class="token operator">/</span><span class="token keyword">data</span> <span class="token comment"># exit</span>
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker exec -it redis-1 /bin/sh</span>
<span class="token operator">/</span><span class="token keyword">data</span> <span class="token comment"># redis-cli -c</span>
127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1:6379> get msg	<span class="token operator">/</span><span class="token operator">/</span>此时由备用机返回msg
<span class="token operator">-</span>> Redirected to slot <span class="token punctuation">[</span>6257<span class="token punctuation">]</span> located at 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379
<span class="token string">"I Love YHH"</span>

</code></pre> 
  <h4>节点信息</h4> 
  <pre><code class="prism language-powershell">172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379> cluster nodes
c040bae27420e3fe503d79cad47816123462262a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379@16379 master <span class="token operator">-</span> 0 1618385704146 3 connected 10923<span class="token operator">-</span>16383
b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379@16379 master<span class="token punctuation">,</span>fail <span class="token operator">-</span> 1618385356051 1618385354000 2 connected
20a534198c68dd48b5a533b0ee4b1d447cc6b1f6 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379@16379 slave af21836f327964924ddfd99eadd0f86c4be2b998 0 1618385703038 5 connected
24bf6f3296119d93f82232555784bbdb1a72697e 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379@16379 slave c040bae27420e3fe503d79cad47816123462262a 0 1618385703139 4 connected
65d83f48f4884e26dc986a60cc03aa33e22dd48a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379@16379 myself<span class="token punctuation">,</span>master <span class="token operator">-</span> 0 1618385702000 8 connected 5461<span class="token operator">-</span>10922
af21836f327964924ddfd99eadd0f86c4be2b998 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379@16379 master <span class="token operator">-</span> 0 1618385702000 1 connected 0<span class="token operator">-</span>5460

</code></pre> 
  <p><code>docker</code>搭建<code>redis</code>集群完成!<br> 我们使用<code>docker</code>之后,所有的技术都会慢慢变得简单起来!</p> 
  <h4>实际运行</h4> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network create redis --subnet 172.38.0.0/16</span>
ab1607a9953d571bc29eb87c58a7a422b742622b79349421fe3b1d5d84d2c309
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker network ls</span>
NETWORK ID     NAME      DRIVER    SCOPE
4b16ee2d6925   bridge    bridge    local
eedd07789e82   host      host      local
9b2a5d2f9fe7   mynet     bridge    local
48629cdb554a   none      null      local
ab1607a9953d   redis     bridge    local
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># for port in $(seq 1 6);\</span>
> <span class="token keyword">do</span> \
> mkdir <span class="token operator">-</span>p <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span>conf
> touch <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
> <span class="token function">cat</span> << EOF >> <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>$<span class="token punctuation">{</span>port<span class="token punctuation">}</span><span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
> port 6379
> bind 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0
> cluster<span class="token operator">-</span>enabled yes
> cluster<span class="token operator">-</span>config<span class="token operator">-</span>file nodes<span class="token punctuation">.</span>conf
> cluster<span class="token operator">-</span>node<span class="token operator">-</span>timeout 5000
> cluster<span class="token operator">-</span>announce<span class="token operator">-</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1$<span class="token punctuation">{</span>port<span class="token punctuation">}</span>
> cluster<span class="token operator">-</span>announce<span class="token operator">-</span>port 6379
> cluster<span class="token operator">-</span>announce<span class="token operator">-</span>bus<span class="token operator">-</span>port 16379
> appendonly yes
> EOF
> done
<span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># cd /mydata/</span>
<span class="token namespace">[root@localhost mydata]</span><span class="token comment"># ls</span>
redis
<span class="token namespace">[root@localhost mydata]</span><span class="token comment"># cd redis/</span>
<span class="token namespace">[root@localhost redis]</span><span class="token comment"># ls</span>
node<span class="token operator">-</span>1  node<span class="token operator">-</span>2  node<span class="token operator">-</span>3  node<span class="token operator">-</span>4  node<span class="token operator">-</span>5  node<span class="token operator">-</span>6
<span class="token namespace">[root@localhost redis]</span><span class="token comment"># cd node-1</span>
<span class="token namespace">[root@localhost node-1]</span><span class="token comment"># ls</span>
conf
<span class="token namespace">[root@localhost node-1]</span><span class="token comment"># cd conf/</span>
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># ls</span>
redis<span class="token punctuation">.</span>conf
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># cat redis.conf </span>
port 6379
bind 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0
cluster<span class="token operator">-</span>enabled yes
cluster<span class="token operator">-</span>config<span class="token operator">-</span>file nodes<span class="token punctuation">.</span>conf
cluster<span class="token operator">-</span>node<span class="token operator">-</span>timeout 5000
cluster<span class="token operator">-</span>announce<span class="token operator">-</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11
cluster<span class="token operator">-</span>announce<span class="token operator">-</span>port 6379
cluster<span class="token operator">-</span>announce<span class="token operator">-</span>bus<span class="token operator">-</span>port 16379
appendonly yes

<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker run -p 6371:6379 -p 16371:16379 --name redis-1 \</span>
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>1<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>1<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
>  <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
Unable to find image <span class="token string">'redis:5.0.9-alpine3.11'</span> locally
5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11: Pulling <span class="token keyword">from</span> library<span class="token operator">/</span>redis
cbdbe7a5bc2a: Pull complete 
dc0373118a0d: Pull complete 
cfd369fe6256: Pull complete 
3e45770272d9: Pull complete 
558de8ea3153: Pull complete 
a2c652551612: Pull complete 
Digest: sha256:83a3af36d5e57f2901b4783c313720e5fa3ecf0424ba86ad9775e06a9a5e35d0
Status: Downloaded newer image <span class="token keyword">for</span> redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11
d7ce020b171e560c48948a714871f88a39ea8fb2d81aace566990a3174d9dee8
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker run -p 6372:6379 -p 16372:16379 --name redis-2 \</span>
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>2<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>2<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
>  <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
b7a12d144758968a6124d5ac42bac61264f428a72588e942d4827737d71a64bd
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker run -p 6373:6379 -p 16373:16379 --name redis-3 \</span>
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>3<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>3<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
>  <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
7411b8f6c7d5ab059941fb2a0a3f82ed5b02fb8f3554082f112e411019424dce
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker run -p 6374:6379 -p 16374:16379 --name redis-4 \</span>
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>4data:<span class="token operator">/</span><span class="token keyword">data</span> \
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>4<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
>  <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
f2ce7d2db9ba756121715672fef55cfd4dfd92574cb1b1798dc91db0ae815ee5
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker run -p 6375:6379 -p 16375:16379 --name redis-5 \</span>
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>5<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>5<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
>  <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
343b4d0986529851a89d5afb78bc523deb0e7b56d7709e30c4440746cd749211
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker run -p 6376:6379 -p 16376:16379 --name redis-6 \</span>
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>6<span class="token operator">/</span><span class="token keyword">data</span>:<span class="token operator">/</span><span class="token keyword">data</span> \
>  <span class="token operator">-</span>v <span class="token operator">/</span>mydata<span class="token operator">/</span>redis<span class="token operator">/</span>node<span class="token operator">-</span>6<span class="token operator">/</span>conf<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf:<span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf \
>  <span class="token operator">-</span>d <span class="token operator">--</span>net redis <span class="token operator">--</span>ip 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16 redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11 redis<span class="token operator">-</span>server <span class="token operator">/</span>etc<span class="token operator">/</span>redis<span class="token operator">/</span>redis<span class="token punctuation">.</span>conf
430f29b7fdd2ea2e11d08f8c5bbdf9f708b69f7ddcda86f6201acc63e7776746
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker ps</span>
CONTAINER ID   IMAGE                    COMMAND                  CREATED              STATUS              PORTS                                              NAMES
430f29b7fdd2   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   About a minute ago   Up About a minute   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6376<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16376<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>6
343b4d098652   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   About a minute ago   Up About a minute   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6375<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16375<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>5
f2ce7d2db9ba   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   About a minute ago   Up About a minute   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6374<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16374<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>4
7411b8f6c7d5   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   About a minute ago   Up About a minute   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6373<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16373<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>3
b7a12d144758   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   About a minute ago   Up About a minute   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6372<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16372<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>2
d7ce020b171e   redis:5<span class="token punctuation">.</span>0<span class="token punctuation">.</span>9<span class="token operator">-</span>alpine3<span class="token punctuation">.</span>11   <span class="token string">"docker-entrypoint.s…"</span>   2 minutes ago        Up About a minute   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:6371<span class="token operator">-</span>>6379<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:16371<span class="token operator">-</span>>16379<span class="token operator">/</span>tcp   redis<span class="token operator">-</span>1
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker exec -it redis-1 /bin/sh</span>
<span class="token operator">/</span><span class="token keyword">data</span> <span class="token comment"># ls</span>
appendonly<span class="token punctuation">.</span>aof  nodes<span class="token punctuation">.</span>conf
<span class="token operator">/</span><span class="token keyword">data</span> <span class="token comment"># redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 \</span>
> 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379 \
> 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379 <span class="token operator">--</span>cluster<span class="token operator">-</span>replicas 1
>>> Performing hash slots allocation on 6 nodes<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
Master<span class="token punctuation">[</span>0<span class="token punctuation">]</span> <span class="token operator">-</span>> Slots 0 <span class="token operator">-</span> 5460
Master<span class="token punctuation">[</span>1<span class="token punctuation">]</span> <span class="token operator">-</span>> Slots 5461 <span class="token operator">-</span> 10922
Master<span class="token punctuation">[</span>2<span class="token punctuation">]</span> <span class="token operator">-</span>> Slots 10923 <span class="token operator">-</span> 16383
Adding replica 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379 to 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379
Adding replica 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379 to 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379
Adding replica 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379 to 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379
M: af21836f327964924ddfd99eadd0f86c4be2b998 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379
   slots:<span class="token punctuation">[</span>0<span class="token operator">-</span>5460<span class="token punctuation">]</span> <span class="token punctuation">(</span>5461 slots<span class="token punctuation">)</span> master
M: b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379
   slots:<span class="token punctuation">[</span>5461<span class="token operator">-</span>10922<span class="token punctuation">]</span> <span class="token punctuation">(</span>5462 slots<span class="token punctuation">)</span> master
M: c040bae27420e3fe503d79cad47816123462262a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379
   slots:<span class="token punctuation">[</span>10923<span class="token operator">-</span>16383<span class="token punctuation">]</span> <span class="token punctuation">(</span>5461 slots<span class="token punctuation">)</span> master
S: 24bf6f3296119d93f82232555784bbdb1a72697e 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379
   replicates c040bae27420e3fe503d79cad47816123462262a
S: 20a534198c68dd48b5a533b0ee4b1d447cc6b1f6 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379
   replicates af21836f327964924ddfd99eadd0f86c4be2b998
S: 65d83f48f4884e26dc986a60cc03aa33e22dd48a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379
   replicates b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62
Can I <span class="token function">set</span> the above configuration? <span class="token punctuation">(</span><span class="token function">type</span> <span class="token string">'yes'</span> to accept<span class="token punctuation">)</span>: yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting <span class="token keyword">for</span> the cluster to join
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
>>> Performing Cluster Check <span class="token punctuation">(</span><span class="token keyword">using</span> node 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379<span class="token punctuation">)</span>
M: af21836f327964924ddfd99eadd0f86c4be2b998 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379
   slots:<span class="token punctuation">[</span>0<span class="token operator">-</span>5460<span class="token punctuation">]</span> <span class="token punctuation">(</span>5461 slots<span class="token punctuation">)</span> master
   1 additional replica<span class="token punctuation">(</span>s<span class="token punctuation">)</span>
S: 20a534198c68dd48b5a533b0ee4b1d447cc6b1f6 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379
   slots: <span class="token punctuation">(</span>0 slots<span class="token punctuation">)</span> slave
   replicates af21836f327964924ddfd99eadd0f86c4be2b998
S: 65d83f48f4884e26dc986a60cc03aa33e22dd48a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379
   slots: <span class="token punctuation">(</span>0 slots<span class="token punctuation">)</span> slave
   replicates b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62
S: 24bf6f3296119d93f82232555784bbdb1a72697e 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379
   slots: <span class="token punctuation">(</span>0 slots<span class="token punctuation">)</span> slave
   replicates c040bae27420e3fe503d79cad47816123462262a
M: b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379
   slots:<span class="token punctuation">[</span>5461<span class="token operator">-</span>10922<span class="token punctuation">]</span> <span class="token punctuation">(</span>5462 slots<span class="token punctuation">)</span> master
   1 additional replica<span class="token punctuation">(</span>s<span class="token punctuation">)</span>
M: c040bae27420e3fe503d79cad47816123462262a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379
   slots:<span class="token punctuation">[</span>10923<span class="token operator">-</span>16383<span class="token punctuation">]</span> <span class="token punctuation">(</span>5461 slots<span class="token punctuation">)</span> master
   1 additional replica<span class="token punctuation">(</span>s<span class="token punctuation">)</span>
<span class="token namespace">[OK]</span> All nodes agree about slots configuration<span class="token punctuation">.</span>
>>> Check <span class="token keyword">for</span> open slots<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
>>> Check slots coverage<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token namespace">[OK]</span> All 16384 slots covered<span class="token punctuation">.</span>
<span class="token operator">/</span><span class="token keyword">data</span> <span class="token comment"># redis-cli -c</span>
127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1:6379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:382
cluster_stats_messages_pong_sent:382
cluster_stats_messages_sent:764
cluster_stats_messages_ping_received:377
cluster_stats_messages_pong_received:382
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:764
127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1:6379> cluster nodes
20a534198c68dd48b5a533b0ee4b1d447cc6b1f6 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>15:6379@16379 slave af21836f327964924ddfd99eadd0f86c4be2b998 0 1618384814088 5 connected
65d83f48f4884e26dc986a60cc03aa33e22dd48a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379@16379 slave b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62 0 1618384814589 6 connected
af21836f327964924ddfd99eadd0f86c4be2b998 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>11:6379@16379 myself<span class="token punctuation">,</span>master <span class="token operator">-</span> 0 1618384814000 1 connected 0<span class="token operator">-</span>5460
24bf6f3296119d93f82232555784bbdb1a72697e 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>14:6379@16379 slave c040bae27420e3fe503d79cad47816123462262a 0 1618384814000 4 connected
b0cf655ea86ff16e2c6f9a82f3d9f1a3d7dc7c62 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>12:6379@16379 master <span class="token operator">-</span> 0 1618384815096 2 connected 5461<span class="token operator">-</span>10922
c040bae27420e3fe503d79cad47816123462262a 172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>13:6379@16379 master <span class="token operator">-</span> 0 1618384814589 3 connected 10923<span class="token operator">-</span>16383

<span class="token comment"># 后续接上面小结  关于redis集群高可用的简单测试</span>

</code></pre> 
  <h3>SpringBoot微服务打包Docker镜像</h3> 
  <h4>1、构建SpringBoot项目</h4> 
  <p><a href="http://img.e-com-net.com/image/info8/00132e03f83a489ab42103ab301b3dc0.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/00132e03f83a489ab42103ab301b3dc0.jpg" alt="跟着狂神学Docker(精髓篇)_第49张图片" width="650" height="384" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/f69d587cee5f483d85970e5477b838af.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/f69d587cee5f483d85970e5477b838af.jpg" alt="跟着狂神学Docker(精髓篇)_第50张图片" width="650" height="384" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/7d9d7067b9bb45fe95b9ef2701ca6b3b.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/7d9d7067b9bb45fe95b9ef2701ca6b3b.jpg" alt="跟着狂神学Docker(精髓篇)_第51张图片" width="650" height="384" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/a65d09c161a046fe9853b69fbe83aa29.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/a65d09c161a046fe9853b69fbe83aa29.jpg" alt="跟着狂神学Docker(精髓篇)_第52张图片" width="650" height="384" style="border:1px solid black;"></a></p> 
  <h5>配置零星</h5> 
  <p><a href="http://img.e-com-net.com/image/info8/bf15bf5b5090454fa2b864c882b9bda6.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/bf15bf5b5090454fa2b864c882b9bda6.jpg" alt="跟着狂神学Docker(精髓篇)_第53张图片" width="650" height="466" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/7bfe652f05b74d9a805eb4393335f24b.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/7bfe652f05b74d9a805eb4393335f24b.jpg" alt="跟着狂神学Docker(精髓篇)_第54张图片" width="650" height="466" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/7c010c0a923640d2a7d7184c55f53e09.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/7c010c0a923640d2a7d7184c55f53e09.jpg" alt="跟着狂神学Docker(精髓篇)_第55张图片" width="650" height="466" style="border:1px solid black;"></a></p> 
  <h5>编写程序</h5> 
  <p><a href="http://img.e-com-net.com/image/info8/bcfc37de0f51405f87991cb90e630e43.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/bcfc37de0f51405f87991cb90e630e43.jpg" alt="跟着狂神学Docker(精髓篇)_第56张图片" width="650" height="476" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-java"><span class="token keyword">package</span> com<span class="token punctuation">.</span>example<span class="token punctuation">.</span>demo<span class="token punctuation">.</span>controller<span class="token punctuation">;</span>

<span class="token keyword">import</span> org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>RequestMapping<span class="token punctuation">;</span>
<span class="token keyword">import</span> org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>RestController<span class="token punctuation">;</span>

<span class="token annotation punctuation">@RestController</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">HelloController</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@RequestMapping</span><span class="token punctuation">(</span><span class="token string">"/hello"</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> String <span class="token function">hello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token string">"hello,huangjialin"</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

</code></pre> 
  <h5>启动测试</h5> 
  <p>http://127.0.0.1:8080/hello<br> <a href="http://img.e-com-net.com/image/info8/054ddc95536549559c7facc93df24ebf.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/054ddc95536549559c7facc93df24ebf.jpg" alt="跟着狂神学Docker(精髓篇)_第57张图片" width="600" height="197" style="border:1px solid black;"></a></p> 
  <h4>2、打包运行</h4> 
  <p><a href="http://img.e-com-net.com/image/info8/3857b4ddcc1b4f65a5ce3fc24e0769f6.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/3857b4ddcc1b4f65a5ce3fc24e0769f6.jpg" alt="跟着狂神学Docker(精髓篇)_第58张图片" width="650" height="476" style="border:1px solid black;"></a><br> <img src="http://img.e-com-net.com/image/info8/2a6040ae079142a7a61782f4aafa221f.jpg" alt="在这里插入图片描述" width="0" height="0"></p> 
  <h5>本地测试</h5> 
  <p><a href="http://img.e-com-net.com/image/info8/1aa36cb365f64ed88139a3d07900ac1d.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/1aa36cb365f64ed88139a3d07900ac1d.jpg" alt="跟着狂神学Docker(精髓篇)_第59张图片" width="650" height="476" style="border:1px solid black;"></a><br> 找到文件地址<br> <a href="http://img.e-com-net.com/image/info8/b1f51d940c814764974d1c6ebad50e61.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/b1f51d940c814764974d1c6ebad50e61.jpg" alt="跟着狂神学Docker(精髓篇)_第60张图片" width="650" height="331" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/88183f7fa9f940c4afe9524825be2b9b.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/88183f7fa9f940c4afe9524825be2b9b.jpg" alt="跟着狂神学Docker(精髓篇)_第61张图片" width="650" height="331" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/06620407e9ce4d5291ce038780ce7f1a.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/06620407e9ce4d5291ce038780ce7f1a.jpg" alt="跟着狂神学Docker(精髓篇)_第62张图片" width="650" height="410" style="border:1px solid black;"></a><br> 启动成功<br> <a href="http://img.e-com-net.com/image/info8/5b7944aa87524f1ebda065e47c1e3e7a.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/5b7944aa87524f1ebda065e47c1e3e7a.jpg" alt="跟着狂神学Docker(精髓篇)_第63张图片" width="650" height="408" style="border:1px solid black;"></a></p> 
  <h5>安装插件</h5> 
  <p><a href="http://img.e-com-net.com/image/info8/4bf53e88e02c4c3ebd1dec73a0886cf2.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/4bf53e88e02c4c3ebd1dec73a0886cf2.jpg" alt="跟着狂神学Docker(精髓篇)_第64张图片" width="650" height="466" style="border:1px solid black;"></a><br> 这里也可以链接远程仓库<br> <a href="http://img.e-com-net.com/image/info8/839c016af7a44ee6983ecafdfddacebd.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/839c016af7a44ee6983ecafdfddacebd.jpg" alt="跟着狂神学Docker(精髓篇)_第65张图片" width="650" height="466" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/b3c4de252c6c43ff99efabd8a5601758.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/b3c4de252c6c43ff99efabd8a5601758.jpg" alt="跟着狂神学Docker(精髓篇)_第66张图片" width="650" height="425" style="border:1px solid black;"></a></p> 
  <h4>3、编写dockerfile</h4> 
  <pre><code class="prism language-powershell"><span class="token keyword">FROM</span> java:8
<span class="token function">COPY</span> <span class="token operator">*</span><span class="token punctuation">.</span>jar <span class="token operator">/</span>app<span class="token punctuation">.</span>jar
CMD <span class="token punctuation">[</span><span class="token string">"--server.port=8080"</span><span class="token punctuation">]</span>
EXPOSE 8080
ENTRYPOINT <span class="token punctuation">[</span><span class="token string">"java"</span><span class="token punctuation">,</span><span class="token string">"-jar"</span><span class="token punctuation">,</span><span class="token string">"app.jar"</span><span class="token punctuation">]</span>

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/c3bf346161f9414f9bfe01ade256432f.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/c3bf346161f9414f9bfe01ade256432f.jpg" alt="跟着狂神学Docker(精髓篇)_第67张图片" width="413" height="161" style="border:1px solid black;"></a></p> 
  <h5>linux操作</h5> 
  <p>停掉所有容器</p> 
  <pre><code class="prism language-powershell">172<span class="token punctuation">.</span>38<span class="token punctuation">.</span>0<span class="token punctuation">.</span>16:6379> <span class="token keyword">exit</span>
<span class="token operator">/</span><span class="token keyword">data</span> <span class="token comment"># exit</span>
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># docker rm -f $(docker ps -qa)</span>
430f29b7fdd2
343b4d098652
f2ce7d2db9ba
7411b8f6c7d5
b7a12d144758
d7ce020b171e
<span class="token namespace">[root@localhost conf]</span><span class="token comment"># </span>

</code></pre> 
  <p>新建目录<code>idea</code></p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost conf]</span><span class="token comment"># cd /home</span>
<span class="token namespace">[root@localhost home]</span><span class="token comment"># ls</span>
ceshi  dockerfile  docker<span class="token operator">-</span>test<span class="token operator">-</span>volume  huang<span class="token punctuation">.</span>java  huangjialin  huang<span class="token punctuation">.</span>txt  mylinux  mysql  test<span class="token punctuation">.</span>java  testTmp
<span class="token namespace">[root@localhost home]</span><span class="token comment"># mkdir idea</span>
<span class="token namespace">[root@localhost home]</span><span class="token comment"># ls</span>
ceshi  dockerfile  docker<span class="token operator">-</span>test<span class="token operator">-</span>volume  huang<span class="token punctuation">.</span>java  huangjialin  huang<span class="token punctuation">.</span>txt  idea  mylinux  mysql  test<span class="token punctuation">.</span>java  testTmp
<span class="token namespace">[root@localhost home]</span><span class="token comment"># cd idea/</span>
<span class="token namespace">[root@localhost idea]</span><span class="token comment"># ls</span>

</code></pre> 
  <h5>文件传输</h5> 
  <p><a href="http://img.e-com-net.com/image/info8/085c803f2f45478e887f7294eb1c3ea5.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/085c803f2f45478e887f7294eb1c3ea5.jpg" alt="跟着狂神学Docker(精髓篇)_第68张图片" width="650" height="465" style="border:1px solid black;"></a><br> 上传成功</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost idea]</span><span class="token comment"># ls</span>
demo<span class="token operator">-</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">-</span>SNAPSHOT<span class="token punctuation">.</span>jar  Dockerfile
<span class="token namespace">[root@localhost idea]</span><span class="token comment"># ll</span>
total 16672
<span class="token operator">-</span>rw<span class="token operator">-</span>r-<span class="token operator">-</span>r-<span class="token operator">-</span><span class="token punctuation">.</span> 1 root root 17064575 Apr 14 01:54 demo<span class="token operator">-</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1<span class="token operator">-</span>SNAPSHOT<span class="token punctuation">.</span>jar
<span class="token operator">-</span>rw<span class="token operator">-</span>r-<span class="token operator">-</span>r-<span class="token operator">-</span><span class="token punctuation">.</span> 1 root root      111 Apr 14 01:54 Dockerfile

</code></pre> 
  <h4>4、构建镜像</h4> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost idea]</span><span class="token comment"># docker build -t huangjialin666 .</span>
Sending build context to Docker daemon  17<span class="token punctuation">.</span>07MB
Step 1<span class="token operator">/</span>5 : <span class="token keyword">FROM</span> java:8
8: Pulling <span class="token keyword">from</span> library<span class="token operator">/</span>java
5040bd298390: Pull complete 
fce5728aad85: Pull complete 
76610ec20bf5: Pull complete 
60170fec2151: Pull complete 
e98f73de8f0d: Pull complete 
11f7af24ed9c: Pull complete 
49e2d6393f32: Pull complete 
bb9cdec9c7f3: Pull complete 
Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d
Status: Downloaded newer image <span class="token keyword">for</span> java:8
 <span class="token operator">--</span><span class="token operator">-</span>> d23bdf5b1b1b
Step 2<span class="token operator">/</span>5 : <span class="token function">COPY</span> <span class="token operator">*</span><span class="token punctuation">.</span>jar <span class="token operator">/</span>app<span class="token punctuation">.</span>jar
 <span class="token operator">--</span><span class="token operator">-</span>> ca5673d370bc
Step 3<span class="token operator">/</span>5 : CMD <span class="token punctuation">[</span><span class="token string">"--server.port=8080"</span><span class="token punctuation">]</span>
 <span class="token operator">--</span><span class="token operator">-</span>> Running in a62e4ab48902
Removing intermediate container a62e4ab48902
 <span class="token operator">--</span><span class="token operator">-</span>> f341490d9232
Step 4<span class="token operator">/</span>5 : EXPOSE 8080
 <span class="token operator">--</span><span class="token operator">-</span>> Running in 1fbd25817932
Removing intermediate container 1fbd25817932
 <span class="token operator">--</span><span class="token operator">-</span>> 1aba2bcfb483
Step 5<span class="token operator">/</span>5 : ENTRYPOINT <span class="token punctuation">[</span><span class="token string">"java"</span><span class="token punctuation">,</span><span class="token string">"-jar"</span><span class="token punctuation">,</span><span class="token string">"app.jar"</span><span class="token punctuation">]</span>
 <span class="token operator">--</span><span class="token operator">-</span>> Running in 980468eb1893
Removing intermediate container 980468eb1893
 <span class="token operator">--</span><span class="token operator">-</span>> 5285ac7f6cbc
Successfully built 5285ac7f6cbc
Successfully tagged huangjialin666:latest

<span class="token namespace">[root@localhost idea]</span><span class="token comment"># docker images</span>
REPOSITORY             TAG                IMAGE ID       CREATED          SIZE
huangjialin666         latest             5285ac7f6cbc   52 seconds ago   660MB

</code></pre> 
  <h4>5、发布运行</h4> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost idea]</span><span class="token comment"># docker run -d -P --name huangjialin-springboot-web huangjialin666</span>
7621b33ce6b8d30c7c44362897f11cc4d9cbffc493852ed2adc8190848c56008
<span class="token namespace">[root@localhost idea]</span><span class="token comment"># docker ps</span>
CONTAINER ID   IMAGE            COMMAND                  CREATED          STATUS          PORTS                     NAMES
7621b33ce6b8   huangjialin666   <span class="token string">"java -jar app.jar -…"</span>   57 seconds ago   Up 49 seconds   0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:49157<span class="token operator">-</span>>8080<span class="token operator">/</span>tcp   huangjialin<span class="token operator">-</span>springboot<span class="token operator">-</span>web
<span class="token namespace">[root@localhost idea]</span><span class="token comment"># curl 127.0.0.1:49157</span>
<span class="token punctuation">{</span><span class="token string">"timestamp"</span>:<span class="token string">"2021-04-14T09:09:35.052+00:00"</span><span class="token punctuation">,</span><span class="token string">"status"</span>:404<span class="token punctuation">,</span><span class="token string">"error"</span>:<span class="token string">"Not Found"</span><span class="token punctuation">,</span><span class="token string">"message"</span>:<span class="token string">""</span><span class="token punctuation">,</span><span class="token string">"path"</span>:<span class="token string">"/"</span><span class="token punctuation">}</span><span class="token namespace">[root@localhost idea]</span><span class="token comment"># </span>
<span class="token namespace">[root@localhost idea]</span><span class="token comment"># curl 127.0.0.1:49157/hello</span>
hello<span class="token punctuation">,</span>huangjialin<span class="token namespace">[root@localhost idea]</span><span class="token comment"># </span>

</code></pre> 
  <p>测试成功</p> 
  <p><a href="http://img.e-com-net.com/image/info8/a36dd19902ff455c99eeba970724941c.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/a36dd19902ff455c99eeba970724941c.jpg" alt="跟着狂神学Docker(精髓篇)_第69张图片" width="607" height="254" style="border:1px solid black;"></a></p> 
  <p>以后我们使用了<code>Docker</code>之后,给别人交付就是一个镜像即可!</p> 
  <h2>狂神UP</h2> 
  <p>https://space.bilibili.com/95256449/video?keyword=Docker</p> 
 </div> 
</div>
                            </div>
                        </div>
                    </div>
                    <!--PC和WAP自适应版-->
                    <div id="SOHUCS" sid="1751074725389418496"></div>
                    <script type="text/javascript" src="/views/front/js/chanyan.js"></script>
                    <!-- 文章页-底部 动态广告位 -->
                    <div class="youdao-fixed-ad" id="detail_ad_bottom"></div>
                </div>
                <div class="col-md-3">
                    <div class="row" id="ad">
                        <!-- 文章页-右侧1 动态广告位 -->
                        <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_1"> </div>
                        </div>
                        <!-- 文章页-右侧2 动态广告位 -->
                        <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_2"></div>
                        </div>
                        <!-- 文章页-右侧3 动态广告位 -->
                        <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_3"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(docker,linux)</h4>
        <div id="paradigm-article-related">
            <div class="recommend-post mb30">
                <ul class="widget-links">
                    <li><a href="/article/1835513699826233344.htm"
                           title="android系统selinux中添加新属性property" target="_blank">android系统selinux中添加新属性property</a>
                        <span class="text-muted">辉色投像</span>

                        <div>1.定位/android/system/sepolicy/private/property_contexts声明属性开头:persist.charge声明属性类型:u:object_r:system_prop:s0图12.定位到android/system/sepolicy/public/domain.te删除neverallow{domain-init}default_prop:property</div>
                    </li>
                    <li><a href="/article/1835509391361667072.htm"
                           title="Linux下QT开发的动态库界面弹出操作(SDL2)" target="_blank">Linux下QT开发的动态库界面弹出操作(SDL2)</a>
                        <span class="text-muted">13jjyao</span>
<a class="tag" taget="_blank" href="/search/QT%E7%B1%BB/1.htm">QT类</a><a class="tag" taget="_blank" href="/search/qt/1.htm">qt</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/sdl2/1.htm">sdl2</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                        <div>需求:操作系统为linux,开发框架为qt,做成需带界面的qt动态库,调用方为java等非qt程序难点:调用方为java等非qt程序,也就是说调用方肯定不带QApplication::exec(),缺少了这个,QTimer等事件和QT创建的窗口将不能弹出(包括opencv也是不能弹出);这与qt调用本身qt库是有本质的区别的思路:1.调用方缺QApplication::exec(),那么我们在接口</div>
                    </li>
                    <li><a href="/article/1835504596898902016.htm"
                           title="linux sdl windows.h,Windows下的SDL安装" target="_blank">linux sdl windows.h,Windows下的SDL安装</a>
                        <span class="text-muted">奔跑吧linux内核</span>
<a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/sdl/1.htm">sdl</a><a class="tag" taget="_blank" href="/search/windows.h/1.htm">windows.h</a>
                        <div>首先你要下载并安装SDL开发包。如果装在C盘下,路径为C:\SDL1.2.5如果在WINDOWS下。你可以按以下步骤:1.打开VC++,点击"Tools",Options2,点击directories选项3.选择"Includefiles"增加一个新的路径。"C:\SDL1.2.5\include"4,现在选择"Libaryfiles“增加"C:\SDL1.2.5\lib"现在你可以开始编写你的第</div>
                    </li>
                    <li><a href="/article/1835503712899002368.htm"
                           title="linux中sdl的使用教程,sdl使用入门" target="_blank">linux中sdl的使用教程,sdl使用入门</a>
                        <span class="text-muted">Melissa Corvinus</span>
<a class="tag" taget="_blank" href="/search/linux%E4%B8%ADsdl%E7%9A%84%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/1.htm">linux中sdl的使用教程</a>
                        <div>本文通过一个简单示例讲解SDL的基本使用流程。示例中展示一个窗口,窗口里面有个随机颜色快随机移动。当我们鼠标点击关闭按钮时间窗口关闭。基本步骤如下:1.初始化SDL并创建一个窗口。SDL_Init()初始化SDL_CreateWindow()创建窗口2.纹理渲染存储RGB和存储纹理的区别:比如一个从左到右由红色渐变到蓝色的矩形,用存储RGB的话就需要把矩形中每个点的具体颜色值存储下来;而纹理只是一</div>
                    </li>
                    <li><a href="/article/1835502578050363392.htm"
                           title="PHP环境搭建详细教程" target="_blank">PHP环境搭建详细教程</a>
                        <span class="text-muted">好看资源平台</span>
<a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/php/1.htm">php</a>
                        <div>PHP是一个流行的服务器端脚本语言,广泛用于Web开发。为了使PHP能够在本地或服务器上运行,我们需要搭建一个合适的PHP环境。本教程将结合最新资料,介绍在不同操作系统上搭建PHP开发环境的多种方法,包括Windows、macOS和Linux系统的安装步骤,以及本地和Docker环境的配置。1.PHP环境搭建概述PHP环境的搭建主要分为以下几类:集成开发环境:例如XAMPP、WAMP、MAMP,这</div>
                    </li>
                    <li><a href="/article/1835501948011376640.htm"
                           title="使用 FinalShell 进行远程连接(ssh 远程连接 Linux 服务器)" target="_blank">使用 FinalShell 进行远程连接(ssh 远程连接 Linux 服务器)</a>
                        <span class="text-muted">编程经验分享</span>
<a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/1.htm">开发工具</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a><a class="tag" taget="_blank" href="/search/ssh/1.htm">ssh</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                        <div>目录前言基本使用教程新建远程连接连接主机自定义命令路由追踪前言后端开发,必然需要和服务器打交道,部署应用,排查问题,查看运行日志等等。一般服务器都是集中部署在机房中,也有一些直接是云服务器,总而言之,程序员不可能直接和服务器直接操作,一般都是通过ssh连接来登录服务器。刚接触远程连接时,使用的是XSHELL来远程连接服务器,连接上就能够操作远程服务器了,但是仅用XSHELL并没有上传下载文件的功能</div>
                    </li>
                    <li><a href="/article/1835493373906087936.htm"
                           title="libyuv之linux编译" target="_blank">libyuv之linux编译</a>
                        <span class="text-muted">jaronho</span>
<a class="tag" taget="_blank" href="/search/Linux/1.htm">Linux</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a>
                        <div>文章目录一、下载源码二、编译源码三、注意事项1、银河麒麟系统(aarch64)(1)解决armv8-a+dotprod+i8mm指令集支持问题(2)解决armv9-a+sve2指令集支持问题一、下载源码到GitHub网站下载https://github.com/lemenkov/libyuv源码,或者用直接用git克隆到本地,如:gitclonehttps://github.com/lemenko</div>
                    </li>
                    <li><a href="/article/1835489588169240576.htm"
                           title="ARM驱动学习之5 LEDS驱动" target="_blank">ARM驱动学习之5 LEDS驱动</a>
                        <span class="text-muted">JT灬新一</span>
<a class="tag" taget="_blank" href="/search/%E5%B5%8C%E5%85%A5%E5%BC%8F/1.htm">嵌入式</a><a class="tag" taget="_blank" href="/search/C/1.htm">C</a><a class="tag" taget="_blank" href="/search/%E5%BA%95%E5%B1%82/1.htm">底层</a><a class="tag" taget="_blank" href="/search/arm%E5%BC%80%E5%8F%91/1.htm">arm开发</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0/1.htm">学习</a><a class="tag" taget="_blank" href="/search/%E5%8D%95%E7%89%87%E6%9C%BA/1.htm">单片机</a>
                        <div>ARM驱动学习之5LEDS驱动知识点:•linuxGPIO申请函数和赋值函数–gpio_request–gpio_set_value•三星平台配置GPIO函数–s3c_gpio_cfgpin•GPIO配置输出模式的宏变量–S3C_GPIO_OUTPUT注意点:DRIVER_NAME和DEVICE_NAME匹配。实现步骤:1.加入需要的头文件://Linux平台的gpio头文件#include//三</div>
                    </li>
                    <li><a href="/article/1835485681187647488.htm"
                           title="【华为OD技术面试真题精选 - 非技术题】 -HR面,综合面_华为od hr面" target="_blank">【华为OD技术面试真题精选 - 非技术题】 -HR面,综合面_华为od hr面</a>
                        <span class="text-muted">一个射手座的程序媛</span>
<a class="tag" taget="_blank" href="/search/%E7%A8%8B%E5%BA%8F%E5%91%98/1.htm">程序员</a><a class="tag" taget="_blank" href="/search/%E5%8D%8E%E4%B8%BAod/1.htm">华为od</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a><a class="tag" taget="_blank" href="/search/%E8%81%8C%E5%9C%BA%E5%92%8C%E5%8F%91%E5%B1%95/1.htm">职场和发展</a>
                        <div>最后的话最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!资料预览给大家整理的视频资料:给大家整理的电子书资料:如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。需要这份系统化的资料的朋友,可以点击这里获</div>
                    </li>
                    <li><a href="/article/1835485429059645440.htm"
                           title="docker" target="_blank">docker</a>
                        <span class="text-muted">igotyback</span>
<a class="tag" taget="_blank" href="/search/eureka/1.htm">eureka</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a>
                        <div>Docker容器的文件系统是隔离的,但是可以通过挂载卷(Volumes)或绑定挂载(BindMounts)将宿主机的文件系统目录映射到容器内部。要查看Docker容器的映射路径,可以使用以下方法:查看容器配置:使用dockerinspect命令可以查看容器的详细配置信息,包括挂载的卷。例如:bashdockerinspect在输出的JSON格式中,查找"Mounts"部分,这里会列出所有的挂载信息</div>
                    </li>
                    <li><a href="/article/1835482277870661632.htm"
                           title="简介Shell、zsh、bash" target="_blank">简介Shell、zsh、bash</a>
                        <span class="text-muted">zhaosuningsn</span>
<a class="tag" taget="_blank" href="/search/Shell/1.htm">Shell</a><a class="tag" taget="_blank" href="/search/zsh/1.htm">zsh</a><a class="tag" taget="_blank" href="/search/bash/1.htm">bash</a><a class="tag" taget="_blank" href="/search/shell/1.htm">shell</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/bash/1.htm">bash</a>
                        <div>Shell是Linux和Unix的外壳,类似衣服,负责外界与Linux和Unix内核的交互联系。例如接收终端用户及各种应用程序的命令,把接收的命令翻译成内核能理解的语言,传递给内核,并把内核处理接收的命令的结果返回给外界,即Shell是外界和内核沟通的桥梁或大门。Linux和Unix提供了多种Shell,其中有种bash,当然还有其他好多种。Mac电脑中不但有bash,还有一个zsh,预装的,据说</div>
                    </li>
                    <li><a href="/article/1835479000600899584.htm"
                           title="Linux MariaDB使用OpenSSL安装SSL证书" target="_blank">Linux MariaDB使用OpenSSL安装SSL证书</a>
                        <span class="text-muted">Meta39</span>
<a class="tag" taget="_blank" href="/search/MySQL/1.htm">MySQL</a><a class="tag" taget="_blank" href="/search/Oracle/1.htm">Oracle</a><a class="tag" taget="_blank" href="/search/MariaDB/1.htm">MariaDB</a><a class="tag" taget="_blank" href="/search/Linux/1.htm">Linux</a><a class="tag" taget="_blank" href="/search/Windows/1.htm">Windows</a><a class="tag" taget="_blank" href="/search/ssl/1.htm">ssl</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/mariadb/1.htm">mariadb</a>
                        <div>进入到证书存放目录,批量删除.pem证书警告:确保已经进入到证书存放目录find.-typef-iname\*.pem-delete查看是否安装OpenSSLopensslversion没有则安装yuminstallopensslopenssl-devel开启SSL编辑/etc/my.cnf文件(没有的话就创建,但是要注意,在/etc/my.cnf.d/server.cnf配置了datadir的,</div>
                    </li>
                    <li><a href="/article/1835469294436184064.htm"
                           title="【从浅识到熟知Linux】Linux发展史" target="_blank">【从浅识到熟知Linux】Linux发展史</a>
                        <span class="text-muted">Jammingpro</span>
<a class="tag" taget="_blank" href="/search/%E4%BB%8E%E6%B5%85%E5%AD%A6%E5%88%B0%E7%86%9F%E7%9F%A5Linux/1.htm">从浅学到熟知Linux</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a>
                        <div>归属专栏:从浅学到熟知Linux个人主页:Jammingpro每日努力一点点,技术变化看得见文章前言:本篇文章记录Linux发展的历史,因在介绍Linux过程中涉及的其他操作系统及人物,本文对相关内容也有所介绍。文章目录Unix发展史Linux发展史开源Linux官网企业应用情况发行版本在学习Linux前,我们可能都会问Linux从哪里来?它是如何发展的。但在介绍Linux之前,需要先介绍一下Un</div>
                    </li>
                    <li><a href="/article/1835467782687387648.htm"
                           title="linux 发展史" target="_blank">linux 发展史</a>
                        <span class="text-muted">种树的猴子</span>
<a class="tag" taget="_blank" href="/search/%E5%86%85%E6%A0%B8/1.htm">内核</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/1.htm">操作系统</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a>
                        <div>linux发展史说明此前对linux认识模糊一知半解,近期通过学习将自己对于linux的发展总结一下方便大家日后的学习。那Linux是目前一款非常火热的开源操作系统,可是linux是什么时候出现的,又是因为什么样的原因被开发出来的呢。以下将对linux的发展历程进行详细的讲解。目录一、Linux发展背景二、UINIX的诞生三、UNIX的重要分支-BSD的诞生四、Minix的诞生五、GNU与Free</div>
                    </li>
                    <li><a href="/article/1835466523163062272.htm"
                           title="Linux sh命令" target="_blank">Linux sh命令</a>
                        <span class="text-muted">fengyehongWorld</span>
<a class="tag" taget="_blank" href="/search/Linux/1.htm">Linux</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                        <div>目录一.基本语法二.选项2.1-c字符串中读取内容,并执行2.1.1基本用法2.1.2获取当前目录下失效的超链接2.2-x每个命令执行之前,将其打印出来2.3结合Here文档使用一.基本语法⏹Linux和Unix系统中用于执行shell脚本或运行命令的命令。sh[选项][脚本文件][参数...]⏹选项-c:从字符串中读取内容,并执行。-x:在每个命令执行之前,将其打印出来。-s:从标准流中读取内容</div>
                    </li>
                    <li><a href="/article/1835466270955368448.htm"
                           title="Linux vi常用命令" target="_blank">Linux vi常用命令</a>
                        <span class="text-muted">fengyehongWorld</span>
<a class="tag" taget="_blank" href="/search/Linux/1.htm">Linux</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                        <div>参考资料viコマンド(vimコマンド)リファレンス目录一.保存系命令二.删除系命令三.移动系命令四.复制粘贴系命令一.保存系命令⏹保存并退出:wq⏹强制保存并退出:wq!⏹退出(文件未编辑):q⏹强制退出(忽略已编辑内容):q!⏹另存为:w新文件名二.删除系命令⏹删除当前行dd⏹清空整个文档gg:移动到文档顶部dG:删除到最后一行ggdG三.移动系命令⏹移动到文档顶部gg⏹移动到文档底部#方式1G</div>
                    </li>
                    <li><a href="/article/1835452402178813952.htm"
                           title="Linux查看服务器日志" target="_blank">Linux查看服务器日志</a>
                        <span class="text-muted">TPBoreas</span>
<a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a>
                        <div>一、tail这个是我最常用的一种查看方式用法如下:tail-n10test.log查询日志尾部最后10行的日志;tail-n+10test.log查询10行之后的所有日志;tail-fn10test.log循环实时查看最后1000行记录(最常用的)一般还会配合着grep用,(实时抓包)例如:tail-fn1000test.log|grep'关键字'(动态抓包)tail-fn1000test.log</div>
                    </li>
                    <li><a href="/article/1835447859219099648.htm"
                           title="06选课支付模块之基于消息队列发送支付通知消息" target="_blank">06选课支付模块之基于消息队列发送支付通知消息</a>
                        <span class="text-muted">echo 云清</span>
<a class="tag" taget="_blank" href="/search/%E5%AD%A6%E6%88%90%E5%9C%A8%E7%BA%BF/1.htm">学成在线</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/rabbitmq/1.htm">rabbitmq</a><a class="tag" taget="_blank" href="/search/%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/1.htm">消息队列</a><a class="tag" taget="_blank" href="/search/%E6%94%AF%E4%BB%98%E9%80%9A%E7%9F%A5/1.htm">支付通知</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E6%88%90%E5%9C%A8%E7%BA%BF/1.htm">学成在线</a>
                        <div>消息队列发送支付通知消息需求分析订单服务作为通用服务,在订单支付成功后需要将支付结果异步通知给其他对接的微服务,微服务收到支付结果根据订单的类型去更新自己的业务数据技术方案使用消息队列进行异步通知需要保证消息的可靠性即生产端将消息成功通知到服务端:消息发送到交换机-->由交换机发送到队列-->消费者监听队列,收到消息进行处理,参考文章02-使用Docker安装RabbitMQ-CSDN博客生产者确</div>
                    </li>
                    <li><a href="/article/1835443696431099904.htm"
                           title="笋丁网页自动回复机器人V3.0.0免授权版源码" target="_blank">笋丁网页自动回复机器人V3.0.0免授权版源码</a>
                        <span class="text-muted">希希分享</span>
<a class="tag" taget="_blank" href="/search/%E8%BD%AF%E5%B8%8C%E7%BD%9158soho_cn/1.htm">软希网58soho_cn</a><a class="tag" taget="_blank" href="/search/%E6%BA%90%E7%A0%81%E8%B5%84%E6%BA%90/1.htm">源码资源</a><a class="tag" taget="_blank" href="/search/%E7%AC%8B%E4%B8%81%E7%BD%91%E9%A1%B5%E8%87%AA%E5%8A%A8%E5%9B%9E%E5%A4%8D%E6%9C%BA%E5%99%A8%E4%BA%BA/1.htm">笋丁网页自动回复机器人</a>
                        <div>笋丁网页机器人一款可设置自动回复,默认消息,调用自定义api接口的网页机器人。此程序后端语言使用Golang,内存占用最高不超过30MB,1H1G服务器流畅运行。仅支持Linux服务器部署,不支持虚拟主机,请悉知!使用自定义api功能需要有一定的建站基础。源码下载:https://download.csdn.net/download/m0_66047725/89754250更多资源下载:关注我。安</div>
                    </li>
                    <li><a href="/article/1835417097660887040.htm"
                           title="Linux CTF逆向入门" target="_blank">Linux CTF逆向入门</a>
                        <span class="text-muted">蚁景网络安全</span>
<a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/CTF/1.htm">CTF</a>
                        <div>1.ELF格式我们先来看看ELF文件头,如果想详细了解,可以查看ELF的manpage文档。关于ELF更详细的说明:e_shoff:节头表的文件偏移量(字节)。如果文件没有节头表,则此成员值为零。sh_offset:表示了该section(节)离开文件头部位置的距离+-------------------+|ELFheader|---++--------->+-------------------</div>
                    </li>
                    <li><a href="/article/1835415332345442304.htm"
                           title="NPM私库搭建-verdaccio(Linux)" target="_blank">NPM私库搭建-verdaccio(Linux)</a>
                        <span class="text-muted">Beam007</span>
<a class="tag" taget="_blank" href="/search/npm/1.htm">npm</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a>
                        <div>1、安装nodelinux服务器安装nodea)、官网下载所需的node版本https://nodejs.org/dist/v14.21.0/b)、解压安装包若下载的是xxx.tar.xz文件,解压命令为tar-xvfxxx.tar.xzc)、修改环境变量修改:/etc/profile文件#SETPATHFORNODEJSexportNODE_HOME=NODEJS解压安装的路径exportPAT</div>
                    </li>
                    <li><a href="/article/1835408447806468096.htm"
                           title="Ubuntu18.04 Docker部署Kinship(Django)项目过程" target="_blank">Ubuntu18.04 Docker部署Kinship(Django)项目过程</a>
                        <span class="text-muted">Dante617</span>

                        <div>1Docker的安装https://blog.csdn.net/weixin_41735055/article/details/1003551792下载镜像dockerpullprogramize/python3.6.8-dlib下载的镜像里包含python3.6.8和dlib19.17.03启动镜像dockerrun-it--namekinship-p7777:80-p3307:3306-p55</div>
                    </li>
                    <li><a href="/article/1835400463676174336.htm"
                           title="C++常见知识掌握" target="_blank">C++常见知识掌握</a>
                        <span class="text-muted">nfgo</span>
<a class="tag" taget="_blank" href="/search/c%2B%2B/1.htm">c++</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>1.Linux软件开发、调试与维护内核与系统结构Linux内核是操作系统的核心,负责管理硬件资源,提供系统服务,它是系统软件与硬件之间的桥梁。主要组成部分包括:进程管理:内核通过调度器分配CPU时间给各个进程,实现进程的创建、调度、终止等操作。使用进程描述符(task_struct)来存储进程信息,包括状态(就绪、运行、阻塞等)、优先级、内存映射等。内存管理:包括物理内存和虚拟内存管理。通过页表映</div>
                    </li>
                    <li><a href="/article/1835399957885054976.htm"
                           title="docker from指令的含义_多个FROM-含义" target="_blank">docker from指令的含义_多个FROM-含义</a>
                        <span class="text-muted">weixin_39722188</span>
<a class="tag" taget="_blank" href="/search/docker/1.htm">docker</a><a class="tag" taget="_blank" href="/search/from%E6%8C%87%E4%BB%A4%E7%9A%84%E5%90%AB%E4%B9%89/1.htm">from指令的含义</a>
                        <div>小编典典什么是基本图片?一组文件,加上EXPOSE端口ENTRYPOINT和CMD。您可以添加文件并基于该基础图像构建新图像,Dockerfile并以FROM指令开头:后面提到的图像FROM是新图像的“基础图像”。这是否意味着如果我neo4j/neo4j在FROM指令中声明,则在运行映像时,neo数据库将自动运行并且可在端口7474的容器中使用?仅当您不覆盖CMD和时ENTRYPOINT。但是图像</div>
                    </li>
                    <li><a href="/article/1835399831116410880.htm"
                           title="Dockerfile FROM 两个" target="_blank">Dockerfile FROM 两个</a>
                        <span class="text-muted">redDelta</span>

                        <div>Docker相关视频讲解:什么是容器Docker介绍实现"DockerfileFROM两个"的步骤步骤表格步骤操作1创建一个Dockerfile文件2写入FROM指令3构建第一个镜像4创建第二个Dockerfile文件5写入FROM指令6构建第二个镜像7合并两个镜像操作步骤说明步骤1:创建一个Dockerfile文件使用任意文本编辑器创建一个名为Dockerfile的文件。登录后复制#Docker</div>
                    </li>
                    <li><a href="/article/1835399577818198016.htm"
                           title="linux脚本sed替换变量,sed 命令中替换值为shell变量" target="_blank">linux脚本sed替换变量,sed 命令中替换值为shell变量</a>
                        <span class="text-muted">诺坎普之约</span>
<a class="tag" taget="_blank" href="/search/linux%E8%84%9A%E6%9C%ACsed%E6%9B%BF%E6%8D%A2%E5%8F%98%E9%87%8F/1.htm">linux脚本sed替换变量</a>
                        <div>文章目录sed命令中替换值为shell变量替换基本语法sed中替换使用shell变量总结参考文档sed命令中替换值为shell变量替换基本语法大家都是sed有很多用法,最多就应该是替换一些值了。让我们先回忆sed的替换语法。在sed进行替换的时候sed-i's/old/new/g'1.txtecho"hellooldfrank"|sed's/old/new/g'结果如下:hellonewfrank</div>
                    </li>
                    <li><a href="/article/1835398694636187648.htm"
                           title="RK3229_Android9.0_Box 4G模块EC200A调试" target="_blank">RK3229_Android9.0_Box 4G模块EC200A调试</a>
                        <span class="text-muted">suifen_</span>
<a class="tag" taget="_blank" href="/search/%E7%BD%91%E7%BB%9C/1.htm">网络</a>
                        <div>0、kernel修改这部分完全可以参考Linux的移植:RK3588EC200A-CN【4G模块】调试_rkec200a-cn-CSDN博客1、修改device/rockchip/rk322xdiff--gita/device.mkb/device.mkindexec6bfaa..e7c32d1100755---a/device.mk+++b/device.mk@@-105,6+105,8@@en</div>
                    </li>
                    <li><a href="/article/1835395039572881408.htm"
                           title="Dockerfile命令详解之 FROM" target="_blank">Dockerfile命令详解之 FROM</a>
                        <span class="text-muted">清风怎不知意</span>
<a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8%E5%8C%96/1.htm">容器化</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/javascript/1.htm">javascript</a>
                        <div>许多同学不知道Dockerfile应该如何写,不清楚Dockerfile中的指令分别有什么意义,能达到什么样的目的,接下来我将在容器化专栏中详细的为大家解释每一个指令的含义以及用法。专栏订阅传送门https://blog.csdn.net/qq_38220908/category_11989778.html指令不区分大小写。但是,按照惯例,它们应该是大写的,以便更容易地将它们与参数区分开来。(引用</div>
                    </li>
                    <li><a href="/article/1835394786899619840.htm"
                           title="Dockerfile(1) - FROM 指令详解" target="_blank">Dockerfile(1) - FROM 指令详解</a>
                        <span class="text-muted">小菠萝测试笔记</span>
<a class="tag" taget="_blank" href="/search/docker/1.htm">docker</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/cmd/1.htm">cmd</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a>
                        <div>FROM指明当前的镜像基于哪个镜像构建dockerfile必须以FROM开头,除了ARG命令可以在FROM前面FROM[--platform=][AS]FROM[--platform=][:][AS]FROM[--platform=][@][AS]小栗子FROMalpine:latest一个dockerfile可以有多个FROM可以有多个FROM来创建多个镜像,或区分构建阶段,将一个构建阶段作为另</div>
                    </li>
                    <li><a href="/article/1835390878806536192.htm"
                           title="linux 安装Sublime Text 3" target="_blank">linux 安装Sublime Text 3</a>
                        <span class="text-muted">hhyiyuanyu</span>
<a class="tag" taget="_blank" href="/search/Python%E5%AD%A6%E4%B9%A0/1.htm">Python学习</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/sublime/1.htm">sublime</a><a class="tag" taget="_blank" href="/search/text/1.htm">text</a>
                        <div>方法/步骤打开官网http://www.sublimetext.com/3,选择64位进行下载执行命令wgethttps://download.sublimetext.com/sublime_text_3_build_3126_x64.tar.bz2进行下载3、下载完成进行解压,执行tar-xvvfsublime_text_3_build_3126_x64.tar.bz解压4、解压完成以后,移动到</div>
                    </li>
                                <li><a href="/article/80.htm"
                                       title="java杨辉三角" target="_blank">java杨辉三角</a>
                                    <span class="text-muted">3213213333332132</span>
<a class="tag" taget="_blank" href="/search/java%E5%9F%BA%E7%A1%80/1.htm">java基础</a>
                                    <div>
package com.algorithm;

/**
 * @Description 杨辉三角
 * @author FuJianyong
 * 2015-1-22上午10:10:59
 */
public class YangHui {
	public static void main(String[] args) {
		//初始化二维数组长度
		int[][] y</div>
                                </li>
                                <li><a href="/article/207.htm"
                                       title="《大话重构》之大布局的辛酸历史" target="_blank">《大话重构》之大布局的辛酸历史</a>
                                    <span class="text-muted">白糖_</span>
<a class="tag" taget="_blank" href="/search/%E9%87%8D%E6%9E%84/1.htm">重构</a>
                                    <div>《大话重构》中提到“大布局你伤不起”,如果企图重构一个陈旧的大型系统是有非常大的风险,重构不是想象中那么简单。我目前所在公司正好对产品做了一次“大布局重构”,下面我就分享这个“大布局”项目经验给大家。 
  
 
 背景 
 
        公司专注于企业级管理产品软件,企业有大中小之分,在2000年初公司用JSP/Servlet开发了一套针对中</div>
                                </li>
                                <li><a href="/article/334.htm"
                                       title="电驴链接在线视频播放源码" target="_blank">电驴链接在线视频播放源码</a>
                                    <span class="text-muted">dubinwei</span>
<a class="tag" taget="_blank" href="/search/%E6%BA%90%E7%A0%81/1.htm">源码</a><a class="tag" taget="_blank" href="/search/%E7%94%B5%E9%A9%B4/1.htm">电驴</a><a class="tag" taget="_blank" href="/search/%E6%92%AD%E6%94%BE%E5%99%A8/1.htm">播放器</a><a class="tag" taget="_blank" href="/search/%E8%A7%86%E9%A2%91/1.htm">视频</a><a class="tag" taget="_blank" href="/search/ed2k/1.htm">ed2k</a>
                                    <div>本项目是个搜索电驴(ed2k)链接的应用,借助于磁力视频播放器(官网: 
http://loveandroid.duapp.com/ 开放平台),可以实现在线播放视频,也可以用迅雷或者其他下载工具下载。 
项目源码: 
http://git.oschina.net/svo/Emule,动态更新。也可从附件中下载。 
项目源码依赖于两个库项目,库项目一链接: 
http://git.oschina.</div>
                                </li>
                                <li><a href="/article/461.htm"
                                       title="Javascript中函数的toString()方法" target="_blank">Javascript中函数的toString()方法</a>
                                    <span class="text-muted">周凡杨</span>
<a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/js/1.htm">js</a><a class="tag" taget="_blank" href="/search/toString/1.htm">toString</a><a class="tag" taget="_blank" href="/search/function/1.htm">function</a><a class="tag" taget="_blank" href="/search/object/1.htm">object</a>
                                    <div>简述 
    The toString() method returns a string representing the source code of the function. 
    简译之,Javascript的toString()方法返回一个代表函数源代码的字符串。 
句法 
    function.</div>
                                </li>
                                <li><a href="/article/588.htm"
                                       title="struts处理自定义异常" target="_blank">struts处理自定义异常</a>
                                    <span class="text-muted">g21121</span>
<a class="tag" taget="_blank" href="/search/struts/1.htm">struts</a>
                                    <div>很多时候我们会用到自定义异常来表示特定的错误情况,自定义异常比较简单,只要分清是运行时异常还是非运行时异常即可,运行时异常不需要捕获,继承自RuntimeException,是由容器自己抛出,例如空指针异常。 
非运行时异常继承自Exception,在抛出后需要捕获,例如文件未找到异常。 
此处我们用的是非运行时异常,首先定义一个异常LoginException: 
/**
 * 类描述:登录相</div>
                                </li>
                                <li><a href="/article/715.htm"
                                       title="Linux中find常见用法示例" target="_blank">Linux中find常见用法示例</a>
                                    <span class="text-muted">510888780</span>
<a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                                    <div>Linux中find常见用法示例 
 
·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; 
 
 
 
 
find命令的参数;</div>
                                </li>
                                <li><a href="/article/842.htm"
                                       title="SpringMVC的各种参数绑定方式" target="_blank">SpringMVC的各种参数绑定方式</a>
                                    <span class="text-muted">Harry642</span>
<a class="tag" taget="_blank" href="/search/springMVC/1.htm">springMVC</a><a class="tag" taget="_blank" href="/search/%E7%BB%91%E5%AE%9A/1.htm">绑定</a><a class="tag" taget="_blank" href="/search/%E8%A1%A8%E5%8D%95/1.htm">表单</a>
                                    <div>1. 基本数据类型(以int为例,其他类似): 
Controller代码: 
 

    @RequestMapping("saysth.do")
    public void test(int count) {
    }
 
表单代码: 
 

<form action="saysth.do" method="post&q</div>
                                </li>
                                <li><a href="/article/969.htm"
                                       title="Java 获取Oracle ROWID" target="_blank">Java 获取Oracle ROWID</a>
                                    <span class="text-muted">aijuans</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a>
                                    <div>  
A ROWID is an identification tag unique for each row of an Oracle Database table. The ROWID can be thought of as a virtual column, containing the ID for each row. 
The oracle.sql.ROWID class i</div>
                                </li>
                                <li><a href="/article/1096.htm"
                                       title="java获取方法的参数名" target="_blank">java获取方法的参数名</a>
                                    <span class="text-muted">antlove</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/jdk/1.htm">jdk</a><a class="tag" taget="_blank" href="/search/parameter/1.htm">parameter</a><a class="tag" taget="_blank" href="/search/method/1.htm">method</a><a class="tag" taget="_blank" href="/search/reflect/1.htm">reflect</a>
                                    <div>reflect.ClassInformationUtil.java 
package reflect;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.Modifier;
import javassist.bytecode.CodeAtt</div>
                                </li>
                                <li><a href="/article/1223.htm"
                                       title="JAVA正则表达式匹配 查找 替换 提取操作" target="_blank">JAVA正则表达式匹配 查找 替换 提取操作</a>
                                    <span class="text-muted">百合不是茶</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/1.htm">正则表达式</a><a class="tag" taget="_blank" href="/search/%E6%9B%BF%E6%8D%A2/1.htm">替换</a><a class="tag" taget="_blank" href="/search/%E6%8F%90%E5%8F%96/1.htm">提取</a><a class="tag" taget="_blank" href="/search/%E6%9F%A5%E6%89%BE/1.htm">查找</a>
                                    <div>正则表达式的查找;主要是用到String类中的split(); 
      String str; 
     str.split();方法中传入按照什么规则截取,返回一个String数组 
  
常见的截取规则: 
str.split("\\.")按照.来截取

str.</div>
                                </li>
                                <li><a href="/article/1350.htm"
                                       title="Java中equals()与hashCode()方法详解" target="_blank">Java中equals()与hashCode()方法详解</a>
                                    <span class="text-muted">bijian1013</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/set/1.htm">set</a><a class="tag" taget="_blank" href="/search/equals%28%29/1.htm">equals()</a><a class="tag" taget="_blank" href="/search/hashCode%28%29/1.htm">hashCode()</a>
                                    <div>一.equals()方法详解 
    equals()方法在object类中定义如下:  
public boolean equals(Object obj) {
    return (this == obj);
}
 
   很明显是对两个对象的地址值进行的比较(即比较引用是否相同)。但是我们知道,String 、Math、I</div>
                                </li>
                                <li><a href="/article/1477.htm"
                                       title="精通Oracle10编程SQL(4)使用SQL语句" target="_blank">精通Oracle10编程SQL(4)使用SQL语句</a>
                                    <span class="text-muted">bijian1013</span>
<a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a><a class="tag" taget="_blank" href="/search/plsql/1.htm">plsql</a>
                                    <div>--工资级别表
create table SALGRADE
(
  GRADE    NUMBER(10),
  LOSAL    NUMBER(10,2),
  HISAL    NUMBER(10,2)
)

insert into SALGRADE values(1,0,100);
insert into SALGRADE values(2,100,200);
inser</div>
                                </li>
                                <li><a href="/article/1604.htm"
                                       title="【Nginx二】Nginx作为静态文件HTTP服务器" target="_blank">【Nginx二】Nginx作为静态文件HTTP服务器</a>
                                    <span class="text-muted">bit1129</span>
<a class="tag" taget="_blank" href="/search/HTTP%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">HTTP服务器</a>
                                    <div> Nginx作为静态文件HTTP服务器 
 
  在本地系统中创建/data/www目录,存放html文件(包括index.html) 
 创建/data/images目录,存放imags图片 
 在主配置文件中添加http指令 
 
  
http {
    server {
        listen       80;
        server_name  </div>
                                </li>
                                <li><a href="/article/1731.htm"
                                       title="kafka获得最新partition offset" target="_blank">kafka获得最新partition offset</a>
                                    <span class="text-muted">blackproof</span>
<a class="tag" taget="_blank" href="/search/kafka/1.htm">kafka</a><a class="tag" taget="_blank" href="/search/partition/1.htm">partition</a><a class="tag" taget="_blank" href="/search/offset/1.htm">offset</a><a class="tag" taget="_blank" href="/search/%E6%9C%80%E6%96%B0/1.htm">最新</a>
                                    <div>kafka获得partition下标,需要用到kafka的simpleconsumer 
  
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.</div>
                                </li>
                                <li><a href="/article/1858.htm"
                                       title="centos 7安装docker两种方式" target="_blank">centos 7安装docker两种方式</a>
                                    <span class="text-muted">ronin47</span>

                                    <div>      第一种是采用yum 方式 
             yum install -y docker 
          </div>
                                </li>
                                <li><a href="/article/1985.htm"
                                       title="java-60-在O(1)时间删除链表结点" target="_blank">java-60-在O(1)时间删除链表结点</a>
                                    <span class="text-muted">bylijinnan</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a>
                                    <div>

public class DeleteNode_O1_Time {

	/**
	 * Q 60 在O(1)时间删除链表结点
	 * 给定链表的头指针和一个结点指针(!!),在O(1)时间删除该结点
	 * 
	 * Assume the list is:
	 * head->...->nodeToDelete->mNode->nNode->..</div>
                                </li>
                                <li><a href="/article/2112.htm"
                                       title="nginx利用proxy_cache来缓存文件" target="_blank">nginx利用proxy_cache来缓存文件</a>
                                    <span class="text-muted">cfyme</span>
<a class="tag" taget="_blank" href="/search/cache/1.htm">cache</a>
                                    <div>user  zhangy users;
worker_processes 10;
error_log  /var/vlogs/nginx_error.log  crit;
pid        /var/vlogs/nginx.pid;
#Specifies the value for ma</div>
                                </li>
                                <li><a href="/article/2239.htm"
                                       title="[JWFD开源工作流]JWFD嵌入式语法分析器负号的使用问题" target="_blank">[JWFD开源工作流]JWFD嵌入式语法分析器负号的使用问题</a>
                                    <span class="text-muted">comsci</span>
<a class="tag" taget="_blank" href="/search/%E5%B5%8C%E5%85%A5%E5%BC%8F/1.htm">嵌入式</a>
                                    <div> 
    假如我们需要用JWFD的语法分析模块定义一个带负号的方程式,直接在方程式之前添加负号是不正确的,而必须这样做: 
 
    string str01 = "a=3.14;b=2.71;c=0;c-((a*a)+(b*b))" 
 
    定义一个0整数c,然后用这个整数c去</div>
                                </li>
                                <li><a href="/article/2366.htm"
                                       title="如何集成支付宝官方文档" target="_blank">如何集成支付宝官方文档</a>
                                    <span class="text-muted">dai_lm</span>
<a class="tag" taget="_blank" href="/search/android/1.htm">android</a>
                                    <div>官方文档下载地址 
 
https://b.alipay.com/order/productDetail.htm?productId=2012120700377310&tabId=4#ps-tabinfo-hash 
 
集成的必要条件 
1. 需要有自己的Server接收支付宝的消息 
2. 需要先制作app,然后提交支付宝审核,通过后才能集成 
 
调试的时候估计会真的扣款,请注意 
</div>
                                </li>
                                <li><a href="/article/2493.htm"
                                       title="应该在什么时候使用Hadoop" target="_blank">应该在什么时候使用Hadoop</a>
                                    <span class="text-muted">datamachine</span>
<a class="tag" taget="_blank" href="/search/hadoop/1.htm">hadoop</a>
                                    <div>原帖地址:http://blog.chinaunix.net/uid-301743-id-3925358.html 
 
存档,某些观点与我不谋而合,过度技术化不可取,且hadoop并非万能。 
 
--------------------------------------------万能的分割线-------------------------------- 
有人问我,“你在大数据和Hado</div>
                                </li>
                                <li><a href="/article/2620.htm"
                                       title="在GridView中对于有外键的字段使用关联模型进行搜索和排序" target="_blank">在GridView中对于有外键的字段使用关联模型进行搜索和排序</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/yii/1.htm">yii</a>
                                    <div>在GridView中使用关联模型进行搜索和排序 
首先我们有两个模型它们直接有关联:   
class Author extends CActiveRecord {
...
}
 
class Post extends CActiveRecord {
...
    function relations() {
        return array(
            '</div>
                                </li>
                                <li><a href="/article/2747.htm"
                                       title="使用NSString 的格式化大全" target="_blank">使用NSString 的格式化大全</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/Objective-C/1.htm">Objective-C</a>
                                    <div>格式定义The format specifiers supported by the NSString formatting methods and CFString formatting functions follow the IEEE printf specification; the specifiers are summarized in Table 1. Note that you c</div>
                                </li>
                                <li><a href="/article/2874.htm"
                                       title="使用activeX插件对象object滚动有重影" target="_blank">使用activeX插件对象object滚动有重影</a>
                                    <span class="text-muted">蕃薯耀</span>
<a class="tag" taget="_blank" href="/search/activeX%E6%8F%92%E4%BB%B6/1.htm">activeX插件</a><a class="tag" taget="_blank" href="/search/%E6%BB%9A%E5%8A%A8%E6%9C%89%E9%87%8D%E5%BD%B1/1.htm">滚动有重影</a>
                                    <div>    
使用activeX插件对象object滚动有重影       <object style="width:0;" id="abc" classid="CLSID:D3E3970F-2927-9680-BBB4-5D0889909DF6" codebase="activex/OAX339.CAB#</div>
                                </li>
                                <li><a href="/article/3001.htm"
                                       title="SpringMVC4零配置" target="_blank">SpringMVC4零配置</a>
                                    <span class="text-muted">hanqunfeng</span>
<a class="tag" taget="_blank" href="/search/springmvc4/1.htm">springmvc4</a>
                                    <div>基于Servlet3.0规范和SpringMVC4注解式配置方式,实现零xml配置,弄了个小demo,供交流讨论。 
  
  
项目说明如下: 
1.db.sql是项目中用到的表,数据库使用的是oracle11g 
2.该项目使用mvn进行管理,私服为自搭建nexus,项目只用到一个第三方 jar,就是oracle的驱动; 
3.默认项目为零配置启动,如果需要更改启动方式,请</div>
                                </li>
                                <li><a href="/article/3128.htm"
                                       title="《开源框架那点事儿16》:缓存相关代码的演变" target="_blank">《开源框架那点事儿16》:缓存相关代码的演变</a>
                                    <span class="text-muted">j2eetop</span>
<a class="tag" taget="_blank" href="/search/%E5%BC%80%E6%BA%90%E6%A1%86%E6%9E%B6/1.htm">开源框架</a>
                                    <div>问题引入 
上次我参与某个大型项目的优化工作,由于系统要求有比较高的TPS,因此就免不了要使用缓冲。 
该项目中用的缓冲比较多,有MemCache,有Redis,有的还需要提供二级缓冲,也就是说应用服务器这层也可以设置一些缓冲。 
当然去看相关实现代代码的时候,大致是下面的样子。    
[java] 
view plain 
copy 
print 
?   
 
 public vo</div>
                                </li>
                                <li><a href="/article/3255.htm"
                                       title="AngularJS浅析" target="_blank">AngularJS浅析</a>
                                    <span class="text-muted">kvhur</span>
<a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a>
                                    <div>概念 
 
 AngularJS is a structural framework for dynamic web apps. 
 了解更多详情请见原文链接:http://www.gbtags.com/gb/share/5726.htm 
 Directive 
扩展html,给html添加声明语句,以便实现自己的需求。对于页面中html元素以ng为前缀的属性名称,ng是angular的命名空间</div>
                                </li>
                                <li><a href="/article/3382.htm"
                                       title="架构师之jdk的bug排查(一)---------------split的点号陷阱" target="_blank">架构师之jdk的bug排查(一)---------------split的点号陷阱</a>
                                    <span class="text-muted">nannan408</span>
<a class="tag" taget="_blank" href="/search/split/1.htm">split</a>
                                    <div>1.前言. 
   jdk1.6的lang包的split方法是有bug的,它不能有效识别A.b.c这种类型,导致截取长度始终是0.而对于其他字符,则无此问题.不知道官方有没有修复这个bug. 
2.代码 
 

String[] paths = "object.object2.prop11".split("'");
System.ou</div>
                                </li>
                                <li><a href="/article/3509.htm"
                                       title="如何对10亿数据量级的mongoDB作高效的全表扫描" target="_blank">如何对10亿数据量级的mongoDB作高效的全表扫描</a>
                                    <span class="text-muted">quentinXXZ</span>
<a class="tag" taget="_blank" href="/search/mongodb/1.htm">mongodb</a>
                                    <div>  本文链接: 
http://quentinXXZ.iteye.com/blog/2149440  
一、正常情况下,不应该有这种需求 
首先,大家应该有个概念,标题中的这个问题,在大多情况下是一个伪命题,不应该被提出来。要知道,对于一般较大数据量的数据库,全表查询,这种操作一般情况下是不应该出现的,在做正常查询的时候,如果是范围查询,你至少应该要加上limit。 
说一下,</div>
                                </li>
                                <li><a href="/article/3636.htm"
                                       title="C语言算法之水仙花数" target="_blank">C语言算法之水仙花数</a>
                                    <span class="text-muted">qiufeihu</span>
<a class="tag" taget="_blank" href="/search/c/1.htm">c</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a>
                                    <div>/**
* 水仙花数
*/
#include <stdio.h>
#define N 10
int main()
{
    int x,y,z;
    for(x=1;x<=N;x++)
    	for(y=0;y<=N;y++)
    		for(z=0;z<=N;z++)
    			if(x*100+y*10+z == x*x*x</div>
                                </li>
                                <li><a href="/article/3763.htm"
                                       title="JSP指令" target="_blank">JSP指令</a>
                                    <span class="text-muted">wyzuomumu</span>
<a class="tag" taget="_blank" href="/search/jsp/1.htm">jsp</a>
                                    <div> 
 jsp指令的一般语法格式: <%@ 指令名 属性 =”值 ” %> 
  常用的三种指令: page,include,taglib 
 page指令语法形式: <%@ page 属性 1=”值 1” 属性 2=”值 2”%> 
 include指令语法形式: <%@include file=”relative url”%> (jsp可以通过 include</div>
                                </li>
                </ul>
            </div>
        </div>
    </div>

<div>
    <div class="container">
        <div class="indexes">
            <strong>按字母分类:</strong>
            <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a
                href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a
                href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a
                href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a
                href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a
                href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a
                href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a
                href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a
                href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a>
        </div>
    </div>
</div>
<footer id="footer" class="mb30 mt30">
    <div class="container">
        <div class="footBglm">
            <a target="_blank" href="/">首页</a> -
            <a target="_blank" href="/custom/about.htm">关于我们</a> -
            <a target="_blank" href="/search/Java/1.htm">站内搜索</a> -
            <a target="_blank" href="/sitemap.txt">Sitemap</a> -
            <a target="_blank" href="/custom/delete.htm">侵权投诉</a>
        </div>
        <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved.
<!--            <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>-->
        </div>
    </div>
</footer>
<!-- 代码高亮 -->
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script>
<link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/>
<script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script>





</body>

</html>