Last active
September 7, 2016 19:20
-
-
Save tko/070266e7237e0453212d0a0125c4683f to your computer and use it in GitHub Desktop.
vagrant with docker backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:12.04 | |
# https://www.vagrantup.com/docs/boxes/base.html | |
RUN apt-get update \ | |
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ | |
bash \ | |
openssh-server \ | |
sudo \ | |
&& rm -rf /var/lib/apt/lists/* \ | |
# Required to not get a 'Missing privilege separation directory' error, normally created by init script | |
&& mkdir /var/run/sshd \ | |
&& chmod 0755 /var/run/sshd | |
# https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub /home/vagrant/.ssh/authorized_keys | |
RUN ssh_key='ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key' \ | |
# user accounts + passwords | |
&& useradd --home-dir /home/vagrant --create-home --shell /bin/bash vagrant \ | |
&& mkdir /home/vagrant/.ssh \ | |
&& echo "$ssh_key" > /home/vagrant/.ssh/authorized_keys \ | |
&& echo 'vagrant:vagrant' | chpasswd \ | |
&& echo 'root:vagrant' | chpasswd \ | |
# vagrant wants sudo without password | |
&& echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/vagrant \ | |
# safe enough permissions so sudo/ssh don't complain | |
&& chmod 0440 /etc/sudoers.d/vagrant \ | |
&& chmod 0700 /home/vagrant/.ssh \ | |
&& chmod 0600 /home/vagrant/.ssh/authorized_keys \ | |
&& chown -R vagrant:vagrant /home/vagrant | |
EXPOSE 22 | |
CMD ["/usr/sbin/sshd", "-D", "-oUseDNS=no"] | |
# puppet is optional | |
RUN apt-get update \ | |
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ | |
puppet \ | |
&& rm -rf /var/lib/apt/lists/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure("2") do |config| | |
config.vm.provider "docker" do |d, override| | |
# https://www.vagrantup.com/docs/docker/configuration.html | |
d.build_dir = "." | |
d.force_host_vm = false # since we have Docker for Mac nowadays | |
d.has_ssh = true | |
# https://github.com/mitchellh/vagrant/issues/7651 | |
override.ssh.host = "127.0.0.1" | |
override.ssh.port = 2222 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment