docker简单食用

最近玩了下docker,发现这个东西真的是一款神器。可以直接拉取镜像,可以极大程度的解决我们平时在搭建一些测试环境的难度。但是这个环境在搭建过程中有很多坑。网上很多教程写的的也不太好。本着开源分享的精神,我便将我自身搭建的过程分享出来,尽可能让大家少走点弯路。

安装docker

本教程环境搭建基于Ubuntu 20.04

sudo passwd root  //修改root账号密码
su root   //输入密码 登录root账号
apt install vim   //安装vim
vim /etc/apt/source.list  //更换源配置

将下面的内容粘贴进去,并保存退出

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
apt-get update   //更新软件
apt-get install ssh  ///安装SSH
cd /etc/ssh      //切换目录
vim sshd_config    //修改配置文件

按下图修改

image-20230220165721823
apt install net-tools  // 安装
service ssh start/stop/restart/status   //开启SSH服务
netstat -anptl        //查看22端口是否开放
update-rc.d ssh enable   //设置为开机自启动
apt install curl   //安装curl
vim installDocker.sh

复制该网址的内容

https://get.docker.com/

chmod +x installDocker.sh
./installDocker.sh
apt install python3-pip 
pip install docker-compose
apt-get install git 

上面的这些操作完成了以后

docker -v
docker-compose -v

看是否成功输出了版本号。如果没成功就恭喜中奖了 建议还原快照 重新找教程安装。。。。

docker玩法

docker我目前主要是用来搭建靶场和ARL 水泽这类资产搜索软件。

下面演示下DVWA的安装方法

docker search DVWA
image-20230220171451085

下面就列举了出了存在的镜像,然后使用pull命令拉取

比如我们需要拉取第一个镜像

docker pull sagikazarmark/dvwa

等待一会就成功了。

docker run --rm -it -p 8080:80 sagikazarmark/dvwa

8080 和 80是可以修改的 意为将 docker的80端口映射到服务器的8080端口。

然后我们打开浏览器访问

服务器的公网IP:你设置的端口

如果访问不了,注意去服务器控制台看看是不是端口没开放。将端口开放,还有就是注意IP设置为白名单。防止被恶意攻击。

实在不放心的可以搭建在虚拟机里面。