最近工作中需要用到docker,所以決定自己搭建一個(gè)docker環(huán)境,于是選擇在virtualbox上安裝centos7虛擬機(jī),并在虛擬機(jī)上安裝docker蹋凝,沒搭建環(huán)境之前鲁纠,覺得應(yīng)該很簡單总棵,沒想到折騰了好長時(shí)間。比如安裝的centos7版本不支持docker改含,最后導(dǎo)致重裝情龄,所以特此記錄下安裝步驟及注意事項(xiàng)。
1) 創(chuàng)建虛擬機(jī)捍壤,選擇centos系統(tǒng)鏡像骤视,比如CentOS-7-x86_64-DVD-1708.iso,務(wù)必使用官方最新支持的版本鹃觉,如果選擇的鏡像版本不對专酗,會導(dǎo)致安裝完docker無法運(yùn)行;
2)開始安裝虛擬機(jī)盗扇,如果需要圖形化界面祷肯,在安裝最后一步記得選擇帶圖形安裝;
3)安裝完畢疗隶,重啟后佑笋,需要同意許可才能進(jìn)入系統(tǒng),如果是命令行界面斑鼻,記得仔細(xì)閱讀提示信息蒋纬,需輸入相應(yīng)的選項(xiàng)同意許可才能進(jìn)入系統(tǒng);
4)安裝virtualbox增強(qiáng)功能坚弱,一般會提示缺少gcc蜀备、make、perl和其他庫文件荒叶,需安裝和系統(tǒng)內(nèi)核版本一致的庫文件碾阁,否則不能安裝virtualbox增強(qiáng)功能,例如:
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...
按照提示信息停撞,安裝所需的工具和庫:
# yum install gcc make perl
# yum install kernel-devel-$(uname -r)
# 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增強(qiáng)功能瓷蛙,成功安裝悼瓮。
5)安裝docker:
$ curl -fsSL https://get.docker.com/ | sh
$ systemctl start docker
$ systemctl status docker
$ systemctl enable docker
安裝docker,并啟動docker艰猬,然后將docker服務(wù)設(shè)置成開機(jī)自啟動横堡。
6)運(yùn)行docker hello world示例:
$ 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
$ 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冠桃。