文章目录
1.安装过程如下
- 查看内核版本(3.10.0以上)
- 更新yum源
yum update
- 执行安装命令
curl – sSL https://get.docker.com/ | sh
- 查看安装版本
docker -v
- 允许开机启动Docker服务
systemctl enable docker
- 安装过程中可能出现的问题
我的OS是Ubuntu 16.04.6 LTS
(1)安装过程中出现:Could not get lock /var/lib/dpkg/lock问题,解决办法如下:
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it
执行命令,将相应的lock文件删除即可
rm -rf /var/cache/apt/archives/lock
rm -rf /var/lib/dpkg/lock
参考:https://www.jianshu.com/p/6e4f16cf6398
(2)配置阿里云镜像加速,因为从docker自己的仓库pull镜像太慢了
首先在:https://cr.console.aliyun.com/cn-hangzhou/mirrors,申请一个账号;
接着按照页面里面的镜像加速器进行配置即可;
参考:https://blog.csdn.net/weixin_37173488/article/details/99694586
配置完毕后,ubuntu结果如下:
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://s2k2mqwz.mirror.aliyuncs.com/
Live Restore Enabled: false
2.Docker服务
- (1)启动Docker服务
service docker start 或者systemctl start docker
- (2)查看Docker服务状态
service docker status 或者systemctl status docker
- (3)停止Docker服务
service docker stop 或者systemctl stop docker
3.镜像操作
- (1)搜索镜像
docker search 关键字 ;关键字不能为空
eg:docker search hello-world
- (2)拉取镜像
docker pull 镜像名
eg:docker pull hello-world
-(3)查看镜像
docker images
- (4)删除镜像
docker rmi 镜像名:tag/镜像ID
eg:docker rmi hello-world:latest
3.容器操作
- (1)创建容器
docker run [选项] 镜像名:tag/镜像ID 要执行的命令
-i:交互模式
-t:打开一个虚拟终端,-i一起使用
-d:后台运行,打开-d,就不要用-i和-t
--name:容器自定义名称
ctrl p+q:表示容器在后台运行
exit:表示真正的退出,不要轻易使用
eg:docker run -i -t --name=wangji1 ubuntu /bin/bash
2、查看容器
docker ps [选项]
3、 启动和停止容器
docker start/stop 容器名/容器ID
eg:stop ubuntu容器结果如下:
4、删除容器
docker rm [选项] 容器名/容器ID
-f:删除正在运行的容器
eg:删除ubuntu容器的结果如下: