—.
π What is Docker?
It’s a container-based virtualization platform that provides a “build once, run anywhere” environment.
β
Runs faster and is lighter than traditional virtualization (VMs)
Simplifies application deployment and management
Ensures consistency across dev/test/production environments
—.
βοΈ Preparation before installation
- Check Ubuntu version (20.04 LTS or higher recommended)
lsb_release -a ```bash lsb_release -a 
- **Update the repository
sudo apt update && sudo apt upgrade -y ```bash
—]
π Step-by-step guide to installing Docker
1οΈβ£ Uninstall the previous Docker (optional)
sudo apt remove docker docker-engine docker.io containerd runc
2οΈβ£ Install prerequisite packages
sudo apt install -y ca-certificates curl gnupg lsb-release
3οΈβ£ Add the Docker official GPG key π
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
4οΈβ£ Set up a repository π¦
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5οΈβ£ Install the Docker engine
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
6οΈβ£ Verify the installation π .
sudo docker run hello-world
β Print on success
Hello from Docker!
This message shows your installation appears to be working correctly.
—]
β‘ Set user permissions (prevent sudo every time)
sudo usermod -aG docker $USER # add current user docker group
newgrp docker # Apply group settings immediately
βοΈ Apply without reboot: `newgrp docker
or rerun terminal
—]
π οΈ Additional useful settings
π Enable Docker autostart
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
```bash
#### π Control the Docker service
```bash
sudo systemctl start docker # Start
sudo systemctl stop docker # Stop
sudo systemctl restart docker # restart
```bash
#### βΉοΈ Check the version
```bash
docker --version # Docker version
docker compose version # Compose plugin version
—]
π§ͺ Test the installation: Run the Nginx container
docker run -d -p 8080:80 --name my-nginx nginx
- access
http://localhost:8080
in your browser - see “Welcome to nginx!” 3. stop and delete the container
- stop and delete the container:
docker stop my-nginx && docker rm my-nginx
—]
β Troubleshooting tips.
- “Permission denied”** error:
sudo chmod 666 /var/run/docker.sock # Temporary workaround (security alert!)
β Permanent workaround: re-login user or run
newgrp docker
- GPG key error: re-run
sudo apt update
after adding repository
—]
β Closing checklist.
- [ ] Successfully run
hello-world
container - [ ] User permission groups added successfully
- [ ] Nginx test container working properly
- [ ] Docker service auto-start enabled
> π’ **Feel the power of Docker!
> Set up development environment in 5 minutes β Deploy production in 1 second π
> bash > # Example: Running a MySQL container. > docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw --name my-db mysql:8.0 >
Your container journey has begun π’. Build an efficient development environment with Ubuntu + Docker combination!