How-To : Build a Docker Host Using Ubuntu Server
The easiest way to get an installation of Docker up and running is to run it on an virtualiased Ubuntu Server build in VirtualBox
VirtualBox
For this demo I will be using Oracle's VirtualBox system to host the Ubuntu server as a Docker host. It's free and very easy to use.
Simply install the latest version of Ubuntu server with bog standard defaults, but be sure to install two network interfaces into the VirtualBox host.
- Interface 1 - NAT routable to the outside world - So you can download updates and packages plus Docker images.
- Interface 2 - Host-Only - While not mandatory it can be very useful for internal testing to have an interface back to your desktop/laptop box. Class C usually something like 192.168.56.0 network.
Ubuntu Server
Installing the Ubuntu Server just install with defaults but you may wish to hardcode the host-only Class C address to 192.168.56.111 for example.
- Use /etc/hosts has the hostname matched to the host-only IP addresss
- Example netplan config YAML file is shown below, note the fixed IP address.
1# This is the network config written by 'subiquity'
2network:
3 ethernets:
4 enp0s3:
5 dhcp4: true
6 enp0s8:
7 addresses:
8 - 192.168.56.111/24
9 nameservers: {}
10 version: 2
Ensure you do a full update from the source repos and reboot.
1apt-get update -y
2apt-get upgrade -y
3apt autoremove -y
4reboot
Install the Docker CE from the official Docker Repo
First we remove the Docker that might already be installed, update the local packages and then install the pre-requisite packages we'll need.
1sudo apt-get remove docker docker-engine docker.io
2sudo apt-get update
3sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
Next we get the GPG key used to verify te Docker repo package can be trusted.
1curl -fsSLk https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Next we need to register the Docker repo locally so we can get the packages down, there's two ways to do it. Either do it with a fixed reference but note this is version specific, I would only do this if you have to.
1sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
The preferred option is to let the O/S find the right version.
1sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
If you find that you get certificate errors like "Certificate verification failed: The certificate is NOT trusted.", especially if you're behind a proxy, then extract the proxy certificates ( do this using a browser like Firefox or Chrome ) and save them to "/usr/local/share/ca-certificates" then run "sudo update-ca-certificates".
Now we're ready to install Docker from the official repo. This is a good time to add your user to the docker group so you can use docker commands without having to keep using sudo. You use sudo for all your root commands right, you'd never login with root?!
1sudo apt-get update
2sudo apt-get install docker-ce
3sudo groupadd docker
4sudo usermod -aG docker $USER
Assuming it all went OK, just check the service came up:
1sudo systemctl status docker
Finally test Docker is working, log out and log back in to make sure the privs take and then issue this:
1docker run --rm hello-world
Using Docker with a Proxy to get Images
If you're behind a proxy then do the following to get docker to work with a proxy.
1sudo mkdir /etc/systemd/system/docker.service.d
2sudo vi /etc/systemd/system/docker.service.d/http-proxy.conf
Add this to the open file:
1[Service]
2Environment="HTTP_PROXY=http://172.26.2.10:9480"
3Environment="HTTPS_PROXY=http://172.26.2.10:9480"
Then restart Docker.
1sudo systemctl daemon-reload
2sudo sysyemctl stop docker
3sudo sysyemctl start docker