Ubuntu安装Docker方式
//阿里云docker安装帮助
https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11t5HRM3
//docker命令帮助大全
https://www.runoob.com/docker/docker-command-manual.html
//更新软件源
sudo apt-get update
//安装必要的一些系统工具
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
//安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
//写入软件源信息
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
//更新并安装Docker-CE
sudo apt-get -y update
- 验证软件源文件
- sudo vim /etc/apt/sources.list
- 查看docker-ce可安装版本
- sudo apt-cache madison docker-ce
- 查看docker-ce-cli可安装版本
- sudo apt-cache madison docker-ce-cli
//安装指定版本docker
sudo apt-get -y install docker-ce=5:18.09.9~3-0~ubuntu-bionic docker-ce-cli=5:18.09.9~3-0~ubuntu-bionic
//启动docker
systemctl restart docker
//开机自启
systemctl enable docker
-
浏览器访问https://hub.docker.com/
-
搜索需要镜像名
- 选择镜像
- 选择标签,以确认版本信息
- 确认版本,复制安装方法
//下载镜像
docker pull nginx:1.16.1
//查看本地可使用镜像
docker images
//运行镜像
docker run -d -p 80:80 nginx:1.16.1
------------------------------------
-d #后台守护进程运行
-p #做端口映射,将宿主机的端口映射到容器的端口,本地没有会先去官网镜像源查是否有,有就下载,没有会报没有源文件
- 浏览器访问http://192.168.26.207/验证nginx时候正常启动
//查看本地docker容器
docker ps
- 示图
//进入容器,查看系统版本,更新软件源
docker exec -i -t c52cc2615ea9 bash
-i #从标准输入
-t #分配一个伪终端
c52cc2615ea9 #容器id
bash #为容器分配一个shell
- 示图
-
创建测试页面
-
root@c52cc2615ea9:/# echo '<h1>bokebi</h1>' > /usr/share/nginx/html/index.html
-
浏览器访问http://192.168.26.207/
Centos安装Docker方法
//安装必要系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
//添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
//更新软件列表
sudo yum makecache fast
//查看可安装docker版本
sudo yum list docker-ce*
- 示图
//安装docker
sudo yum -y install docker
//安装指定版本网站链接
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/
- 示图
//安装指定版本方法
yum localinstall docker-ce-*
//验证安装的docker版本
docker version
- 示图