There are two versions of Docker – Docker CE (Community Edition) and Docker EE (Enterprise Edition). If you have a small-scale project, or you’re just learning, you’ll want to use Docker CE.
In this gist, we will cover how to install Docker on Ubuntu 18.04.
- Ubuntu 18.04 64-bit operating system
- A user account with sudo privileges
- Command line / terminal (CTRL-ALT-T or Applications menu > Accessories > Terminal)
- Docker software repositories (optional)
Step 1: Update Software Repositories As usual, it’s a good idea to update the local database of software to make sure you’ve got access to the latest revisions.
Therefore, open a terminal window and type:
sudo apt-get update
Allow the operation to complete.
Step 2: Uninstall Old Versions of Docker Next, it’s recommended to uninstall any old Docker software before proceeding.
Use the command:
sudo apt-get remove docker docker-engine docker.io
Step 3: Install Docker To install Docker on Ubuntu, in the terminal window enter the command:
sudo apt install docker.io
Step 4: Start and Automate Docker The Docker service needs to be setup to run at startup. To do so, type in each command followed by enter:
sudo systemctl start docker
sudo systemctl enable docker
Step 5: Manage Docker as a non-root user If you don’t want to preface the docker command with sudo, create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.
To create the docker group and add your user:
- Create the docker group.
sudo groupadd docker
- Add your user to the docker group.
sudo usermod -aG docker $USER
- Log out and log back in so that your group membership is re-evaluated.
If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect. On a desktop Linux environment such as X Windows, log out of your session completely and then log back in. On Linux, you can also run the following command to activate the changes to groups:
newgrp docker
- Verify that you can run docker commands without sudo.
docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.