Creating a Docker Host on Ubuntu

#docker#container

Chris Brocklesby

Creating a Docker Host on Ubuntu for hosting various containers.

Create a Swap File (If needed)

sudo fallocate -l 1G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Install Docker

snap install docker         # Via Snap
apt  install docker.io      # Install Docker
apt  install podman-docker  # Install Podman

Create User and add to Docker Group

sudo adduser docker
sudo usermod -aG docker docker
su - docker
mkdir ~/.ssh
nano ~/.ssh/authorized_keys  # Add your public key

Configure Docker Context Locally (Opional if needed)

docker context create docker-host --docker "host=ssh://docker@<ip_address>"
docker context use docker-host
# OR use the DOCKER_CONTEXT env var
DOCKER_CONTEXT=docker-host docker ps

# Troubleshooting (If using VScode and Docker extension) Sometimes the ssh connection has issues due to the SSH identity. Also check the ssh config file.
ssh add

Chris BrocklesbyHead of Technology, Software Engineer, Technology lover and Family man based in Mapua, Tasman in New Zealand (Originally from Swansea UK).