LinuxΒ·

Installing Docker on Ubuntu Server

Installing Docker Engine on Ubuntu Server
AΓ§Δ±klama

πŸ‘‡πŸ» Prerequisites

Before installing Docker on Ubuntu Server, ensure you meet the following requirements:

Minimum system requirements:

  • 64-bit Ubuntu Server (20.04 LTS or higher)
  • Minimum 4GB RAM
  • A user with sudo privileges
  • Active internet connection

Ensure your system is up to date:

sudo apt update
sudo apt upgrade -y

πŸƒ Installation Steps

  1. Add Docker's GPG key:
sudo apt install ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  1. Add Docker repository:
echo "deb [arch=$(dpkg --print-architecture) 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
  1. Update system packages:
sudo apt update
  1. Install Docker Engine:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Check Docker service status:
sudo systemctl status docker

πŸͺ„ Tips

  1. Using Docker Without Sudo Add your user to the docker group to run Docker commands without sudo:
sudo usermod -aG docker $USER

Log out and back in for the changes to take effect.

  1. Automatic Start on System Boot
sudo systemctl enable docker
  1. Docker Hub Rate Limits
  • Rate limiting applies to free Docker Hub accounts
  • For production environments, it's recommended to authenticate:
docker login
  1. Docker Images Cleanup Clean unused images to save disk space
docker system prune -a

πŸ‘¨β€πŸ’» Troubleshooting

  1. Docker Daemon Startup Issue If Docker daemon fails to start:
sudo systemctl daemon-reload
sudo systemctl restart docker
  1. Permission Denied Error If you get socket access error:
  • Ensure you're added to the docker group
  • Restart the system or run:
newgrp docker
  1. Network Issues If containers can't access the internet
# Check DNS settings
cat /etc/docker/daemon.json

Update DNS settings if needed:

sudo nano /etc/docker/daemon.json
{
  "dns": ["8.8.8.8", "8.8.4.4"]
}
  1. Disk Space Issues Docker stores data in /var/lib/docker. If you're experiencing disk space issues:
# Clean unused resources
docker system prune -a

# Check disk usage
docker system df

πŸ€” Security Recommendations

  1. Rootless Docker
  • Consider rootless mode for enhanced security
  • Check Docker's official documentation for detailed information
  1. Container Security
  • Always use trusted images
  • Avoid running containers in privileged mode
  • Set resource limits
  1. Network Security
  • Don't expose unnecessary ports
  • Restrict inter-container communication
  • Isolate Docker networks

🏁 Conclusion

In this guide, we covered the installation of Docker on Ubuntu Server, basic configuration steps, and solutions to common issues. We recommend following the above suggestions to use Docker efficiently and securely. Feel free to leave comments or feedback in the section below.