Install Docker on Ubuntu or Debian
Installing Docker on Ubuntu or Debian only takes a few commands. This should all take only a few minutes. Let’s dive in.
1. Remove Docker
Section titled “1. Remove Docker”First, you need to remove any Docker dependencies. (If you’ve never installed Docker before, don’t worry. You can skip this step.)
$ sudo apt-get remove docker docker-engine docker.io containerd runc2. Set up the repository
Section titled “2. Set up the repository”Now we need to set up the Docker repository, add the official GPG key, and verify it.
$ sudo apt-get update
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-commonNext, we add the GPGKey.
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -Now, we need to verify the fingerprint and check it matches this:
- 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
$ sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22 Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88uid Docker Release (CE deb) <docker@docker.com>sub 4096R/F273FCD8 2017-02-22If that’s all good, we add the Docker repository.
$ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"3. Install Docker
Section titled “3. Install Docker”Okay, now that we’ve got the repository set up and verified, it’s time to install Docker.
$ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.ioAt this point, it’s good to start a container to check that Docker installed correctly.
$ sudo docker run hello-world4. Add non-root users
Section titled “4. Add non-root users”You’ll notice that if you want to start Docker as a non-root user, you’ll probably run into this error message.
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission deniedDon’t worry. There’s an easy fix for that. First, create the docker group.
$ sudo groupadd dockerThen add the non-root user to the group.
$ sudo usermod -aG docker $USERWith all that done, you’ve got Docker set up and ready to use.