在流浪汉身上安装docker的最佳方法
我想创建几个预安装了在流浪汉身上安装docker的最佳方法,docker,vagrant,vagrant-provision,Docker,Vagrant,Vagrant Provision,我想创建几个预安装了docker的虚拟机 最好的/推荐的方法是什么 a) 让Docker provisioner做一些虚拟的事情,只是为了安装Docker,例如 mymachine.vm.provision "docker" do |docknode| # do something pointless end b) 通过shell provisioner脚本运行docker安装 mymachine.vm.provision "shell", path: "docker-in
docker
的虚拟机
最好的/推荐的方法是什么
a) 让Docker provisioner做一些虚拟的事情,只是为了安装Docker,例如
mymachine.vm.provision "docker" do |docknode|
# do something pointless
end
b) 通过shell provisioner脚本运行docker安装
mymachine.vm.provision "shell", path: "docker-installation-script.sh"
c) 使用预安装的Docker附带的流浪映像?我将其用作“您可以使用机器在本地Mac或Windows box、公司网络、数据中心或Azure、AWS或Digital Ocean等云提供商上创建Docker主机”。使用Docker启动虚拟机是一种简单快捷的方法。官方说明如下: 例如:
Vagrant.configure("2") do |config|
config.vm.provision "docker" do |d|
d.build_image "/vagrant/app"
end
end
或
我也在寻找这个问题的答案,在StackOverflow上找到了答案。看来你是对的。运行虚拟映像是安装最新版本DOCKER的最佳方式
config.vm.provision "docker" do |d|
d.run "hello-world"
end
From:如果您想安装特定版本的docker,您必须在docker provisioner(provisioners按顺序运行)之前运行shell provisioner来安装特定版本的docker。如果您使用的是具有支持的最新Vagrant(例如,下面的步骤是使用2.2.6测试的),然后,您可以使用非常简单的一个或两个一行程序安装Docker,而无需: 运行
vagrant provision
或vagrant up
并观察此输出:
==> default: Running provisioner: docker...
default: Installing Docker onto machine...
==> default: Running provisioner: docker_compose...
default: Checking for Docker Compose installation...
default: Getting machine and kernel name from guest machine...
default: Downloading Docker Compose 1.24.1 for Linux x86_64
default: Uploading Docker Compose 1.24.1 to guest machine...
default: Installing Docker Compose 1.24.1 in guest machine...
default: Symlinking Docker Compose 1.24.1 in guest machine...
最后,vagrant ssh
连接到VM并检查已部署Docker基础架构的版本:
$ docker --version
Client: Docker Engine - Community
Version: 19.03.3
API version: 1.40
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 01:00:44 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.3
API version: 1.40 (minimum version 1.12)
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 00:59:17 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
这里有一个更加用户友好的
Vagrant文件
(在Vagrant 2.2.7上测试)
Vagrant.configure(“2”)do | config|
config.vm.box=“ubuntu/bionic64”
#需要插件https://github.com/leighmcculloch/vagrant-docker-compose
config.vagrant.plugins=“vagrant docker compose”
#安装docker和docker compose
config.vm.provision:docker
config.vm.provision:docker_compose
config.vm.provider“virtualbox”do | vb|
vb.customize[“modifyvm”,:id,“--ioapic”,“on”]
vb.customize[“modifyvm”,:id,“--memory”,“2048”]
vb.customize[“modifyvm”,:id,“--cpu”,“2”]
结束
结束
如上所述,您可以从Vagrantfile
下面是步骤
$ vagrant up
Vagrant has detected project local plugins configured for this
project which are not installed.
vagrant-docker-compose
Install local plugins (Y/N) [N]: y
Installing the 'vagrant-docker-compose' plugin. This can take a few minutes...
Fetching: vagrant-docker-compose-1.5.1.gem (100%)
Installed the plugin 'vagrant-docker-compose (1.5.1)'!
Vagrant has completed installing local plugins for the current Vagrant
project directory. Please run the requested command again.
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/bionic64'...
...
==> default: Running provisioner: docker...
default: Installing Docker onto machine...
==> default: Running provisioner: docker_compose...
default: Checking for Docker Compose installation...
default: Getting machine and kernel name from guest machine...
default: Downloading Docker Compose 1.24.1 for Linux x86_64
default: Downloaded Docker Compose 1.24.1 has SHA256 signature cfb3...
default: Uploading Docker Compose 1.24.1 to guest machine...
default: Installing Docker Compose 1.24.1 in guest machine...
default: Symlinking Docker Compose 1.24.1 in guest machine...
$ vagrant ssh
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-88-generic x86_64)
vagrant@ubuntu-bionic:~$ docker -v
Docker version 19.03.8, build afacb8b7f0
vagrant@ubuntu-bionic:~$ docker-compose -v
docker-compose version 1.24.1, build 4667896b
我认为(b)是最好的部署方式,通过这种方式,您可以知道在部署过程中会发生什么。这意味着,当发现bug或您想要的某些功能时,您可以解决所有问题
有一天,也许您需要将docker部署到另一个地方,脚本将对您有很大帮助。使用boot2docker或vagrant是非常必要的
$ docker --version
Client: Docker Engine - Community
Version: 19.03.3
API version: 1.40
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 01:00:44 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.3
API version: 1.40 (minimum version 1.12)
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 00:59:17 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
$ vagrant up
Vagrant has detected project local plugins configured for this
project which are not installed.
vagrant-docker-compose
Install local plugins (Y/N) [N]: y
Installing the 'vagrant-docker-compose' plugin. This can take a few minutes...
Fetching: vagrant-docker-compose-1.5.1.gem (100%)
Installed the plugin 'vagrant-docker-compose (1.5.1)'!
Vagrant has completed installing local plugins for the current Vagrant
project directory. Please run the requested command again.
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/bionic64'...
...
==> default: Running provisioner: docker...
default: Installing Docker onto machine...
==> default: Running provisioner: docker_compose...
default: Checking for Docker Compose installation...
default: Getting machine and kernel name from guest machine...
default: Downloading Docker Compose 1.24.1 for Linux x86_64
default: Downloaded Docker Compose 1.24.1 has SHA256 signature cfb3...
default: Uploading Docker Compose 1.24.1 to guest machine...
default: Installing Docker Compose 1.24.1 in guest machine...
default: Symlinking Docker Compose 1.24.1 in guest machine...
$ vagrant ssh
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-88-generic x86_64)
vagrant@ubuntu-bionic:~$ docker -v
Docker version 19.03.8, build afacb8b7f0
vagrant@ubuntu-bionic:~$ docker-compose -v
docker-compose version 1.24.1, build 4667896b