threst's Blog

kali下安装docker

2018/05/29 Share

周末水了下suctf,只做出签到题,太菜了,今天在安全客上面梅子酒师傅发出了wp,看了之后觉得质量非常高,最重要的是可以在docker上复现,发现现在kali上面并没有安装docker,之前在知乎上面写过一篇关于如何安装docker的文章,于是晚上试了下,尴尬的是失败了!!google了下,喜获一个一键安装脚本,看了下大佬脚本发现可能是apt-get install docker-ce这个的问题,因为之前一直是apt-cache policy docker-engine

之前的安装方式

由于kali linux是基于Debian Wheezy,所以这里docker需要的内核版本至少是3.10,因此需要检查下kali的内核,如果不够的话,需要更新内核
uname -a
切换用户root下

1.创建/etc/apt/sources.list.d/backports.list

leafpad /etc/apt/sources.list.d/backports.list

2.在list文件里加上一条反向端口条目

deb http://http.debian.net/debian wheezy-backports main

3.更新软件包

apt update

4.如果以前安装过docker

就这样删除所有旧版本docker

apt-get purge lxc-docker*
apt-get purge docker.io*

可能没有旧版本(之前没有安装过)
没有的继续

5.确认apt添加了https方法和CA cerificates

apt-get install apt-transport-https ca-certificates gnupg2

6.添加一个新的GPG key

apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

7.安装repository

apt-cache policy docker-engine
这个命令可以查看是否存在资源之后再
apt-get install docker-engine
但是这个好像不行了要执行下列命令
apt-get install docker-ce

一键安装脚本

#!/bin/bash
# install dependencies 
sudo apt-get install apt-transport-https ca-certificates curl gnupg software-properties-common dirmngr

# use https get sources  
sudo echo "deb https://http.kali.org/kali kali-rolling main non-free contrib" > /etc/apt/sources.list
sudo echo "deb-src https://http.kali.org/kali kali-rolling main non-free contrib" >> /etc/apt/sources.list

# update apt-get
export DEBIAN_FRONTEND="noninteractive"
sudo apt-get update

# remove previously installed Docker
sudo apt-get purge lxc-docker*
sudo apt-get purge docker.io*

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

# add deb docker sources
sudo echo "deb [arch=amd64] https://download.docker.com/linux/debian stretch stable" >> /etc/apt/sources.list 
cat > /etc/apt/sources.list.d/docker.list <<'EOF'
deb https://apt.dockerproject.org/repo debian-stretch main
EOF
sudo apt-get update

# install Docker
sudo apt-get install docker-ce

# run Hellow World image
sudo docker run hello-world

# manage Docker as a non-root user
sudo groupadd docker
sudo usermod -aG docker $USER

# configure Docker to start on boot
sudo systemctl enable docker

脚本地址

测试:

root@kali:/home/threst# docker run hello-world
出现下面这个就是安装成功了

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/engine/userguide/

使用国内镜像:
docker pull registry.docker-cn.com/myname/myrepo:mytag
例如
docker pull registry.docker-cn.com/suctf/2018-web-annonymous

CATALOG
  1. 1. 之前的安装方式
    1. 1.1. 1.创建/etc/apt/sources.list.d/backports.list
    2. 1.2. 2.在list文件里加上一条反向端口条目
    3. 1.3. 3.更新软件包
    4. 1.4. 4.如果以前安装过docker
    5. 1.5. 5.确认apt添加了https方法和CA cerificates
    6. 1.6. 6.添加一个新的GPG key
    7. 1.7. 7.安装repository
  2. 2. 一键安装脚本
  3. 3. 测试: