Last active
May 6, 2020 14:10
-
-
Save tygern/514b5d5ee57f976fa890e01fcb9caf06 to your computer and use it in GitHub Desktop.
Docker machine on Digital Ocean
This file contains hidden or 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
# Install docker-machine | |
curl -L https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-$(uname -s)-$(uname -m) > ~/bin/docker-machine | |
chmod +x ~/bin/docker-machine | |
# Install doctl | |
curl -sL https://github.com/digitalocean/doctl/releases/download/v1.41.0/doctl-1.41.0-darwin-amd64.tar.gz | tar -xzv | |
chmod +x doctl | |
mv doctl ~/bin | |
# Create docker machine | |
docker-machine create --driver digitalocean --digitalocean-access-token $DO_PERSONAL_TOKEN --digitalocean-size s-4vcpu-8gb docker-sandbox | |
# Create firewall | |
export DROPLET_ID=$(docker-machine inspect docker-sandbox | jq ".Driver.DropletID") | |
doctl -t $DO_PERSONAL_TOKEN compute firewall create --droplet-ids=$DROPLET_ID \ | |
--inbound-rules "protocol:tcp,ports:22,address:0.0.0.0/0,address:::/0 protocol:tcp,ports:2376,address:0.0.0.0/0,address:::/0" \ | |
--outbound-rules "protocol:icmp,address:0.0.0.0/0,address:::/0 protocol:tcp,ports:all,address:0.0.0.0/0,address:::/0 protocol:udp,ports:all,address:0.0.0.0/0,address:::/0" \ | |
--name=sandbox-firewall | |
# Start containers | |
eval $(docker-machine env docker-sandbox) | |
docker-machine start docker-sandbox | |
docker-compose up redis sql-server-db rabbitmq | |
# Start ssh tunnel (example) | |
docker-machine ssh docker-sandbox -N -L 1433:localhost:1433 -L 6379:localhost:6379 -L 5672:localhost:5672 | |
# Stop droplet and tear down firewall | |
docker-machine stop docker-sandbox | |
export FIREWALL_ID=$(doctl -t $DO_PERSONAL_TOKEN compute firewall list-by-droplet $DROPLET_ID --format ID --no-header) | |
doctl -t $DO_PERSONAL_TOKEN compute firewall delete $FIREWALL_ID -f | |
# Remove droplet | |
docker-machine rm -f docker-sandbox |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SSH tunnel: