我正在尝试通过 vagrant 安装 Docker 作为 VM 设置的一部分。我在 vagrant 文件中添加了以下内容:
# Install Docker:
config.vm.provision :shell, path: "./shared_directory/install_scripts/install_docker.sh"
为install_docker.sh
:
echo "-------Try to install docker---------"
cd ~
sudo su -
apt-get update
apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
echo "Y" | apt-get install docker-ce
使用提供的说明这里。需要注意的是,当我使用 create this VM 时(无论我是否调用我的install_docker.sh
),如果我在 VM 内部使用这些命令(例如通过从 shell 文件中复制和粘贴它们),Docker 即安装成功。
当我尝试使用 Vagrantfile 和 shell 脚本(通过vagrant up
)执行此操作时,我得到了以下信息:
default: -------Try to install docker--------- default: Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease default: Hit:2 http://ppa.launchpad.net/webupd8team/java/ubuntu trusty InRelease default: Hit:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease default: Hit:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease default: Hit:5 http://security.ubuntu.com/ubuntu xenial-security InRelease default: Reading package lists... default: Reading package lists... default: Building dependency tree... default: Reading state information... default: apt-transport-https is already the newest version (1.2.26). default: ca-certificates is already the newest version (20170717~16.04.1). default: curl is already the newest version (7.47.0-1ubuntu2.7). default: software-properties-common is already the newest version (0.96.20.7). default: 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. default: OK default: pub 4096R/0EBFCD88 2017-02-22 default: Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 default: uid Docker Release (CE deb) <[email protected]> default: sub 4096R/F273FCD8 2017-02-22 default: Reading package lists... default: Building dependency tree... default: Reading state information... default: Package docker-ce is not available, but is referred to by another package. default: This may mean that the package is missing, has been obsoleted, or default: is only available from another source default: E default: : default: Package 'docker-ce' has no installation candidate
在设置虚拟机时我应该怎么做才能确保 Docker 已经安装?
答案1
似乎您还应该apt-get update
在添加存储库后(脚本的最后两行)执行此操作。
安装 Docker CE
更新 apt 包索引。
$ sudo apt-get update
安装最新版本的 Docker CE (...)
$ sudo apt-get install docker-ce
因此,您可以尝试将脚本的最后一行更改为:
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
echo "Y" | apt-get install docker-ce
您也可以尝试将最后一行更改为:
apt-get -y install docker-ce
尽管我不知道这是否会带来什么区别。
如果一切都失败了,可以在该页面下方找到一个脚本“使用便捷脚本安装“部分,除非您不能/不想使用它。