在Kali Linux上安装Docker和Docker Compose

欢迎来到有关如何在Kali Linux上安装Docker和Docker Compose的指南。在Kali Linux上安装Docker CE(社区版)。 Docker是最常见且使用最广泛的容器运行时。开发人员可以打包和运送应用程序,并在单独的容器中运行它们。促进从开发人员的机器到Kubernetes调整的生产环境的运输。

以下是Docker生态系统中常用的术语。

  • Docker守护程序答:这也称为Docker Engine,它是一个在主机系统上运行的后台进程,负责构建和运行容器。
  • 码头工人 委托人答:这是用户用于与Docker守护程序进行交互的命令行工具。
  • Docker镜像答:图像是一个不变的文件,本质上是容器的快照。 Docker映像具有运行应用程序所需的文件系统和应用程序依赖关系。
  • Docker容器答:这是具有应用程序及其依赖关系的docker映像的运行实例。每个容器都有唯一的进程ID,并且与其他容器隔离。容器仅共享内核。
  • Docker注册表答:这是一个管理Docker容器映像的存储和分发的应用程序。它可以是私人的也可以是公共的。

让我们开始在Kali Linux上安装Docker。

步骤1:安装依赖包

确保已安装docker用作依赖项的所有软件包,然后开始安装。

sudo apt update
sudo apt -y install curl gnupg2 apt-transport-https software-properties-common ca-certificates  

步骤2:导入Docker GPG密钥:

导入用于签署Docker软件包的Docker GPG密钥。

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

步骤3:将Docker仓库添加到Kali Linux

添加一个包含最新稳定版本Docker CE的Docker存储库。

echo "deb [arch=amd64] https://download.docker.com/linux/debian buster stable" | sudo tee  /etc/apt/sources.list.d/docker.list

此命令将存储库URL添加到/etc/apt/sources.list.d/docker.list。

步骤4:在Kali Linux上安装Docker

更新资料 apt 包索引。

$ sudo apt update
gn:1 http://dl.google.com/linux/chrome/deb stable InRelease
Get:3 https://download.docker.com/linux/debian buster InRelease [44.4 kB]                          
Hit:2 http://kali.download/kali kali-rolling InRelease
Hit:4 http://dl.google.com/linux/chrome/deb stable Release
Get:5 https://download.docker.com/linux/debian buster/stable amd64 Packages [10.9 kB]
Fetched 55.3 kB in 1s (45.2 kB/s)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
186 packages can be upgraded. Run 'apt list --upgradable' to see them.

要在Kali Linux上安装Docker CE,请执行以下命令:

sudo apt install docker-ce docker-ce-cli containerd.io

命中 ÿ 在Kali Linux上启动Docker安装的密钥。

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  aufs-dkms aufs-tools cgroupfs-mount dkms linux-compiler-gcc-9-x86 linux-headers-5.4.0-kali3-amd64
  linux-headers-5.4.0-kali3-common linux-headers-amd64 linux-kbuild-5.4 pigz
Suggested packages:
  aufs-dev menu
The following NEW packages will be installed:
  aufs-dkms aufs-tools cgroupfs-mount containerd.io dkms docker-ce docker-ce-cli linux-compiler-gcc-9-x86
  linux-headers-5.4.0-kali3-amd64 linux-headers-5.4.0-kali3-common linux-headers-amd64 linux-kbuild-5.4 pigz
0 upgraded, 13 newly installed, 0 to remove and 186 not upgraded.
Need to get 98.1 MB of archives.
After this operation, 446 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

此安装添加 docker 分组为没有用户的系统。通过将用户帐户添加到组,以非特权用户身份运行docker命令。

sudo usermod -aG docker $USER
newgrp docker

检查已安装的Docker版本。

$ docker version
Client: Docker Engine - Community
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.16
 Git commit:        369ce74a3c
 Built:             Thu Feb 13 01:27:58 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.6
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.16
  Git commit:       369ce74a3c
  Built:            Thu Feb 13 01:26:32 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.12
  GitCommit:        35bd7a5f69c13e1563af8a93431411cd9ecf5021
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

步骤5:在Kali Linux上安装Docker Compose

使用以下指南在Kali Linux上安装最新的Docker Compose。

如何在Linux上安装最新的Docker Compose

安装后,检查版本以确认安装成功。

$  docker-compose version
docker-compose version 1.25.4, build 8d51620a
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

步骤6:测试Docker安装。

运行测试Docker容器。

$ docker run --rm -it  hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
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 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/

步骤6:测试Docker Compose安装。

创建一个测试Docker Compose文件。

$ vim docker-compose.yml

将以下数据添加到文件中。

version: '3'  
services:
  web:
    image: nginx:latest
    ports:
     - "8080:80"
    links:
     - php
  php:
    image: php:7-fpm

启动服务容器。

$ docker-compose up -d
Creating network "jkmutai_default" with the default driver
Pulling php (php:7-fpm)...
7-fpm: Pulling from library/php
bc51dd8edc1b: Pull complete
a3224e2c3a89: Pull complete
be7a066df88f: Pull complete
bfdf741d72a9: Pull complete
0096578ff21c: Pull complete
52b9a3846c51: Pull complete
91c8df69c5cf: Pull complete
ba16a1822680: Pull complete
c137b651214d: Pull complete
a2738b6c9bea: Pull complete
Digest: sha256:022dcc4f1a054584660ce3d77bb0dc1f5084d25f117d4814726518b7f66af47f
Status: Downloaded newer image for php:7-fpm
Pulling web (nginx:latest)...
latest: Pulling from library/nginx
bc51dd8edc1b: Already exists
66ba67045f57: Pull complete
bf317aa10aa5: Pull complete
Digest: sha256:ad5552c786f128e389a0263104ae39f3d3c7895579d45ae716f528185b36bc6f
Status: Downloaded newer image for nginx:latest
Creating jkmutai_php_1 ... done
Creating jkmutai_web_1 ... done

显示正在运行的容器:

$ docker-compose ps
    Name                   Command              State          Ports        
----------------------------------------------------------------------------
jkmutai_php_1   docker-php-entrypoint php-fpm   Up      9000/tcp            
jkmutai_web_1   nginx -g daemon off;            Up      0.0.0.0:8080->80/tcp

销毁一个容器:

$ docker-compose stop
Stopping jkmutai_web_1 ... done
Stopping jkmutai_php_1 ... done

$ docker-compose rm
Going to remove jkmutai_web_1, jkmutai_php_1
Are you sure? [yN] y
Removing jkmutai_web_1 ... done
Removing jkmutai_php_1 ... done

在Kali Linux上享受使用Docker和Docker Compose开发和运行容器化应用程序的乐趣。

Sidebar