Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Last active February 9, 2021 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npodonnell/98d8088bdbbce5b0fa4849948b924469 to your computer and use it in GitHub Desktop.
Save npodonnell/98d8088bdbbce5b0fa4849948b924469 to your computer and use it in GitHub Desktop.
Docker Ubuntu Install

Docker Ubuntu Setup

N. P. O'Donnell, 2020

Preparing a Ubuntu host for docker. Ensures an nginx image can run on port 80.

Install docker:

sudo apt-get update
sudo apt-get install docker.io

Add yourself to docker group and refresh shell:

sudo usermod -a -G docker $USER
su - $USER

Check if the hello-world container runs:

docker run hello-world

Disable/remove any existing nginx:

sudo systemctl stop nginx
sudo systemctl disable nginx
sudo apt-get remove nginx nginx-common

Ensure port 80 is free:

sudo lsof -P -i :80 | grep LISTEN

Start a demonized nginx which will auto start on boot:

docker run -d --restart unless-stopped --name docker-nginx -p 80:80 nginx

Make sure you can browse to the nginx server:

curl -I localhost

Reboot:

sudo reboot now

When the host has rebooted, check that the nginx container has come back up:

docker ps            # Should see the nginx container
curl -I localhost    # Should get a 200

Cleanup:

for patt in nginx hello-world; do \
  for cid in $(docker ps -a | grep $patt | awk '{print $1}'); do \
    docker stop $cid; \
    docker rm $cid; \
  done; \
  docker rmi $patt; \
done

SSH Setup for docker-compose deployments

  1. Add an entry in your ~/.ssh/authorized_keys for the machine you'll be deploying from. Password auth won't work.
  2. Add these lines to the sshd config file (/etc/ssh/sshd_config on Ubuntu):
AllowTcpForwarding yes
MaxSessions 1000 # possibly more

Restart sshd:

sudo systemctl restart sshd

Before logging out, ensure you can still SSH to the host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment