目标
充分利用Parallels Desktop 虚拟管理平台,在mac 电脑上安装好Docker,能正常运行,使用Mac简洁。
条件
- brew 如果还没安装,请参考Mac下安装brew
- Parallels Desktop 11.0.0+ Pro or Business edition(标准版不支持)
安装过程
- 安装
1.1 使用brew命令安装方法
brew install docker-machine-parallels
此过程会自动安装 docker-machine命令
1.2 或者:直接下载 docker-machine-driver-parallels 放到$PATH中。
命令
$curl -L https://github.com/Parallels/docker-machine-parallels/releases/download/v1.4.0/docker-machine-driver-parallels > /usr/local/bin/docker-machine-driver-parallels
$chmod +x /usr/local/bin/docker-machine-driver-parallels
$brew install docker-machine
国内用户下载详见文章最后网盘
- Mac 安装 Docker客户端
brew install docker
- 创建book2docker虚拟机
docker-machine create --driver=parallels prl-dev
其中 prl-dev 为虚拟机名字,可以自定义
输出参考:
docker-machine create --driver=parallels prl-dev
Creating CA: /Users/xxx/.docker/machine/certs/ca.pem
Creating client certificate: /Users/xxx/.docker/machine/certs/cert.pem
Running pre-create checks...
(prl-dev) Image cache directory does not exist, creating it at /Users/xxx/.docker/machine/cache...
(prl-dev) No default Boot2Docker ISO found locally, downloading the latest release...
(prl-dev) Latest release for github.com/boot2docker/boot2docker is v19.03.5
(prl-dev) Downloading /Users/xxx/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v19.03.5/boot2docker.iso...
(prl-dev) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(prl-dev) Copying /Users/xxx/.docker/machine/cache/boot2docker.iso to /Users/xxx/.docker/machine/machines/prl-dev/boot2docker.iso...
(prl-dev) Creating SSH key...
(prl-dev) Creating Parallels Desktop VM...
(prl-dev) Starting Parallels Desktop VM...
(prl-dev) Waiting for VM to come online...
(prl-dev) Mounting shared folder "/Users" ...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
当出现Docker is up and running 表示成功。
如果boot2docker.iso无法下载,请自行下载到/Users/xxx/.docker/machine/machines/prl-dev/【xxx为自己的mac帐号,请自行更改,prl-dev为虚拟机名字,如果不同,请自行更改】,下载地址:https://github.com/boot2docker/boot2docker/releases
国内用户下载详见文章最后网盘。
- Docker 绑定虚拟机
docker-machine env prl-dev
eval $(docker-machine env prl-dev)
如有需要,可以增加
eval $(docker-machine env prl-dev)
到你的bash环境中。
- 查看 docker
docker verion
输出参考:
docker version
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.13.4
Git commit: 633a0ea
Built: Thu Nov 14 23:51:40 2019
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea838
Built: Wed Nov 13 07:28:45 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
- 运行hellow world
docker run hello-world
参考输出:
docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
至此Docker 安装完成。
总结
不少用户Mac 电脑安装了 Parallels Desktop 虚拟机管理平台,而Docker程序由于基于Linux内核开发,其服务器端并不能在Mac下直接运行。开源程序docker-machine-parallels为docker-machine插件,使得Mac用户利用Parallels Desktop优秀的虚拟化技术为docker服务。
安装完成之后,Parallels Desktop 会多出一个 prl-dev 虚拟机,请勿删除。
资源网盘
链接: https://pan.baidu.com/s/1y5EABosMkWuJh8Y3o_vijg 提取码: srj3
附录
定制虚拟机参考:
To create a Parallels Desktop virtual machine for Docker purposes just run this command:
$ docker-machine create --driver=parallels prl-dev
Available options:
-
--parallels-boot2docker-url
: The URL of the boot2docker image. -
--parallels-disk-size
: Size of disk for the host VM (in MB). -
--parallels-memory
: Size of memory for the host VM (in MB). -
--parallels-cpu-count
: Number of CPUs to use to create the VM (-1 to use the number of CPUs available). -
--parallels-video-size
: Size of video memory for host (in MB). -
--parallels-share-folder
: Path to the directory which should be shared with the host VM. Could be specified multiple times, once per each directory. -
--parallels-no-share
: Disable the sharing of any directory. -
--parallels-nested-virutalization
: Enable nested virtualization.
The --parallels-boot2docker-url
flag takes a few different forms. By default, if no value is specified for this flag, Machine will check locally for a boot2docker ISO. If one is found, that will be used as the ISO for the created machine. If one is not found, the latest ISO release available on boot2docker/boot2docker will be downloaded and stored locally for future use.
This is the default behavior (when --parallels-boot2docker-url=""
), but the option also supports specifying ISOs by the http://
and file://
protocols.
Environment variables and default values:
CLI option | Environment variable | Default |
---|---|---|
--parallels-boot2docker-url |
PARALLELS_BOOT2DOCKER_URL |
Latest boot2docker url |
--parallels-cpu-count |
PARALLELS_CPU_COUNT |
1 |
--parallels-disk-size |
PARALLELS_DISK_SIZE |
20000 |
--parallels-memory |
PARALLELS_MEMORY_SIZE |
1024 |
--parallels-video-size |
PARALLELS_VIDEO_SIZE |
64 |
--parallels-share-folder |
- | /Users |
--parallels-no-share |
- | false |
--parallels-nested-virtualization |
- | false |