我试图从一本关于Scrapy的书中学习。作者使用由vagrant和docker构建的测试环境。环境需要遵循本书中的教程。我对这两种技术都一无所知,但从昨天起就一直在努力让一切运转起来。经过几个小时的搜索,并尝试各种各样的事情(比如拔出我的指甲),我完全没有进展。
我试图包含任何可能相关的信息。很抱歉某些数据格式不佳。我是新来的。此外,我不得不从一些代码嵌入链接中删除'http',因为stackoverflow不会让我发布太多的超链接。
版本号为:vagrant 1.8.5,docker 1.12.1,ubuntu 16.04
当我进入包含vagrant文件的目录并运行'vagrant up --no-parallel'时,我得到了臭名昭着的“系统找不到可用的默认提供程序”,错误。
'vagrant box list'返回'没有安装的盒子!使用vagrant box add
添加一些。'
'vagrant global-status'返回“此计算机上没有活动的Vagrant环境!或者,您没有销毁并重新创建使用较旧版本的Vagrant启动的Vagrant环境。” (我的操作系统是一个全新的安装)
“docker info”返回:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 1.12.1
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 0
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: overlay bridge host null
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor seccomp
Kernel Version: 4.4.0-31-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.823 GiB
Name: chris-Inspiron-1440
ID: SIHD:H76B:TWRL:FZSA:MKGE:O4WK:IAZS:LQIS:SQ76:YFTY:7AD4:KJ5T
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: //index.docker.io/v1/
WARNING: No swap limit support
Insecure Registries:
127.0.0.0/8
systemctl status docker.service returns:
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2016-09-03 16:05:43 EDT; 48min ago
Docs: //docs.docker.com
Main PID: 2659 (dockerd)
Tasks: 17
Memory: 55.6M
CPU: 1.995s
CGroup: /system.slice/docker.service
├─2659 /usr/bin/dockerd -H fd://
└─2713 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.so
sudo docker守护进程-D返回:
FATA[0000] Error starting daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid
本书随附的流浪文件:
ENV['VAGRANT_DEFAULT_PROVIDER'] = "docker"
host_vagrantfile = "./Vagrantfile.dockerhost"
force_host_vm = TRUE
Vagrant.configure("2") do |config|
# -------------- Web server --------------
config.vm.define "web" do |web|
web.vm.provider "docker" do |d|
d.image = "scrapybook/web"
#d.build_dir = "../scrapybook-docker-web"
d.name = "web"
d.vagrant_machine = "docker-provider"
d.vagrant_vagrantfile = host_vagrantfile
d.force_host_vm = force_host_vm
end
web.vm.synced_folder ".", "/vagrant", disabled: true
web.vm.network "forwarded_port", guest: 9312, host: 9312
web.vm.hostname = "web"
end
# -------------- Spark server --------------
config.vm.define "spark" do |spark|
spark.vm.provider "docker" do |d|
d.image = "scrapybook/spark"
#d.build_dir = "../scrapybook-docker-spark"
d.name = "spark"
d.vagrant_machine = "docker-provider"
d.vagrant_vagrantfile = host_vagrantfile
d.force_host_vm = force_host_vm
end
spark.vm.synced_folder ".", "/root/book"
spark.vm.network "forwarded_port", guest: 21, host: 21
(30000..30009).each do |port|
spark.vm.network "forwarded_port", guest: port, host: port
end
spark.vm.hostname = "spark"
end
# -------------- ES server --------------
config.vm.define "es" do |es|
es.vm.provider "docker" do |d|
d.image = "scrapybook/es"
#d.build_dir = "../scrapybook-docker-es"
d.name = "es"
d.vagrant_machine = "docker-provider"
d.vagrant_vagrantfile = host_vagrantfile
d.force_host_vm = force_host_vm
end
es.vm.synced_folder ".", "/vagrant", disabled: true
es.vm.network "forwarded_port", guest: 9200, host: 9200
es.vm.hostname = "es"
end
# -------------- Redis server --------------
config.vm.define "redis" do |redis|
redis.vm.provider "docker" do |d|
d.image = "scrapybook/redis"
#d.build_dir = "../scrapybook-docker-redis"
d.name = "redis"
d.vagrant_machine = "docker-provider"
d.vagrant_vagrantfile = host_vagrantfile
d.force_host_vm = force_host_vm
end
redis.vm.synced_folder ".", "/vagrant", disabled: true
redis.vm.network "forwarded_port", guest: 6379, host: 6379
redis.vm.hostname = "redis"
end
# -------------- MySQL server --------------
config.vm.define "mysql" do |mysql|
mysql.vm.provider "docker" do |d|
d.image = "scrapybook/mysql"
#d.build_dir = "../scrapybook-docker-mysql"
d.name = "mysql"
d.vagrant_machine = "docker-provider"
d.vagrant_vagrantfile = host_vagrantfile
d.force_host_vm = force_host_vm
end
mysql.vm.synced_folder ".", "/vagrant", disabled: true
mysql.vm.network "forwarded_port", guest: 3306, host: 3306
mysql.vm.hostname = "mysql"
end
# -------------- 3 Scrapyd servers --------------
{
"scrapyd1" => 6801,
"scrapyd2" => 6802,
"scrapyd3" => 6803,
}.each do |host, port|
config.vm.define host do |scp|
scp.vm.provider "docker" do |d|
d.image = "scrapybook/dev"
#d.build_dir = "../scrapybook-docker-dev"
d.name = host
d.link("spark:spark")
d.link("web:web")
d.vagrant_machine = "docker-provider"
d.vagrant_vagrantfile = host_vagrantfile
d.force_host_vm = force_host_vm
end
scp.vm.synced_folder ".", "/vagrant", disabled: true
scp.vm.network "forwarded_port", guest: 6800, host: port
scp.vm.hostname = host
end
end
# -------------- Dev machine --------------
config.vm.define "dev", primary: true do |dev|
dev.vm.provider "docker" do |d|
d.image = "scrapybook/dev"
#d.build_dir = "../scrapybook-docker-dev"
d.name = "dev"
d.link("web:web")
d.link("spark:spark")
d.link("scrapyd1:scrapyd1")
d.link("scrapyd2:scrapyd2")
d.link("scrapyd3:scrapyd3")
d.link("mysql:mysql")
d.link("redis:redis")
d.link("es:es")
d.vagrant_machine = "docker-provider"
d.vagrant_vagrantfile = host_vagrantfile
d.force_host_vm = force_host_vm
end
dev.vm.synced_folder ".", "/root/book"
dev.vm.network "forwarded_port", guest: 6800, host: 6800
dev.vm.hostname = "dev"
end
config.ssh.username = 'root'
config.ssh.private_key_path = 'insecure_key'
end
还有一个名为Vagrant.dockerhost的文件,该文件在Vagrantfile中引用:
# Set if you are behind proxy
#proxy_url = "http://user:pass@proxy.com:8080/"
Vagrant.configure("2") do |config|
if !defined?(proxy_url) || proxy_url.nil? || proxy_url.empty?
# No proxy setup necessary.
else
# Setup proxies
ENV['http_proxy'] = proxy_url
ENV['https_proxy'] = proxy_url
end
config.vm.define "docker-provider"
config.vm.box = "lookfwd/scrapybook"
# Setting up ports
(
[9200] + # ES
[6379] + # Redis
[3306] + # MySQL
[9312] + # Web
(6800..6803).to_a + # Scrapyd
[21] + (30000..30009).to_a + # Spark
[]).each do |port|
config.vm.network "forwarded_port", guest: port, host: port
end
# Set the mem/cpu requirements
config.vm.provider :virtualbox do |vb|
vb.memory = 2048
vb.cpus = 4
vb.name = "docker-provider"
vb.check_guest_additions = false
end
end
答案 0 :(得分:0)
解决方法是安装VirtualBox
答案 1 :(得分:0)
如果您只需要在没有VM Host的情况下使用docker,请将force_host_vm = TRUE更改为FALSE(force_host_vm = FALSE)