https://linuxize.com/post/how-to-install-and-use-docker-on-debian-9
Docker is de facto standard for
container technology and it is an essential tool for DevOps engineers
and their continuous integration and delivery pipeline.
In this tutorial we will guide you through the process of installing Docker on a Debian 9 machine and explore the basic Docker concepts and commands.
If you want to run Docker commands as a non-root user without prepending
Log out and log back in so that the group membership is refreshed.
To verify that you can run docker commands without prepending
The output should look like the following:
To list all available commands run
If you need more help on any
You can think of a Docker image as a snapshot of a Docker container.
Most Docker images are available on Docker Hub.
The Docker Hub is cloud-based registry service which among other functionalities is used for keeping the Docker images either in a public or private repository.
For example, to search for a Debian image, you would type:
The output should look like this:
As you can see the search results prints a table with five columns,
Official image is an image that Docker develops in conjunction with upstream partners.
Most Docker images on Docker Hub are tagged with version numbers. When no tag is specified Docker will pull the latest image.
Depending on your Internet speed, the download may take a few seconds or a few minutes.
Since we haven’t specified a tag, docker will pull the latest Debian image which is 9.5. If you want to pull some of the previous Debian versions, let’s say Debian 8 then you need to use
Once the image is downloaded we can list the images by typing:
The output will look something like this:
It may not be the most appropriate comparison but if you are a programmer you can think of a Docker image as class and Docker container as an instance of a class.
We can start, stop, remove and manage a container with the
At
first sight it may seem to you that nothing happened at all. Well, that
is not true. The Debian container stops immediately after booting up
because it does not have a long-running process and we didn’t provide
any command, so the container booted up, ran an empty command and then
exited.
The switch
As
you can see from the output above once the container is started the
command prompt is changed which means that you’re now working from
inside the container:
To view both active and inactive containers, pass it the
You should also check out the official Docker documentation.
If you have any question, please leave a comment below.
How To Install and Use Docker on Debian 9
This tutorial is also available for:
In this tutorial we will guide you through the process of installing Docker on a Debian 9 machine and explore the basic Docker concepts and commands.
Prerequisites
Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
Install Docker
The following steps describe how to install the latest stable Docker version from the Docker’s repositories.- Update your system and install necessary packages
Update theapt
package list and upgrade all installed packages:
sudo apt update sudo apt upgrade
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg2
- Add the Docker repository
First add the Docker’s GPG key to your apt keyring by executing:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
$(lsb_release -cs)
will return the name of the Debian distibution, in this case it will returnjessie
. - Install Docker
Now that the Docker repository is enabled, update theapt
package list and install the latest version of Docker CE (Community Edition) with:
sudo apt update sudo apt install docker-ce
- Verify the installation
Once the installation is completed the Docker service will start automatically. You can verify it by typing:
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 Fri 2018-07-27 17:02:07 UTC; 1min 14s ago Docs: https://docs.docker.com Main PID: 16929 (dockerd) CGroup: /system.slice/docker.service
18.06.0-ce
. To check the Docker version run:
docker -v
Docker version 18.06.0-ce, build 0ffa825
Executing the Docker Command Without Sudo
By default, only a user with administrator privileges can execute Docker commands.If you want to run Docker commands as a non-root user without prepending
sudo
you’ll need to add your user to the docker group which is created
during the installation of the Docker CE package. You can do that by
typing:sudo usermod -aG docker $USER
To verify that you can run docker commands without prepending
sudo
run the following command which will download a test image, run it in a
container, print a “Hello from Docker” message and exit:docker container run hello-world
Docker command line interface
Now that we have Docker installed, let’s go over the basic syntax of the docker CLI:docker [option] [subcommand] [arguments]
docker
with no parameters:docker
[subcommand]
, you can use the --help
switch as shown bellow:docker [subcommand] --help
Docker Images
A Docker image is made up of a series of filesystem layers representing instructions in the image’s Dockerfile that make up an executable software application. An image is an immutable binary file including the application and all other dependencies such as libraries, binaries and instructions necessary for running the application.You can think of a Docker image as a snapshot of a Docker container.
Most Docker images are available on Docker Hub.
The Docker Hub is cloud-based registry service which among other functionalities is used for keeping the Docker images either in a public or private repository.
Search Docker Image
To search for an image from Docker Hub registry, use thesearch
subcommand.For example, to search for a Debian image, you would type:
docker search debian
As you can see the search results prints a table with five columns,
NAME
, DESCRIPTION
, STARS
, OFFICIAL
and AUTOMATED
.Official image is an image that Docker develops in conjunction with upstream partners.
Most Docker images on Docker Hub are tagged with version numbers. When no tag is specified Docker will pull the latest image.
Download Docker Image
If we want to download the official build of the Debian image we can do that by using theimage pull
subcommand:docker image pull debian
Since we haven’t specified a tag, docker will pull the latest Debian image which is 9.5. If you want to pull some of the previous Debian versions, let’s say Debian 8 then you need to use
docker image pull debian:8
Once the image is downloaded we can list the images by typing:
docker image ls
Remove Docker Image
If for some reason you want to delete an image you can do that with theimage rm [image_name]
subcommand:docker image rm debian
Docker Containers
An instance of an image is called a container. A container represents a runtime for a single application, process, or service.It may not be the most appropriate comparison but if you are a programmer you can think of a Docker image as class and Docker container as an instance of a class.
We can start, stop, remove and manage a container with the
docker container
subcommand.Start Docker Container
The following command will start a Docker container based on the Debian image. If you don’t have the image locally, it will be downloaded first:docker container run debian
The switch
-it
allows us to interact with the container via the command line. To start an interactive container type:docker container run -it debian /bin/bash
root@ee86c8c81b3b:/#
List Docker Containers
To list active containers, type:docker container ls
If you don’t have any running containers the output will be empty.
-a
switch:docker container ls -a
Remove Docker Containers
To delete a container multiple containers just copy the container ID (or IDs) and paste them after the
container rm
subcommand:docker container rm c55680af670c
Conclusion
You have learned how to install Docker on your Debian 9 machine and how to download Docker images and manage Docker containers. This tutorial barely scratches the surface of the Docker ecosystem. In some of our next articles, we will continue to dive into other aspects of Docker.You should also check out the official Docker documentation.
If you have any question, please leave a comment below.
No comments:
Post a Comment