• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Docker | Install Docker Engine (Ubuntu)
  1. Notes
  2. Uninstall existing installation
  3. Install Docker Engine
  4. Check installed packages
  5. Check Docker Version
  6. Print Docker Information
  7. Verify that Docker Engine is installed correctly
  8. Manage Docker service
  9. Important Docker files/folders

  1. Notes
    See this page for more details on how to install Docker Engine for Ubuntu: https://docs.docker.com/install/linux/docker-ce/ubuntu/
  2. Uninstall existing installation
    • Check if Docker was already installed:
      $ dpkg -l | grep docker
      docker-ce/bionic,now 5:19.03.12~3-0~ubuntu-bionic amd64 [installed]
      docker-ce-cli/bionic,now 5:19.03.12~3-0~ubuntu-bionic amd64 [installed]
      $ dpkg -l | grep containerd
      containerd.io/bionic,now 1.2.13-2 amd64 [installed]
      You might have Docker installed with different package names: docker, docker.io , or docker-engine

    • To uninstall an existing installation of Docker:
      $ for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
      [Optional] Delete Docker data folder:
      $ sudo rm -rf /var/lib/docker
      [Optional] Delete Docker custom configuration folder:
      $ sudo rm -rf /etc/docker/
      [Optional] Delete docker command configuration folder:
      $ rm -rf ~/.docker/
  3. Install Docker Engine
    • Update the apt package index:
      $ sudo apt-get update
    • [Optional] Install packages to allow apt to use a repository over HTTPS:
      $ sudo apt-get install \
          apt-transport-https \
          ca-certificates \
          curl \
          gnupg-agent \
          software-properties-common
    • Add Docker’s official GPG key:
      $ sudo apt-get install ca-certificates curl
      $ sudo install -m 0755 -d /etc/apt/keyrings
      $ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
      $ sudo chmod a+r /etc/apt/keyrings/docker.asc
    • Set up the repository:
      $ echo \
        "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
        $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
        sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    • Update the apt package index:
      $ sudo apt-get update
    • Install the latest version of Docker Engine and containerd:
      $ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  4. Check installed packages
    • Check Docker daemon (dockerd server):
      $ ps -ef | grep docker
      root    12269    /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    • Check Docker service:
      $ sudo systemctl status docker
      ● docker.service - Docker Application Container Engine
           Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
           Active: active (running) since Tue 2024-04-29 06:59:47 EDT; 19min ago
      TriggeredBy: ● docker.socket
             Docs: https://docs.docker.com
         Main PID: 9987 (dockerd)
            Tasks: 13
           Memory: 21.9M
              CPU: 418ms
           CGroup: /system.slice/docker.service
                   └─9987 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    • Check containerd Service:
      $ sudo systemctl status containerd
      ● containerd.service - containerd container runtime
           Loaded: loaded (/lib/systemd/system/containerd.service; enabled; vendor preset: enabled)
           Active: active (running) since Tue 2024-04-29 06:59:46 EDT; 19min ago
             Docs: https://containerd.io
         Main PID: 9834 (containerd)
            Tasks: 12
           Memory: 13.7M
              CPU: 886ms
           CGroup: /system.slice/containerd.service
                   └─9834 /usr/bin/containerd
  5. Check Docker Version
    $ sudo docker version
    Client: Docker Engine - Community
     Version:           28.1.1
     API version:       1.49
     Go version:        go1.23.8
     Git commit:        4eba377
     Built:             Fri Apr 18 09:52:10 2025
     OS/Arch:           linux/amd64
     Context:           default
    Server: Docker Engine - Community
     Engine:
      Version:          28.1.1
      API version:      1.49 (minimum version 1.24)
      Go version:       go1.23.8
      Git commit:       01f442b
      Built:            Fri Apr 18 09:52:10 2025
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.7.27
      GitCommit:        05044ec0a9a75232cad458027ca83437aae3f4da
     runc:
      Version:          1.2.5
      GitCommit:        v1.2.5-0-g59923ef
     docker-init:
      Version:          0.19.0
      GitCommit:        de40ad0
    Note the versions of the client and the server.
    Also note the version of the API version supported by the server (and the minimum compatible version).
  6. Print Docker Information
    $ sudo docker system info
    Client: Docker Engine - Community
     Version:    28.1.1
     Context:    default
     Debug Mode: false
     Plugins:
      buildx: Docker Buildx (Docker Inc.)
        Version:  v0.23.0
        Path:     /usr/libexec/docker/cli-plugins/docker-buildx
      compose: Docker Compose (Docker Inc.)
        Version:  v2.35.1
        Path:     /usr/libexec/docker/cli-plugins/docker-compose
    Server:
     Containers: 0
      Running: 0
      Paused: 0
      Stopped: 0
     Images: 0
     Server Version: 28.1.1
     Storage Driver: overlay2
      Backing Filesystem: extfs
      Supports d_type: true
      Using metacopy: false
      Native Overlay Diff: true
      userxattr: false
     Logging Driver: json-file
     Cgroup Driver: systemd
     Cgroup Version: 2
     Plugins:
      Volume: local
      Network: bridge host ipvlan macvlan null overlay
      Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
     Swarm: inactive
     Runtimes: io.containerd.runc.v2 runc
     Default Runtime: runc
     Init Binary: docker-init
     containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
     runc version: v1.2.5-0-g59923ef
     init version: de40ad0
     Security Options:
      apparmor
      seccomp
       Profile: builtin
      cgroupns
     ID: 6bf6b3bf-947e-4048-889a-8391e7164a8e
     Docker Root Dir: /var/lib/docker
     Debug Mode: false
     Experimental: false
     Insecure Registries:
      ::1/128
      127.0.0.0/8
     Live Restore Enabled: false
    The command might show warnings with your Docker installation if any.

    The command docker system provides more options:
    $ docker system --help
    Usage:  docker system COMMAND
    
    Manage Docker
    
    Commands:
      df          Show docker disk usage
      events      Get real time events from the server
      info        Display system-wide information
      prune       Remove unused dat
    You can print the Docker disk usage:
    $ docker system df
    TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
    Images          24        9         2.534GB   1.681GB (66%)
    Containers      35        18        831.5kB   413.7kB (49%)
    Local Volumes   0         0         0B        0B
    Build Cache     10        0         12.29kB   12.29kB
  7. Verify that Docker Engine is installed correctly
    The command "docker container run hello-world" downloads the hello-world image and runs it in a container.
    When the container runs, it prints a "Hello from Docker!" message and exits.

    $ sudo docker container run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    e6590344b1a5: Pull complete
    Digest: sha256:c41088499908a59aae84b0a49c70e86f4731e588a737f1637e73c8c09d995654
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker container run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     https://hub.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/get-started/
  8. Manage Docker service
    • To Enable/Disable Docker service (start on boot):
      $ sudo systemctl enable docker
      $ sudo systemctl disable docker
    • To Start/Stop Docker service:
      $ sudo systemctl start docker
      $ sudo systemctl stop docker
  9. Important Docker files/folders
    • Important folders/files:
      /var/lib/docker/
      /etc/docker/key.json
      /etc/docker/daemon.json
      /lib/systemd/system/docker.service
      /lib/systemd/system/docker.socket
      /lib/systemd/system/containerd.service

      /etc/docker/daemon.json: might not be created by default when you install Docker. For Docker Desktop, you need to use the its UI to modify this file. It can hold configurations related to the dockerd server, including the arguments we use when we start Docker (e.g., "experimental", "metrics-addr")
      $ sudo ls -1 /var/lib/docker/
      buildkit
      containers
      engine-id
      image
      network
      overlay2
      plugins
      runtimes
      swarm
      tmp
      volumes
      $ cat /lib/systemd/system/docker.service
      [Unit]
      Description=Docker Application Container Engine
      Documentation=https://docs.docker.com
      After=network-online.target nss-lookup.target docker.socket firewalld.service containerd.service time-set.target
      Wants=network-online.target containerd.service
      Requires=docker.socket
      
      [Service]
      Type=notify
      ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
      ExecReload=/bin/kill -s HUP $MAINPID
      TimeoutStartSec=0
      RestartSec=2
      Restart=always
      $ cat /lib/systemd/system/docker.socket
      [Unit]
      Description=Docker Socket for the API
      
      [Socket]
      ListenStream=/run/docker.sock
      SocketMode=0660
      SocketUser=root
      SocketGroup=docker
      $ cat /lib/systemd/system/containerd.service
      [Unit]
      Description=containerd container runtime
      Documentation=https://containerd.io
      After=network.target local-fs.target dbus.service
      
      [Service]
      ExecStartPre=-/sbin/modprobe overlay
      ExecStart=/usr/bin/containerd
© 2025  mtitek