最近工做中須要用到docker,因此決定本身搭建一個docker環境,因而選擇在virtualbox上安裝centos7虛擬機,並在虛擬機上安裝docker,沒搭建環境以前,以爲應該很簡單,沒想到折騰了好長時間。好比安裝的centos7版本不支持docker,最後致使重裝,因此特此記錄下安裝步驟及注意事項。docker
1) 建立虛擬機,選擇centos系統鏡像,好比CentOS-7-x86_64-DVD-1708.iso,務必使用官方最新支持的版本,若是選擇的鏡像版本不對,會致使安裝完docker沒法運行;ubuntu
2)開始安裝虛擬機,若是須要圖形化界面,在安裝最後一步記得選擇帶圖形安裝;centos
3)安裝完畢,重啓後,須要贊成許可才能進入系統,若是是命令行界面,記得仔細閱讀提示信息,需輸入相應的選項贊成許可才能進入系統;bash
4)安裝virtualbox加強功能,通常會提示缺乏gcc、make、perl和其餘庫文件,需安裝和系統內核版本一致的庫文件,不然不能安裝virtualbox加強功能,例如:app
Verifying archive integrity... All good. Uncompressing VirtualBox 5.2.6 Guest Additions for Linux........ VirtualBox Guest Additions installer Copying additional installer modules ... Installing additional modules ... VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This system is currently not set up to build kernel modules. Please install the gcc make perl packages from your distribution. Please install the Linux kernel "header" files matching the current kernel for adding new hardware support to the system. The distribution packages containing the headers are probably: kernel-devel kernel-devel-3.10.0-693.el7.x86_64 VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This system is currently not set up to build kernel modules. Please install the gcc make perl packages from your distribution. Please install the Linux kernel "header" files matching the current kernel for adding new hardware support to the system. The distribution packages containing the headers are probably: kernel-devel kernel-devel-3.10.0-693.el7.x86_64 Press Return to close this window...
按照提示信息,安裝所需的工具和庫:curl
[root@ssli-centos7 ~]# yum install gcc make perl [root@ssli-centos7 ~]# yum install kernel-devel-$(uname -r) [root@ssli-centos7 ~]# rpm -qa kernel\* kernel-3.10.0-693.el7.x86_64 kernel-tools-3.10.0-693.el7.x86_64 kernel-headers-3.10.0-693.el7.x86_64 kernel-devel-3.10.0-693.el7.x86_64 kernel-tools-libs-3.10.0-693.el7.x86_64
再次安裝virtualbox加強功能,成功安裝。ide
5)安裝docker:工具
root@ssli-centos7:~$ curl -fsSL https://get.docker.com/ | sh root@ssli-centos7:~$ systemctl start docker root@ssli-centos7:~$ systemctl status docker root@ssli-centos7:~$ systemctl enable docker
安裝docker,並啓動docker,而後將docker服務設置成開機自啓動。ui
6)運行docker hello world示例:this
root@ssli-centos7:~$ docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7 Status: Downloaded newer image for hello-world:latest
root@ssli-centos7:~$ 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://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
至此,成功在centos7上安裝docker。