Skip to main content

Debian Install Docker

Installing Docker in Debian or Ubuntu, is very simple, but the potential of containers is huge, more and more developers, systems support them, and so do we with the Docker Consultancy
It is available in all Linux distributions, MacOS, even Microsoft supports containerization with Windows Subsystem for Linux WSL

Installing Docker in Docker

For the installation some additional packages are required and enabling the project's official repository
We can copy the lines and run them from user or root

  1. Install requirements

    $ sudo apt-get install -y --no-install-recommends apt-transport-https ca-certificates curl software-properties-common
  2. We remove any conflicting packages

    $ for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
  3. We import the Docker repository key

    $ sudo install -m 0755 -d /etc/apt/keyrings
    $ sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
    $ sudo chmod a+r /etc/apt/keyrings/docker.asc
  4. Add Docker repository

    echo \
      "deb [deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
      $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  5. Let's update the available packages again

    $ sudo apt-get update
  6. We install the Docker packages

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

Docker run hello world

Finished installing Docker, let's try with a test run of our Docker engine

docker run hello-world

If we managed to install Docker correctly on our operating system, the daemon will download the container and run it, giving similar output:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:ec153840d1e635ac434fab5e377081f17e0e15afab27beb3f726c3265039cfff
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.
 The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 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 run -en 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/

Run of the first container

Now we can perform the runof the first Docker container

$ sudo docker run -en --entrypoint bash debian

We will be looking at the Shell of our newly created Debian container
To see the list of containers created we can use

$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0b4aacdb44b9 debian "bash" 30 seconds ago Up elegant_lovelace

Stopping a container

To stop a container we can use docker stop followed by the container name. The status will change from "Up" to "Exited" for example:

$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0b4aacdb44b9 debian "bash" 30 seconds ago Up elegant_lovelace
$ sudo docker stop elegant_lovelace
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0b4aacdb44b9 debian "bash" 30 seconds ago Exited elegant_lovelace

Remove a container

You need to use docker rm and the container name, obtained from ps -a, the container to be deleted must first be stopped

$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0b4aacdb44b9 debian "bash" 30 seconds ago Exited elegant_lovelace
$ sudo docker rm elegant_lovelace

Docker update a container

To update the container image you just need to perform its pull, you use the same command to download from the official repository with the syntax docker pull nomecontainer:version

$ sudo docker pull debian:latest
latest: Pulling from library/debian
d6ff36c9ec48: Pull complete
Digest: sha256:1e74c92df240634a39d050a5e23fb18f45df30846bb222f543414da180b47a5d
Status: Downloaded newer image for debian:latest
docker.io/library/debian:latest

From the moment we create a container the newly downloaded updated image will be used

Custom Docker support

Simplify your Docker container management with our advanced technical support. Maximum reliability for your operations!"

Contact a Docker Technician now: Free 30m consulting!

Frequently Asked Questions FAQ

How to install Docker in Kali Linux?

Installing Docker in Kali Linux follows the same process as Debian, since Kali is Debian-based. Run the commands listed in the previous section. Make sure your system is up-to-date before you start:
$ sudo apt update && sudo apt full-upgrade

How to start the Docker daemon in Debian?

To start the Docker service in Debian, use the command:
$ sudo systemctl start docker

To enable it at system startup:
$ sudo systemctl enable docker

Check the status of the service with:
$ sudo systemctl status docker

Can I install a Linux system inside a Docker container?

Not really, you can use a minimal Linux distribution inside a Docker container. For example, to start a Debian-based container, use the command:
$ sudo docker run -en debian
This will provide you with an isolated Debian-based environment. You can choose from several Linux distributions available on the Docker Hub, such as Ubuntu, CentOS, or Fedora.

Add new comment

Comment

  • Allowed HTML tags: <br> <p> <code class="language-*"> <pre>
  • Lines and paragraphs break automatically.
  • Only images hosted on this site may be used in <img> tags.