boot2docker Vagrant Box

This repository contains the scripts necessary to create a boot2docker Vagrant box compatible with Parallels provider. If you work solely with Docker, this box lets you keep your Vagrant workflow and work in the most minimal Docker environment possible.

Docker installation

Docker client should be installed on your Mac. It is bundled to Docker Toolbox

Usage

The box is available on Atlas, making it very easy to use it:

vagrant init parallels/boot2docker
vagrant up

Then you need to prepare your environment for Docker client

If TLS is enabled (by default):

# Copy TLS certificates from the VM to `./tls/` directory on your Mac host:
vagrant ssh -c "sudo cp -r /var/lib/boot2docker/tls `pwd`/"

export DOCKER_TLS_VERIFY="1"
export DOCKER_CERT_PATH="`pwd`/tls"
export DOCKER_HOST="tcp://`vagrant ssh-config | sed -n "s/[ ]*HostName[ ]*//gp"`:2376"

If TLS is disabled:

Use these commands to disable TLS for Docker daemon (you should do it only once, after the initial vagrant up):

vagrant ssh -c "sudo sh -c 'echo \"export DOCKER_TLS=no\" > /var/lib/boot2docker/profile'"
vagrant reload

Now you just need to set DOCKER_HOST variable:

unset DOCKER_TLS_VERIFY
export DOCKER_HOST="tcp://`vagrant ssh-config | sed -n "s/[ ]*HostName[ ]*//gp"`:2375"

That's it! Now your VM can be used as Docker host, check it:

docker version
...

Shared Folders

/Users path on you Mac is shared with boot2docker VM by default. It means that you can mount any directory placed in /Users on your Mac into the container, for example:

docker run -v /Users/bob/myapp/src:/src [...]

If you want to mount any directory outside of /Users, then you should set it (or its parent dir) as a synced folder in your Vagrantfile at first:

config.vm.synced_folder "/tmp/dir_to_share", "/tmp/dir_to_share"

Refer to "Synced Folders - Basic Usage" to get more details about synced folders in Vagrant.

Tips & tricks

  • Vagrant synced folders has been tested with :

    • Parallels Shared Folders : This is default sharing system for Parallels provider

    • NFS : Set B2D_NFS_SYNC environment variable to use NFS for sharing folders:

      $ export B2D_NFS_SYNC=1
      $ vagrant up
  • If you want to tune contents (custom profile, install tools inside the VM), just place a bootlocal.sh script alongside your Vagrantfile. It will be run in the VM automatically each time after vagrant up. Refer to boot2docker FAQ to get more details.

Building the Box

If you want to recreate the box, rather than using the binary, then you can use the scripts and Packer template within this repository to do so in seconds.

To build the box, first install the following prerequisites:

Then run this command to build the box for Parallels provider:

make

Execute this to run integration tests:

make test-parallels

Authors



boot2docker Vagrant Box

此存储库包含创建a所需的脚本 boot2docker 与Vagrant框兼容的 Parallels提供商。 如果您仅使用Docker,此框可让您保持Vagrant工作流程 可以在最小的Docker环境中工作。

Docker安装

Docker客户端应该安装在Mac上。它被捆绑到 Docker Toolbox

用法

该框适用于 Atlas , 使其很容易使用:

vagrant init parallels/boot2docker
vagrant up

然后,您需要为Docker客户端准备您的环境

如果启用TLS(默认情况下):

# Copy TLS certificates from the VM to ./tls/ directory on your Mac host:
vagrant ssh -c "sudo cp -r /var/lib/boot2docker/tls </span>pwd<span class="pl-pds">/"

export DOCKER_TLS_VERIFY="1" export DOCKER_CERT_PATH="</span>pwd<span class="pl-pds">/tls" export DOCKER_HOST="tcp://</span>vagrant ssh-config <span class="pl-k">|</span> sed -n <span class="pl-s"><span class="pl-pds">&#34;</span>s/[ ]*HostName[ ]*//gp<span class="pl-pds">&#34;</span></span><span class="pl-pds">:2376"

如果禁用TLS:

使用这些命令可以禁用Docker守护程序的TLS(您应该这样做) 只有一次,最初的 vagrant up ):

vagrant ssh -c "sudo sh -c 'echo &#34;export DOCKER_TLS=no&#34; > /var/lib/boot2docker/profile'"
vagrant reload

现在您只需要设置 DOCKER_HOST 变量:

unset DOCKER_TLS_VERIFY
export DOCKER_HOST="tcp://vagrant ssh-config | sed -n &#34;s/[ ]*HostName[ ]*//gp&#34;:2375"

就是这样!现在您的虚拟机可以用作Docker主机,请检查它:

docker version
…

共享文件夹

默认情况下,您的Mac共享与boot2docker VM共享的

/ Users 路径。它的意思是 您可以将安装在Mac上的 / Users 中的任何目录装入 容器,例如:

docker run -v /Users/bob/myapp/src:/src […]

如果要安装 / Users 之外的任何目录,那么您应该设置它 (或其父目录)作为您的Vagrantfile中的同步文件夹:

config.vm.synced_folder "/tmp/dir_to_share", "/tmp/dir_to_share"

请参阅同步文件夹 - 基本使用情况 获取有关Vagrant中同步文件夹的更多详细信息。

提示&amp;

  • Vagrant同步的文件夹已通过以下测试:

    • 并行共享文件夹:这是Parallels提供商的默认共享系统

    • NFS : 设置 B2D_NFS_SYNC 环境变量以使用NFS共享文件夹:

       $  export  B2D_NFS_SYNC = 1
      $ vagrant up 
  • 如果要调整内容(自定义配置文件,在VM中安装工具), 只需在您的Vagrantfile旁边放置一个 bootlocal.sh 脚本。 每次在 vagrant up 后,VM将自动运行。 请参阅 boot2docker常见问题解答 获得更多细节。

构建框

如果要重新创建该框,而不是使用二进制文件 您可以使用此存储库中的脚本和Packer模板 在几秒钟内完成。

要构建该框,请首先安装以下先决条件:

然后运行此命令构建Parallels提供程序的框:

make

执行此运行集成测试:

make test-parallels

作者




相关问题推荐