1. 添加Docker的ATP仓库

    sudo sh -c "echo deb https://get.docker.io/ubuntu docker main >   /etc/apt/sources.list.d/docker.list"
    
  2. 添加Docker仓库的GPG密钥
    curl -s https://get.docker.io/gpg | sudo apt-key add -
    
  3. 更新APT源
    sudo apt-get update
    
  4. 在Ubuntu中安装Docker
    sudo apt-get install lxc-docker docker
    
  5. 确认Docker已经安装在Ubuntu中
    ➜  ~  sudo docker info
    [sudo] password for tp:
    Containers: 1
    Images: 4
    Storage Driver: aufs
    Root Dir: /var/lib/docker/aufs
    Backing Filesystem: extfs
    Dirs: 6
    Dirperm1 Supported: true
    Execution Driver: native-0.2
    Logging Driver: json-file
    Kernel Version: 3.16.0-44-generic
    Operating System: Ubuntu 14.10
    CPUs: 4
    Total Memory: 7.702 GiB
    Name: ubuntu
    ID: LOMF:BPSX:TEY4:HU4K:S5E3:H6UX:DUNQ:MFSG:UAIP:JMW5:HKEP:SQ2M
    WARNING: No swap limit support
  6. 检查docker守护进程是否在运行

    ➜  ~  sudo status docker
    [sudo] password for tp:
    docker start/running, process 18117
  7. 居于ubuntu镜像,创建一个docker
    ➜  ~  sudo docker run -i -t ubuntu /bin/bash
    [sudo] password for tp:
    root@5e2accdd4f7a:/#
    # 创建特定名称的docker
    sudo docker run --name first-docker -i -t ubuntu /bin/bash
  8. 创建一个kali-linux
    # 先获取镜像
    ➜ tools sudo docker pull kalilinux/kali-linux-docker
    latest: Pulling from kalilinux/kali-linux-docker a4d244f4db27: Pull complete
    ff90a7782c43: Pull complete
    426f69441115: Pull complete
    c4fad45aeb16: Pull complete
    e4c3a586e9ad: Pull complete
    63ae5ac8df0f: Already exists
    Digest: sha256:9d50de0f7e4f9696f7b85896cad1d966d4fabcc47c75ed427705708a33b762b4
    Status: Downloaded newer image for kalilinux/kali-linux-docker:latest # 创建kali-linux
    ➜ tools sudo docker run --name kali -t -i kalilinux/kali-linux-docker /bin/bash
    root@fe6c7da22c2e:/# uname -a
    Linux fe6c7da22c2e 3.16.0-44-generic #59-Ubuntu SMP Tue Jul 7 02:07:39 UTC 2015 x86_64 GNU/Linux # 更新源列表,由于刚安装的,vim都没有,所以用nano进行编辑 #加入如下源,ctrl+o写入ctrl+x退出
    deb http://mirrors.ustc.edu.cn/kali kali main non-free contrib
    deb-src http://mirrors.ustc.edu.cn/kali kali main non-free contrib
    deb http://mirrors.ustc.edu.cn/kali-security kali/updates main contrib non-free # 刷新源列表
    apt-get update
    # 安装metasploit
    root@fe6c7da22c2e:/# apt-get install metasploit
  9. 使用容器
    root@5e2accdd4f7a:/# hostname
    5e2accdd4f7a
    root@5e2accdd4f7a:/# cat /etc/hosts
    172.17.0.2 5e2accdd4f7a
    127.0.0.1 localhost
    ::1 localhost ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    root@5e2accdd4f7a:/# vim
    bash: vim: command not found
    root@5e2accdd4f7a:/# apt-get install vim
  10. 查看当前系统中容器列表
    ➜  ~  sudo docker ps -a
    [sudo] password for tp:
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    5e2accdd4f7a ubuntu "/bin/bash" 6 minutes ago Up 6 minutes fervent_wozniak
    c5e16b9df2e5 ubuntu "/bin/bash" 25 minutes ago Up 7 minutes reverent_hoover
  11. 切换到正在运行的docker
    ➜  ~  sudo docker attach reverent_hoover
    root@c5e16b9df2e5:/#
  12. 查看容器内的进程
    ➜  ~  sudo docker top fervent_wozniak
    UID PID PPID C STIME TTY TIME CMD
    root 20254 18117 0 14:02 pts/16 00:00:00 /bin/bash
  13. 停止或重容器
    ➜  ~  sudo docker stop reverent_hoover
    reverent_hoover
    ➜ ~ sudo docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    f68e131bb9dc ubuntu "/bin/bash" 12 minutes ago Exited (0) 11 minutes ago first-docker
    5e2accdd4f7a ubuntu "/bin/bash" 22 minutes ago Exited (2) 39 seconds ago fervent_wozniak
    c5e16b9df2e5 ubuntu "/bin/bash" 42 minutes ago Exited (0) 2 seconds ago reverent_hoover
    ➜ ~ sudo docker start reverent_hoover
    reverent_hoover
    ➜ ~ sudo docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    f68e131bb9dc ubuntu "/bin/bash" 12 minutes ago Exited (0) 11 minutes ago first-docker
    5e2accdd4f7a ubuntu "/bin/bash" 22 minutes ago Exited (2) 49 seconds ago fervent_wozniak
    c5e16b9df2e5 ubuntu "/bin/bash" 42 minutes ago Up 1 seconds reverent_hoover
  14. 获取容器更多信息
    ➜  ~  sudo docker inspect reverent_hoover
    
  15. 删除容器
    ➜  ~  sudo docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    f68e131bb9dc ubuntu "/bin/bash" 15 minutes ago Exited (0) 14 minutes ago first-docker
    5e2accdd4f7a ubuntu "/bin/bash" 26 minutes ago Exited (2) 4 minutes ago fervent_wozniak
    c5e16b9df2e5 ubuntu "/bin/bash" 45 minutes ago Up 3 minutes reverent_hoover
    ➜ ~ sudo docker rm first-docker
    first-docker
    ➜ ~ sudo docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    5e2accdd4f7a ubuntu "/bin/bash" 26 minutes ago Exited (2) 4 minutes ago fervent_wozniak
    c5e16b9df2e5 ubuntu "/bin/bash" 46 minutes ago Up 3 minutes reverent_hoover # 删除全部容器
    sudo docker rm `docker ps -a -q`
05-01 00:50