Skip to content

Instantly share code, notes, and snippets.

@shui
Last active January 15, 2019 12:28
Show Gist options
  • Select an option

  • Save shui/7feba96b26bbd1076643dbe43c8df323 to your computer and use it in GitHub Desktop.

Select an option

Save shui/7feba96b26bbd1076643dbe43c8df323 to your computer and use it in GitHub Desktop.
Windows 10上使用docker

最近虽然总在忙跟IT不相干的事,但偶尔也想搞点事情。 常用系统切回Windows,但新系统不想像以前那样安装一堆开发环境,比如Mysql。打算用Docker代替。 记录下安装过程。

0

自行安装最新版本的Git Bash、VirtualBox会很方便。

1

官网下载并安装Docker Toolbox。

2

(节约时间)从https://github.com/boot2docker/boot2docker/releases/下载最新版本的boot2docker.iso到C:\Users\${USER}\.docker\machine\cache\目录下。

3

打开Git Bash,执行:

docker-machine create  -driver virtualbox  \
  --engine-registry-mirror http://f1361db2.m.daocloud.io  \  
  --virtualbox-hostonly-cidr "192.168.200.1/24"  \
  default
  1. docker-machine有个--virtualbox-hostonly-cidr选项可以指定创建的VirtualBox虚拟机使用的Host-Only网络的IP范围。但是网络不能过小,至少/28(VirtualBox的限制)。也不知道为什么。
  2. 最后一行是虚拟机名称,不能改,不然使用Docker命令会报错:could not read CA certificate "C:\\Users\\${USER}\\.docker\\machine\\machines\\default\\ca.pem": open C:\Users\${USER}\.docker\machine\machines\default\ca.pem: The system cannot find the path specified.。不知道哪里可以设置。

4

参考Creating a Docker Machine with a fixed IP使用固定IP。

$ docker-machine ssh default
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

docker@default:~$ echo "ifconfig eth1 192.168.200.100 netmask 255.255.255.0 broadcast 192.168.99.255 up" | sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null
docker@default:~$ exit
logout

这里也需要注意的是192.168.200.100最好是一开始分配给虚拟机的IP。
不然每次都要执行eval ${docker-machine env default}设置环境变量。不知道Git Bash将环境变量保存在哪了。

重启:

$ docker-machine restart default

如果修改IP后重启连接虚拟机可能会提示:

$ docker-machine env default
Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.101:2376": x509: certificate is valid for 192.168.99.100, not 192.168.99.101
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
Be advised that this will trigger a Docker daemon restart which might stop running containers.

需要执行:docker-machine regenerate-certs default
再修改下配置文件C:\Users\${USER}\.docker\machine\machines\default\config.json。修改HostOptionsEngineOptionsEnvNO_PROXY,改成新IP:"NO_PROXY=192.168.99.101"

5

更换虚拟机镜像存储位置。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment