Docker Setup Guide on Ubuntu Server
This guide will help you set up Docker on your Ubuntu Server for the first time. We'll cover installing Docker, running your first container, and basic usage.
Prerequisites
- Ubuntu Server: Ubuntu 18.04 LTS or newer is recommended.
- User Privileges: A user account with
sudoprivileges.
Step 1: Update Your System
Begin by updating your package list and upgrading existing packages:
Step 2: Install Required Packages
Install packages that allow apt to use repositories over HTTPS:
Step 3: Add Docker’s Official GPG Key
Create a directory for the keyrings:
Add Docker's official GPG key:
Set appropriate permissions:
Step 4: Set Up the Docker Repository
Add the Docker APT repository to your system:
Step 5: Install Docker Engine
Update the package database:
Install Docker Engine and related components:
Step 6: Verify Docker Installation
Run the hello-world image to verify that Docker is installed correctly:
You should see a message that says "Hello from Docker!"
Step 7: Manage Docker as a Non-Root User (Optional)
To run Docker commands without sudo, add your user to the docker group:
Log out and log back in to apply the group membership.
Test Docker without sudo:
Step 8: Enable Docker to Start on Boot
Ensure Docker starts automatically when the system boots:
Step 9: Basic Docker Commands
List Docker Images
List Running Containers
List All Containers (Including Stopped Ones)
Pull an Image from Docker Hub
Run a Container
This command runs an Ubuntu container and provides an interactive shell.
Stop a Running Container
First, find the container ID using docker ps, then stop it:
Conclusion
You've successfully installed Docker on your Ubuntu Server and run your first container. You can now explore Docker's features further by creating your own images, managing containers, and integrating Docker into your workflows.
No Comments