Hello,
trying to use my Dockerfile with vagrant I ran into the message "Provisioners will not be run since container doesn't support SSH".
Interestingly the Dockerfile works fine without vagrant. With vagrant It seems the container is not started at all.
OS: Mac OS/x
Docker: 0.10
Vagrant 1.6.2
Using "docker ps" I got the error that client and server versions are different. Downgrading client to docker 0.10 fixed that.
What can be done to make this work?
Thanks!
Alex
Dockerfile
FROM ubuntu:14.04
# Update the system
RUN echo "deb http://archive.ubuntu.com/ubuntu trusty main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y
# Install OpenSSH Server and set credentials to root/root
RUN apt-get install -y openssh-server
RUN mkdir -p /var/run/sshd
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
RUN sed -ri 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
RUN echo 'root:root' | chpasswd
# Setup basic aliases
RUN echo "\nalias ..='cd ..'" >> /root/.bashrc
# Expose port 22 for ssh
EXPOSE 22
CMD /usr/sbin/sshd -D
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.define "app" do |app|
app.vm.provider "docker" do |d|
d.build_dir = "."
d.name = "demo_box"
end
end
end
Shell-Script to run
#!/bin/sh
vagrant destroy --force
vagrant up --provider=docker
Vagrant output
./container_run.sh
==> app: Stopping container...
==> app: Deleting the container...
Bringing machine 'app' up with 'docker' provider...
==> app: Docker host is required. One will be created if necessary...
app: Docker host VM is already ready.
==> app: Syncing folders to the host VM...
app: Rsyncing folder: /Users/alex/space/projects/docker/vagrant/ => /var/lib/docker/docker_1401304062_36653
app: Rsyncing folder: /Users/alex/space/projects/docker/vagrant/ => /mnt/docker_build_ef9d90609727622f6191842cfa92d268
==> app: Building the container from a Dockerfile...
app: Image: 13333f54d9b1
==> app: Warning: When using a remote Docker host, forwarded ports will NOT be
==> app: immediately available on your machine. They will still be forwarded on
==> app: the remote machine, however, so if you have a way to access the remote
==> app: machine, then you should be able to access those ports there. This is
==> app: not an error, it is only an informational message.
==> app: Creating the container...
app: Name: demo_box
app: Image: 13333f54d9b1
app: Volume: /var/lib/docker/docker_1401304062_36653:/vagrant
app: Port: 2222:22
app:
app: Container created: dd2f056693b6a970
==> app: Starting container...
==> app: Provisioners will not be run since container doesn't support SSH.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd2f056693b6 13333f54d9b1 /bin/sh -c '/usr/sbi 4 minutes ago Up 4 minutes 0.0.0.0:2222->22/tcp demo_box
Trying to ssh into container
ssh root@localhost -p 2222
root@localhost's password:
Permission denied, please try again.
Everything looks good to me!
If you want SSH to work, you must explicitly say has_ssh = true in the Docker config and configure the SSH key/password and port.
Note that forwarded ports will not work with proxy VMs, so you'll need to specify an IP on the host VM probably.
This is all documented here: http://docs.vagrantup.com/v2/docker/basics.html
Hate to comment on a SUPER old thread, but the documentation seems rather thin in terms of working examples. They are all individual pieces that are not weaved together. I am experiencing a similar issue but "configure the SSH key/password and port" is too vague for me to suss out the issue. I have scoured Google for the past two days but most walkthroughs have been from 2015.
OS X 10.13.3 (High Sierra)
Vagrant 2.0.2
VirtualBox 5.2.6
Using a separate Vagrantfile for the host VM:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.network :forwarded_port, guest: 80, host: 4567
config.vm.provision "docker"
# fixes error where a docker.lock file can't be accessed due to permissions
config.vm.provision "shell", inline: "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill"
# ensures vagrant is in the docker group so no further permissions issues occur
config.vm.provision "shell", inline: "usermod -aG docker vagrant"
config.vm.define "dockerhostvm"
config.vm.box = "ubuntu/xenial64"
config.vm.synced_folder "./", "/vagrant", id: "vagrant-root",
owner: "vagrant",
group: "www-data",
mount_options: ["dmode=775,fmode=664"],
type: ""
config.vm.provider :virtualbox do |vb|
vb.name = "dockerhostvm"
vb.memory = 4096
vb.cpus = 2
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
end
Container Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# config.vm.synced_folder ".", "/vagrant", type: "nfs", disabled: true
config.vm.define "my-container" do |m|
m.ssh.username = "root"
m.ssh.password = "root"
m.ssh.port = 22
m.vm.provider :docker do |d|
d.name = "my-container"
d.vagrant_machine = "dockerhostvm"
d.vagrant_vagrantfile = "./host/Vagrantfile"
d.build_dir = "."
d.force_host_vm = true
d.has_ssh = true
d.cmd = ["tail", "-f", "/dev/null"]
d.remains_running = true
d.ports = ['80:80']
end
end
end
The Dockerfile (only contains lines from the Docker docs for ssh):
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Finally, the tail of the vagrant up output (the host vm successfully spins up based on container Vagrantfile):
my-container: ---> bf064e84f943
my-container: Step 10/10 : CMD ["/usr/sbin/sshd", "-D"]
my-container: ---> Running in d76eb8c6152f
my-container: Removing intermediate container d76eb8c6152f
my-container: ---> c5081aab7f32
my-container: Successfully built c5081aab7f32
my-container:
my-container: Image: c5081aab7f32
==> my-container: Warning: When using a remote Docker host, forwarded ports will NOT be
==> my-container: immediately available on your machine. They will still be forwarded on
==> my-container: the remote machine, however, so if you have a way to access the remote
==> my-container: machine, then you should be able to access those ports there. This is
==> my-container: not an error, it is only an informational message.
==> my-container: Creating the container...
my-container: Name: my-container
my-container: Image: c5081aab7f32
my-container: Cmd: tail -f /dev/null
my-container: Volume: /var/lib/docker/docker_1518127122_93706:/vagrant
my-container: Port: 127.0.0.1:2222:22
my-container: Port: 80:80
my-container:
my-container: Container created: af42c4f56066e503
==> my-container: Starting container...
==> my-container: Waiting for machine to boot. This may take a few minutes...
/opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/transport/packet_stream.rb:214:in `poll_next_packet': padding error, need 1497196486 block 16 (Net::SSH::Exception)
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/transport/packet_stream.rb:87:in `next_packet'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/transport/session.rb:193:in `block in poll_message'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/transport/session.rb:188:in `loop'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/transport/session.rb:188:in `poll_message'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/session.rb:544:in `dispatch_incoming_packets'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/session.rb:246:in `ev_preprocess'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/event_loop.rb:99:in `each'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/event_loop.rb:99:in `ev_preprocess'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/event_loop.rb:27:in `process'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/session.rb:225:in `process'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/session.rb:178:in `block in loop'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/session.rb:178:in `loop'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/session.rb:178:in `loop'
from /opt/vagrant/embedded/gems/gems/net-ssh-4.2.0/lib/net/ssh/connection/channel.rb:269:in `wait'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/plugins/communicators/ssh/communicator.rb:645:in `shell_execute'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/plugins/communicators/ssh/communicator.rb:236:in `block in execute'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/plugins/communicators/ssh/communicator.rb:333:in `connect'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/plugins/communicators/ssh/communicator.rb:230:in `execute'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/plugins/providers/docker/executor/vagrant.rb:32:in `execute'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/plugins/providers/docker/driver.rb:172:in `execute'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/plugins/providers/docker/driver.rb:84:in `created?'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/plugins/providers/docker/provider.rb:179:in `state'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/lib/vagrant/machine.rb:514:in `state'
from /opt/vagrant/embedded/gems/gems/vagrant-2.0.2/lib/vagrant/action/builtin/wait_for_communicator.rb:26:in `block in call'
I can open a new issue if necessary but this thread is the only one i could find with setup/results closest to my problem.
Hey @Smolations - please open a new issue...thanks! :)
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Hate to comment on a SUPER old thread, but the documentation seems rather thin in terms of working examples. They are all individual pieces that are not weaved together. I am experiencing a similar issue but "configure the SSH key/password and port" is too vague for me to suss out the issue. I have scoured Google for the past two days but most walkthroughs have been from 2015.
OS X 10.13.3 (High Sierra)
Vagrant 2.0.2
VirtualBox 5.2.6
Using a separate Vagrantfile for the host VM:
Container Vagrantfile:
The Dockerfile (only contains lines from the Docker docs for ssh):
Finally, the tail of the
vagrant upoutput (the host vm successfully spins up based on container Vagrantfile):I can open a new issue if necessary but this thread is the only one i could find with setup/results closest to my problem.