如何在Docker Toolbox上更改docker0桥接接口的IP地址 [英] How to change ip address of docker0 bridge interface on Docker Toolbox
问题描述
我正在Windows 7上使用Docker Toolbox,我试图更改docker0接口的ip地址,但是难以找到适用于Windows 7的确切解决方案。请帮助我寻找解决方案。
I'm using Docker Toolbox for windows 7, I'm trying to change the ip address of docker0 interface but, having difficulty in finding the exact solution which works for Windows 7. Can anyone please help me in finding the solution.
Client:
Version: 1.12.5
API version: 1.24
Go version: go1.6.4
Git commit: 7392c3b
Built: Fri Dec 16 06:14:34 2016
OS/Arch: linux/amd64
Server:
Version: 1.12.5
API version: 1.24
Go version: go1.6.4
Git commit: 7392c3b
Built: Fri Dec 16 06:14:34 2016
OS/Arch: linux/amd64
谢谢。
推荐答案
要更改IP地址, Docker 将在其 docker0
接口上设置使用定义CIDR的-bip
选项(例如-bip = 10.32.57.1 / 24
) ,请参见 Docker 用户指南中的working / default_network / custom-docker0 / rel = nofollow noreferrer> 自定义docker0网桥。
To change the IP address Docker will set on it's docker0
interface, you have to use the --bip
option which defines the CIDR (eg. --bip=10.32.57.1/24
), see "Customize the docker0 bridge" in Docker user guide.
Docker工具箱 使用基于虚拟机的 Boot2Docker (在虚拟机中运行) 微型Core Linux 操作系统。
Docker Toolbox uses Boot2Docker (running in a virtual machine) which is based on the Tiny Core Linux OS.
Docker 守护程序在启动之前读取 / var / lib / boot2docker / profile
(请参阅中的 rel = nofollow noreferrer> 本地自定义的常见问题解答),其中 EXTRA_ARGS
变量已准备好填充自定义设置。
Docker daemon reads /var/lib/boot2docker/profile
before starting (see "Local Customisation" in Boot2Docker's FAQ) where a EXTRA_ARGS
variable is ready to be filled with your custom settings.
只需将-bip = ...
添加到 EXTRA_ARGS
的值部分,然后重新启动守护程序。
Just add your --bip=...
in EXTRA_ARGS
's value part and restart the daemon.
以下命令(用于键入 Docker快速入门Terminal )将停止 Docker 守护进程,删除所有现有规则,删除接口,并在<$$中添加-bip
选项c $ c> / var / lib / boot2docker / profile 并重新启动守护程序:
The following command (to type in the Docker Quickstart Terminal) will stop the Docker daemon, drop any existing rule, delete the interface, add a --bip
option to /var/lib/boot2docker/profile
and restart the daemon:
docker-machine ssh default "\
sudo /etc/init.d/docker stop ; \
sudo iptables -t nat -F POSTROUTING ; \
sudo ip link del docker0 ; \
sudo sed -i \"/^EXTRA_ARGS='\\$/a --bip=10.32.57.1/24\" /var/lib/boot2docker/profile ; \
sudo /etc/init.d/docker start \
"
( / var / lib / boot2docker
的内容在 Boot2Docker 虚拟机重启之间持续存在,因此只需运行一次此命令就足够了)
(Content of /var/lib/boot2docker
is persisted between Boot2Docker VM restarts so running this command once should suffice)
您可以使用以下命令进行检查:
You can check with:
docker-machine ssh default "ip a show dev docker0"
如果有人需要对Debian进行相同的操作(因此没有 Boot2Docker ):
对于 Sysvinit :
cat >> /etc/default/docker <<EOT
# Change Docker network bridge:
DOCKER_OPTS="--bip=10.32.57.1/24" # "3257" = "dckr" on a phone keyboard
EOT
对于 systemd :
cat > /etc/systemd/system/docker.service <<'EOT'
[Service]
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// $OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY
EOT
mkdir /etc/sysconfig
cat > /etc/sysconfig/docker <<EOT
OPTIONS="--bip=10.32.57.1/24"
EOT
systemctl daemon-reload
然后(对于 Sysvinit 和 systemd ):
service docker stop
iptables -t nat -F POSTROUTING
ip link del docker0
service docker start
iptables -t nat -L -n # Check if POSTROUTING table is OK
这篇关于如何在Docker Toolbox上更改docker0桥接接口的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!