-
-
Save xZero707/708872ada769e5f5ca0bd0cabce546b2 to your computer and use it in GitHub Desktop.
Alpine Docker Dev Host Setup
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
#/bin/sh | |
# | |
# The following assumes a default Alpine install using the standard Alpine image | |
# | |
# Note: for VirtualBox, you could be tempted to use the `alpine-virt` image, | |
# however it uses the `virtgrsec` kernel, for which there is no guest additions support | |
# if required, SSH root password access can be enabled by adding `PermitRootLogin yes` | |
# to `/etc/ssh/sshd_config` | |
# VirtualBox networking: | |
# Network > Adapter 1 > Host-only Adapter: this will allow communication between host and guest | |
# Network > Adapter 2 > NAT: this will let the guest connect to the internet | |
# Note: the order of the adapters is important! | |
# | |
# Make sure `/etc/network/interfaces` has the following (this makes sure both interface are up with static IPs): | |
# | |
# auto eth1 | |
# iface eth1 inet static | |
# address 10.0.3.15 | |
# netmask 255.255.255.0 | |
# gateway 10.0.3.2 | |
# | |
# auto eth0 | |
# iface eth0 inet static | |
# address 192.168.56.101 | |
# netmask 255.255.255.0 | |
# | |
# DNS, edit `/etc/resolv.conf` to have the following, | |
# note that the first nameserver depends on having the DNS docker container running, see below: | |
# | |
# nameserver 172.17.0.1 | |
# nameserver 8.8.8.8 | |
# nameserver 8.8.4.4 | |
# use main and community and repos on `dl-2` mirror | |
# - edge repos added for Docker 1.12 | |
# (default 1.11 has grsec issue: https://github.com/docker/docker/pull/22506) | |
echo -e "http://dl-2.alpinelinux.org/alpine/v3.4/main\nhttp://dl-2.alpinelinux.org/alpine/v3.4/community\nhttp://dl-2.alpinelinux.org/alpine/edge/main\nhttp://dl-2.alpinelinux.org/alpine/edge/community\n" > /etc/apk/repositories | |
# detect VirtualBox | |
dmidecode -s system-product-name | |
if [ $? == 'VirtualBox' ] ;then | |
IS_VIRTUALBOX="Y" | |
else | |
IS_VIRTUALBOX="N" | |
fi | |
# add edge/testing for VirtualBox grsec additions | |
if [ "$IS_VIRTUALBOX" == "Y" ]; then | |
echo -e "http://dl-2.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories | |
fi | |
apk update | |
apk upgrade | |
# add `curl`, `docker`, `drill` (`dig` equivalent), `python` (2.7), `pip` | |
apk add --no-cache curl docker drill python py-pip | |
# add VirtualBox guest additions | |
if [ "$IS_VIRTUALBOX" == "Y" ]; then | |
apk add --no-cache virtualbox-additions-grsec virtualbox-guest-modules-grsec virtualbox-guest-additions | |
echo -e "vboxpci\nvboxdrv\nvboxnetflt" >> /etc/modules | |
rc-update add virtualbox-guest-additions boot | |
service virtualbox-guest-additions start | |
fi | |
# autostart & start `docker` daemon | |
rc-update add docker boot | |
# add `docker-machine` | |
curl -L "https://github.com/docker/machine/releases/download/v0.8.2/docker-machine-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-machine | |
chmod +x /usr/local/bin/docker-machine | |
# add `docker-compose` (official curl method results in non-executable `docker-compose`) | |
pip install docker-composedocker run -d --name=dnsdock -e DNSDOCK_NAME=dnsdock -e DNSDOCK_IMAGE=devtools -p 172.17.0.1:53:53/udp -v /var/run/docker.sock:/var/run/docker.sock aacebedo/dnsdock:latest-amd64 --domain=vm | |
# create base data directory | |
mkdir /data | |
# if in VirtualBox, and assuming a shared folder named "data", automatically mount it, | |
# this fails using fstab as vbox guest drivers aren't loaded in time | |
if [ "$IS_VIRTUALBOX" == "Y" ]; then | |
echo -e "#!/bin/sh\nmount -t vboxsf data /data" > /etc/local.d/vboxsf.start | |
chmod +x /etc/local.d/vboxsf.start | |
rc-update add local default | |
fi | |
# start local DNS instance (`dnsdock`) in Docker for dev | |
docker run -d --name=dnsdock --restart=always -e DNSDOCK_NAME=dnsdock -e DNSDOCK_IMAGE=devtools -p 172.17.0.1:53:53/udp -v /var/run/docker.sock:/var/run/docker.sock aacebedo/dnsdock:latest-amd64 --domain=vm | |
# reboot to apply all changes | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment