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
- Add an entry in your
~/.ssh/authorized_keys
for the machine you'll be deploying from. Password auth won't work. - 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.