我对Vagrant和Docker都是陌生的.
我要在这里做的是通过Vagrant中的docker提供一个容器,并使用Shell Provisioner安装一个小型Webapp.
这是我的Vagrantfile
Vagrant.configure(2) do |config|
# config.vm.provision :shell,path: "bootstrap.sh"
config.vm.provision :shell,inline: 'echo Hi there !!!'
config.vm.provider :docker do |d|
d.name="appEnvironment"
d.image = "phusion/baseimage"
d.remains_running = true
d.has_ssh = true
d.cmd = ["/sbin/my_init","--enable-insecure-key"]
end
end
我在这里面临的问题是,在创建容器之后,它会继续运行以下内容,最终只是停止.
当我输入docker ps时,我可以看到一个正在运行的docker容器,但它没有运行配置部分.我假设这是因为ssh没有成功
==> default: Creating the container...
default: Name: appEnvironment
default: Image: phusion/baseimage
default: Cmd: /sbin/my_init --enable-insecure-key
default: Volume: /home/devops/vagrantBoxForDemo:/vagrant
default: Port: 127.0.0.1:2222:22
default:
default: Container created: 56a87b7cd10c22fe
==> default: Starting container...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 172.17.0.50:22
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...
有人可以让我知道我可能在哪里吗?我也尝试更改图像,但没有成功.
最佳答案
首先从以下位置下载phusion提供的不安全密钥:
原文链接:https://www.f2er.com/docker/532552.htmlhttps://github.com/phusion/baseimage-docker/blob/master/image/insecure_key
*请记住,不安全的密钥应仅用于开发目的.
现在,您需要通过在Dockerfile中添加以下内容来启用ssh:
FROM phusion/baseimage
RUN rm -f /etc/service/sshd/down
RUN /etc/my_init.d/00_regen_ssh_host_keys.sh
RUN /usr/sbin/enable_insecure_key
启用ssh并在Vagrantfile中指定密钥文件:
Vagrant.configure("2") do |config|
config.vm.define "app" do |app|
app.vm.provider "docker" do |d|
d.build_dir = "."
d.cmd = ["/sbin/my_init","--enable-insecure-key"]
d.has_ssh = true
end
end
config.ssh.username = "root"
config.ssh.private_key_path = "path/to/your/insecure_key"
end
改善环境
vagrant up
现在您应该可以通过ssh访问您的容器
vagrant ssh app