博客
关于我
docker自定义网络模式,实现容器固定ip地址
阅读量:614 次
发布时间:2019-03-12

本文共 958 字,大约阅读时间需要 3 分钟。

当我们在使用 Docker 容器时,容器启动后分配的虚拟IP经常更改,这给运维团队带来了不少麻烦。

Docker 网络模式

Docker 默认使用 bridge 桥接网络模式。这种模式下,容器的网络接口会向容器内部服务暴露不同的 IP 地址。

工作原理

运行 docker network ls 查看现有的网络:

[root@localhost]# docker network lsNAME              DRIVER   SCOPE   VERSION   CODE   CREATE TIME   UPDATED TIME   STATE   DESCRIPTIONbridge          桥接    或者    或者    v0.24.0    docker    整个主机    2020-02-08T15:23:33    2020-02-08T15:23:33     健康    桥接网络

创建自定义网络

可以创建一个固定的网络:

docker network create --subnet=172.20.0.0/16 extnetwork

给容器指定 IP

创建容器时指定固定的 IP:

docker run -p 8066:8066 -it -v /home/docker/mycat/conf/:/home/mycat/conf/ -v /home/docker/mycat/logs/:/home/mycat/logs/ --net extnetwork --ip 172.20.0.2 镜像id

注意:IP 分配应从 172.20.0.2 开始,因为 172.20.0.1 是网关。

查看容器信息

使用 docker inspect 查看容器 IP:

[root@localhost]# docker inspect 你的容器id"NetworkSettings": {    "Interface": "something",    "IP": "172.20.0.2",    ...}

兼容性问题

确保 your application 可以处理固定 IP。

网络删除

如果不再使用这个网络,可以删除它:

docker network rm extnetwork

转载地址:http://cxjxz.baihongyu.com/

你可能感兴趣的文章
npm install 报错 EEXIST File exists 的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 Failed to connect to github.com port 443 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install 权限问题
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>
npm node pm2相关问题
查看>>
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
查看>>
npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
查看>>
npm scripts 使用指南
查看>>
npm should be run outside of the node repl, in your normal shell
查看>>
npm start运行了什么
查看>>
npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
查看>>
npm 下载依赖慢的解决方案(亲测有效)
查看>>