Docker has become a fundamental tool in modern DevOps workflows โ€” from local development to CI/CD pipelines and production deployments. If you’re working with Ubuntu and want to set up Docker properly, hereโ€™s a clear, step-by-step guide to get you up and running with best practices in mind.


โœ… Why Docker in DevOps?

Docker allows teams to package applications and their dependencies into containers โ€” lightweight, portable units that can run anywhere. For DevOps, this means:

  • Consistent environments across dev, test & production

  • Simplified deployment and rollback

  • Faster onboarding for new developers

  • Seamless integration with CI/CD tools (e.g. GitLab CI, GitHub Actions, Jenkins)


๐Ÿง Installing Docker on Ubuntu

Hereโ€™s how to install the official Docker Engine on Ubuntu (20.04 or newer):


1. Update and install dependencies:

sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release


2. Add Dockerโ€™s 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


3. Set up the stable Docker 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


4. Install Docker Engine & CLI tools:

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin


5. Test your Docker installation:

sudo docker run hello-world

You should see a success message from the Docker daemon.


๐Ÿ”’ Run Docker as non-root (optional but recommended)

By default, Docker requires sudo. To avoid this:

sudo usermod -aG docker $USER
newgrp docker

This adds your user to the docker group so you can run Docker without typing sudo.

This is common in development environments. In production, always run Docker securely and restrict access via group permissions and firewalls.


๐Ÿ› ๏ธ DevOps Tip: Use Docker with CI/CD

Once Docker is installed, integrate it into your pipelines:

  • GitLab CI: Use the official Docker-in-Docker (dind) image

  • GitHub Actions: Use docker/build-push-action for multi-arch builds

  • Jenkins: Use the Docker plugin or build agents inside containers


๐Ÿš€ Final Thoughts

Docker on Ubuntu is quick to install but powerful in its impact. Whether you’re building microservices, automating deployments, or preparing for Kubernetes, Docker is a foundational DevOps skill โ€” and this setup gets you started the right way.