Installing and Configuring Docker on Ubuntu
Docker is a platform for developing, shipping, and running applications inside lightweight, portable containers. This guide will show you how to install Docker on Ubuntu, configure it, and run your first container.
← BackStep 1: Update Package Index
Before installing Docker, it’s essential to update the package index on your Ubuntu system:
sudo apt update
Step 2: Install Required Packages
To allow Ubuntu to retrieve Docker packages from HTTPS sources, install these prerequisite packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Step 3: Add Docker’s Official GPG Key
Docker packages are signed with a GPG key. Add Docker’s official GPG key to your system:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 4: Add Docker APT Repository
Add Docker's APT repository to your list of sources to ensure you install the latest stable version of Docker:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 5: Install Docker Engine
Now that you have the Docker repository set up, you can install Docker:
sudo apt update
sudo apt install docker-ce
Step 6: Verify Docker Installation
To verify that Docker is installed and running, use the following command:
sudo docker --version
You should see the installed version of Docker.
Step 7: Start and Enable Docker Service
Ensure that Docker starts automatically when your system boots:
sudo systemctl enable docker
Start Docker if it’s not already running:
sudo systemctl start docker
Step 8: Run Your First Docker Container
To ensure Docker is working properly, try running a simple test container. For example, run a "Hello World" container:
sudo docker run hello-world
If Docker is installed correctly, you’ll see a message indicating that Docker is running successfully.
Step 9: Manage Docker as a Non-root User (Optional)
To manage Docker without needing to prefix commands with sudo
, you can add your user to the Docker group:
sudo usermod -aG docker $USER
Log out and back in to apply the group changes. Then, you can use Docker commands without sudo
.
Step 10: Test Docker Without Sudo
Once you have logged back in, test that you can run Docker commands without sudo
:
docker run hello-world
Conclusion
Congratulations! You’ve successfully installed and configured Docker on Ubuntu. You can now start using Docker to create containers, manage services, and deploy applications. If you need more help, the official Docker documentation offers comprehensive guides and tutorials.
← Back