I have deployed my vagrant machine using the docker provider. I am able to access it from local.
My Vagrantfile
Vagrant.configure(2) do |config|
ENV["LC_ALL"] = "en_US.UTF-8"
config.vm.hostname = "dev-machine1"
config.vm.provider "docker" do |d|
d.image = "tknerr/baseimage-ubuntu:18.04"
d.has_ssh = true
end
config.vm.network "forwarded_port", guest: 80, host: 8080, id: "nginx", auto_correct: true
config.ssh.insert_key = false
config.ssh.forward_agent = true
config.vm.provision "shell" do |s|
ssh_pub_key = File.readlines("/root/.ssh/vagrant1.pub").first.strip # /root/.ssh/vagrant-sample
s.inline = <<-SHELL
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
directory="/root/.ssh/"
if [ ! -d "$directory" ]; then
mkdir -p "$directory"
echo "Directory '$directory' created."
else
echo "Directory '$directory' already exists."
fi
# sudo touch /root/.ssh/authorized_keys
sudo echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
SHELL
end
config.vm.provision "shell", path: ".provision/bootstrap.sh", privileged: false
end
I verified the public keys on the host machine as well as inside the container. They are correct. Able to SSH on port 2201 in local.
$ ssh -i vagrant1 vagrant@<my-other-node-where vagrant-vm-exists-ip>
Permission denied (public key)