Command To Install Docker On Ubuntu

Command To Install Docker On Ubuntu

Reading time1 min
#Docker#Ubuntu#Containers#Snap#Sysadmin

Command To Install Docker On Ubuntu

Situation: Urgent patch deployment deadline, CI/CD pipelines failing, and you realize the base Ubuntu node hasn’t got Docker. Traditional install guides recommend five or six steps just to get started. Why complicate a common infrastructure task?

The Docker snap package for Ubuntu offers a streamlined alternative: a single command for installation, minimal configuration, and isolated dependencies—backed directly by Canonical. Particularly since Ubuntu 20.04 LTS, the snap-supported Docker has been viable for both workstations and staging servers.


The Core Command

sudo snap install docker

This fetches the latest stable container engine, configures the required systemd unit, and establishes a confined runtime environment. No need to manually add Docker’s APT repository, manage GPG keys, or check for system package conflicts.


Process Details and Aftercare

Post-installation tasks are not optional if you want standard usability:

# Add your user to the docker group to avoid sudo on every command
sudo usermod -aG docker $USER

# For group changes to take effect:
newgrp docker

# Check that Docker Engine responds as expected
docker run hello-world

Tip: If docker run hello-world fails with:

docker: Got permission denied while trying to connect to the Docker daemon socket

Double-check group membership, and that your terminal session is new.


Snap Package: Pros and Limitations

AspectSnap Install (snap install docker)Traditional Install (apt/docker repo)
Setup SpeedSingle-command, automatic configMultiple steps, keys, repos
UpdatesAutomatic, handled by snapdManual via apt/OS updater
Daemon Path/var/snap/docker/common/var-lib-docker/var/lib/docker
System IntegrationSlightly isolated from hostFully native integration
Version ControlFollows snap track/channelsComplete version pinning/editing
  • Data path difference: Snap installs relocate Docker’s default storage directory. Be explicit when mounting host directories, especially for volume persistence in Compose or K8s.
  • Socket path and permissions: The default Unix socket remains /var/run/docker.sock, but snap’s confinement model may affect integrations with third-party tools.

Real-World Docker Usage Post-Snap

After installation, launching a disposable Alpine container remains identical:

docker run --rm -it alpine:3.18 sh

For automated environments (Jenkins runners, ephemeral GitHub Actions VMs), one-liner installation shortens provisioning step time, albeit with some trade-off in version control granularity.


Known Issues & Recommendations

  • Snap apparmor restrictions can block advanced network features (MacVLAN, overlay). For production-grade or network-intense setups, consider official Docker APT packages for full host integration.
  • Not all third-party Docker manage tools (especially those interfacing beyond the docker CLI, like some monitoring agents) play well with snap’s file hierarchy.
  • If you require a very specific Docker daemon version, the repo method with explicit version pinning is preferred.

“Why Not Just Use APT?”

APT installation requires:

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

This approach offers more control and typically better aligns with fleet-wide configuration management tools (e.g., Ansible, SaltStack). However, it's slower for ad hoc provisioning and increases initial cognitive overload for newcomers.


Summary

For most modern Ubuntu environments (20.04 LTS+), sudo snap install docker is the fastest path to a functional Docker engine, suited for dev/test, throwaway labs, and cloud instances where rapid iteration matters.

Note: Always assess the project’s operational requirements before standardizing on snap, especially if you anticipate advanced Docker daemon tuning, plugin use, or integration with legacy orchestration tooling. Sometimes, simplicity wins—other times, control is paramount.


Container deployment shouldn’t be a bottleneck. Deploy fast, then iterate.