centos7安裝docker
1、查看linux發行版,內核
[root@docker~]# cat /etc/redhat-release #查看版本號 CentOS Linux release 7.1.1503 (Core) [root@docker ~]# uname -r #查看Linux內核 c3.10.0-229.el7.x86_64
2、替換阿里雲yum源
1 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #下載阿里yum源2 2 yum makecache #生成倉庫緩存
3、安裝docker
yum install docker -y
4、啟動docker
systemctl start docker #啟動docker systemctl enable docker #開機啟動docker systemctl status docker #查看docker狀態
5、查看docker 版本
docker version
#yum裝的是1.12.6
6、DaoCloud 加速器 是廣受歡迎的 Docker 工具,解決了國內用戶訪問 Docker Hub 緩慢的問題。DaoCloud 加速器結合國內的 CDN 服務與協議層優化,成倍的提升了下載速度。
使用前請先確保您的 Docker 版本在 1.8 或更高版本,否則無法使用加速。
http://guide.daocloud.io/dcs/daocloud-9153151.html 教程官網
cat /etc/docker/daemon.json #修改這個文件為如下內容
{
"registry-mirrors": [
"http://95822026.m.daocloud.io"
],
"insecure-registries": []
}
---------------------------------------------------------
或者用這條命令
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://95822026.m.daocloud.io
#事后重啟docker
systemctl restart docker
7、比如我們要裝一個nginx,先搜尋一下有哪些公有鏡像,然后開始安裝 啟動..
docker search nginx #就找第一個,下載最多的,官方鏡像
docker pull nginx #下載nginx鏡像
docker images #查看有哪些鏡像
8、啟動nginx鏡像
docker run -p 8000:80 --name mynginx -d nginx
#-p指定服務器8000端口,映射容器80 web端口,容器名為mynginx -d 守護進程模式啟動(因為容器必須有進程在運行,否則結束就掛)
docker ps #查看目前工作的容器
docker ps -a #查看所有運行過的容器
9、此時可以用服務器ip地址,在瀏覽器訪問,默認80端口不用寫,即可訪問到 welcome nginx
10、可用exec命令進入容器系統
docker exec -it 容器ID /bin/bash