docker学习(2) mac中docker-machine使用vmware fusion以及配置国内镜像加速

简介: 一、前言 先回顾下上一节创建docker-machine的过程,默认情况下docker toolbox中的docker-machine使用virtual box创建虚拟机,KI首次启动时创建虚拟机的过程,大致相当于下面这条命令: docker-machine create --driver ...

一、前言

先回顾下上一节创建docker-machine的过程,默认情况下docker toolbox中的docker-machine使用virtual box创建虚拟机,KI首次启动时创建虚拟机的过程,大致相当于下面这条命令:

docker-machine create --driver virtualbox default

输出如下:

Running pre-create checks...
Creating machine...
(default) Copying /Users/yjmyzz/.docker/machine/cache/boot2docker.iso to /Users/yjmyzz/.docker/machine/machines/default2/boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Machine is running, waiting for SSH to be available...
Detecting operating system of created instance...
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!
To see how to connect Docker to this machine, run: docker-machine env default

其大致过程为从网上下载boot2docker.iso这个文件,然后利用它创建VirtualBox VM,然后生成SSH key(方便免密码登录到虚拟机)、分配IP之类,创建完以后,可以用:

docker-machine env default

查看虚拟机default的状态,如果要删除该虚拟机,直接

rm -rf ~/.docker/machine/machines/default

现在才开始本文的正题:

 

二、使用vmware做为docker machine

对于已经在mac上安装了vmwarefusion的同学来讲,为了使用docker强制安装一个virtualbox有点多余,其实docker支持vmwarefusion,只要把driver改一下就行了,命令如下:

docker-machine create --driver vmwarefusion default

创建完成后,用docker-machine ls列出所有虚拟机

可以看到类型确实为vmwarefusion,然后可以

docker-machine ssh default

连接到虚拟机的终端下,顺便ping下外网地址,检查下虚拟机里是否能上网(这个很重要,因为后面下载镜像需要联网)

  

如果有条件翻*^墙的同学,可以运行

docker pull kitematic/hello-world-nginx 

直接从docker hub拉一个只有几M的镜像文件试试

 

三、设置国内镜像加速pull

docker hub官网太慢了,还好国内有一家公司daocloud提供了加速服务,设置步骤:

3.1 先到daocloud.io网站注册一个账号

过程略,注册成功后,进入控制台

3.2 点击控制台上的加速器

拉到中间部分,有一个『主机监控程序』的文字链接,见下图:

然后选择主机类型,我用的是mac,所以选择mac主机:

如果已经安装好了docker toolbox最新版,直接点击【安装好了】

然后会出现二条命令,复制粘贴执行即可:

注:如果按它的提示,最后出现latest: Pulling from daocloud/daomonit not found之类的错误,可以尝试

docker logout daocloud.io

然后重试,安装成功后,执行

dao pull ubuntu

就可以感受下速度了

  

如果好奇dao这个命令是什么鬼?可以

which dao

查找下位置,正常情况下应该在/usr/local/bin/dao下,可以cat看下该文件的内容:

#!/bin/sh

# DaoTools made by DaoCloud

# Update
command_exists() {
	command -v "$@" > /dev/null 2>&1
}
lsb_dist=''
if command_exists lsb_release; then
	lsb_dist="$(lsb_release -si)"
fi
if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
	lsb_dist="$(. /etc/os-release && echo "$ID")"
fi
lsb_dist="$(echo $lsb_dist | cut -d " " -f1)"
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"

sh_c='sh -c'

if [ "$user" != 'root' ]; then
	if command_exists sudo; then
		sh_c='sudo -E sh -c'
	elif command_exists su; then
		sh_c='su -c'
	else
		echo >&2 'Error: dao needs the ability to run commands as root.'
		echo >&2 'We are unable to find either "sudo" or "su" available to make this happen.'
	fi
fi


