今天遇到一个问题,我需要在docker镜像上部署一下跑ffmpeg环境的容器,但是呢?又不能让容器的ip地址和宿主机的IP地址一个网段,因为需要连接数据库,而连接数据库又需要设置白名单,这个时候就需要设置一下docker的默认IP了,docker安装参考:https://www.wulaoer.org/?p=260
已经安装好了docker,可以在daemon.json文件中,进行配置。
[root@www.wulaoer.org ~]# cat /etc/docker/daemon.json { "registry-mirrors": [ #docker镜像源 "https://dockerhub.azk8s.cn", "https://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com" ], "max-concurrent-downloads": 10, "log-driver": "json-file", "log-level": "warn", "log-opts": { "max-size": "10m", "max-file": "3" }, "data-root": "/var/lib/docker", #docker日志路径 "bip":"10.16.100.1/24" #默认ip段 }
注意,如果添加后要看看bip上面一行是否有一个逗号,如果没有加上。也可以使用mtu=BYTES,覆盖默认的Docker MTU配置。
添加之后重启一下docker服务。然后ifconfig一下,看看docker默认的ip端口已经改成我们设置的ip段了。
[root@www.wulaoer.org ~]# ifconfig docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.16.100.1 netmask 255.255.255.0 broadcast 10.16.100.255 inet6 fe80::42:6ff:fe25:d2dc prefixlen 64 scopeid 0x20<link> ether 02:42:06:25:d2:dc txqueuelen 0 (Ethernet) RX packets 35465 bytes 1452750 (1.3 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 67574 bytes 100206284 (95.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ..........................................
然后我们看一下容器的ip是否改变成我们设置的ip段。
[root@www.wulaoer.org ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3f436c53f6a7 centos:7.2.1511 "/bin/bash" About an hour ago Up 2 seconds ffmpeg 4d39f0c15898 nacos/nacos-server "bin/docker-startup.Β 2 days ago Up 2 minutes 0.0.0.0:8848->8848/tcp nacos [root@www.wulaoer.org ~]# docker inspect 3f436c53f6a7 [ ......................................................... "NetworkSettings": { "Bridge": "", "SandboxID": "2e12856d2f71f39cfb8ca10e80cd19f37146b07f4a6575d4af8547fe4de676f0", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/2e12856d2f71", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "16be1e086ba862f64f04a775f064514980b0ab6ee38d7f4f25979581ccd78a9a", "Gateway": "10.16.100.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "10.16.100.3", #容器的ip地址 "IPPrefixLen": 24, "IPv6Gateway": "", "MacAddress": "02:42:0a:10:64:03", "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "26efa8b50393ba7363fa90687bda7ede61b8fa607f824902bf6eba22662d1b81", "EndpointID": "16be1e086ba862f64f04a775f064514980b0ab6ee38d7f4f25979581ccd78a9a", "Gateway": "10.16.100.1", "IPAddress": "10.16.100.3", "IPPrefixLen": 24, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:0a:10:64:03", "DriverOpts": null } } } } ]
docker默认ip段设置成功。暂时没有了,看点其他的吧。
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