Command To Install Docker

Command To Install Docker

Reading time1 min
#Docker#Containers#DevOps#Linux#Installation#CLI

Mastering the Command to Install Docker: Streamlined Linux Setup

Rolling out containers across new environments should be predictable, fast, and reproducible. Yet, too often, Docker installation devolves into dependency tangles and manual configuration. Production environments demand something cleaner.


Single-Command Docker Installation on Linux

Canonical, version-agnostic Docker installation:

curl -fsSL https://get.docker.com | sh

This one-liner—endorsed by Docker Inc.—handles repository setup, GPG key registration, dependency resolution, and package installation. It's supported on most mainstream x86_64/AArch64 Linux distributions, including Debian, Ubuntu, RHEL/CentOS (7+), Fedora, and derivatives.

What happens under the hood:

  • Auto-detects OS and distribution version.
  • Adds the appropriate Docker repository and GPG keys.
  • Installs the current stable release of Docker Engine, CLI, and containerd.
  • No interactive prompts; scripts run non-interactively.

Caveat: If you require a specific Docker Engine version (instead of latest stable), revert to manual installation—pin version via your package manager (apt, yum, or dnf).


Workflow Example: Real Setup

Deploying Docker on a new Ubuntu 22.04 LTS node:

sudo apt update
sudo apt install -y curl
curl -fsSL https://get.docker.com | sh

Practical gotcha: On locked-down environments, outbound HTTP/HTTPS may be blocked—confirm egress before automation rolls out.

User group adjustment (post-install):
Allow non-root Docker CLI access:

sudo usermod -aG docker $USER
newgrp docker

Logging out and back in accomplishes the same result. In ephemeral CI runners, this isn't practical—continue using sudo as required.


Verification and Sanity Checks

Minimal verification:

docker --version

Expected output (June 2024 stable, for reference):

Docker version 24.0.5, build f3504c2

Container runtime check:

docker run --rm hello-world

Success output should include status similar to:

...
Hello from Docker!
This message shows that your installation appears to be working correctly.
...

Non-obvious tip: For cold-start hosts lacking /sbin or /usr/local/sbin in the default PATH, binary access issues can occur. Adjust PATH or re-login to refresh environment variables.


Not on Linux? Alternatives

OSInstall MethodNote
macOSDocker Desktop for MacIncludes GUI, Kubernetes, and update manager
WindowsDocker Desktop for WindowsWSL2 or Hyper-V required, not headless

Note: Headless Docker Engine on Windows Server Core requires a separate process using PowerShell and Windows features; consult Docker documentation.


Troubleshooting: Known Issues

  • curl Not Installed:

    bash: curl: command not found
    

    Solution:

    sudo apt install curl           # Debian/Ubuntu
    sudo yum install curl           # RHEL/CentOS
    
  • Permission Denied on /var/run/docker.sock:

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

    Add user to docker group as above; verify with id $USER.

  • Proxy/Firewall blocks script download:
    Manual installation required—mirror the script internally.

Side note: Some hardened enterprise images remove sudo or restrict usermod. Direct root login or changes in workflow may be needed, e.g., via Ansible or remote root SSH.


Final Remarks

For most CI/CD and developer scenarios, curl -fsSL https://get.docker.com | sh is sufficient, stable, and simplifies otherwise error-prone base layer setup. It’s not perfect—enterprise-hardening (no auto-updates, custom daemon.json security configs) demands further work.

Where reproducibility and speed outweigh granular control, the official install script tilts the balance. For prod hardening, baseline from this method, then tighten as needed.

For additional customization—from daemon socket locations to experimental CLI features—post-install is the domain of your config management tool.


Questions about container runtime differences, rootless Docker, or production hardening? Leave specifics, and I’ll address them in a follow-up post.