update_daotools() {
	## Update Bash from https://get.daocloud.io/daotools

	## Update Docker Image
	$sh_c "docker inspect daocloud.io/daocloud/daocloud-toolset" > /dev/null 2>&1
	if [ $? -eq 0 ]; then
	  $sh_c "docker pull daocloud.io/daocloud/daocloud-toolset"
	fi

	$sh_c "curl --retry 20 --retry-delay 5 -L -o /tmp/daotools https://get.daocloud.io/daotools"
	if grep -q "DaoCloud" /tmp/daotools
	then
		$sh_c "chmod +x /tmp/daotools"
		if [  "$lsb_dist" = "coreos"  ]
		then
			$sh_c "mv -f /tmp/daotools /opt/bin/dao"
		else
			$sh_c "mv -f /tmp/daotools /usr/local/bin/dao"
		fi
	fi

#	if [ "$(uname)" == "Darwin" ]
#	then
#		chmod 777 /usr/local/bin/dao
#	fi




}



# RUN

$sh_c "docker inspect daocloud.io/daocloud/daocloud-toolset" > /dev/null 2>&1
if [ $? -eq 1 ]; then
	echo "Dao from DaoCloud"
	echo "Initializing, Please wait a minute"
	$sh_c "docker pull daocloud.io/daocloud/daocloud-toolset"
	if [ $? -eq 0 ]; then
		echo "Inital Success"
		echo
	fi
fi

# UPDATE

update_daotools > /dev/null 2>&1  &


# check if this is a tty mode
tty > /dev/null 2>&1

if [ $? -eq 0 ]
then
        istty="-it"
else
        istty=""
fi

if [ "$(uname)" = "Darwin" ]
then
	$sh_c "docker run --rm -v /var/run/docker.sock:/var/run/docker.sock  -v $(which docker):/usr/bin/docker:ro \
	  -v /mnt/sda1/daocloud:/etc/daocloud -v /tmp/daocloud:/tmp/daocloud $istty daocloud.io/daocloud/daocloud-toolset $*"
elif [ "$lsb_dist" = "boot2docker" ]
then
	$sh_c "docker run --rm -v /var/run/docker.sock:/var/run/docker.sock  -v $(which docker):/usr/bin/docker:ro \
	  -v /mnt/sda1/daocloud:/etc/daocloud -v /tmp/daocloud:/tmp/daocloud $istty daocloud.io/daocloud/daocloud-toolset $*"
else
	$sh_c "docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker:ro \
	  -v /etc/daocloud:/etc/daocloud -v /tmp/daocloud:/tmp/daocloud --privileged $istty daocloud.io/daocloud/daocloud-toolset $*"

有兴趣的可以仔细研究研究

 

参考文章:

http://elasticskies.com/docker-machine-on-osx-with-vmware-fusion/

目录
相关文章
|
1月前
|
关系型数据库 MySQL 开发工具
MySQL5.7主从配置(Docker)
MySQL5.7主从配置(Docker)
726 0
|
2月前
|
NoSQL Redis 数据安全/隐私保护
Docker中Redis的安装与配置
本文主要讲解如何在Docker环境中搭建Redis环境,并进行相关配置
241 5
Docker中Redis的安装与配置
|
16天前
|
前端开发 应用服务中间件 nginx
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
78 0
|
30天前
|
NoSQL 关系型数据库 MySQL
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
188 0
|
1月前
|
存储 Ubuntu Shell
mac docker镜像在哪个文件夹
【2月更文挑战第22天】
|
1月前
|
前端开发 应用服务中间件 nginx
Docker安装nginx和基本配置
Docker安装nginx和基本配置
123 0
|
2月前
|
存储 文件存储 数据安全/隐私保护
Docker环境下Minio文件存储的安装与配置
Docker环境下Minio文件存储的安装与配置
71 4
|
2月前
|
Docker 容器
Docker Compose的安装与配置
Docker Compose的安装与配置
125 2
Docker Compose的安装与配置
|
2月前
|
存储 网络安全 API
|
2月前
|
应用服务中间件 Shell nginx
【Docker】Docker安装Nginx配置静态资源
【Docker】Docker安装Nginx配置静态资源
73 0