一、在linux虚拟机上安装docker
1、检查内核版本,必须是3.10及以上
uname ‐r
2、安装docker
yum install docker
3、输入y确认安装
4、启动docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker ‐v
Docker version 1.12.6, build 3e8e77d/1.12.6
5、开机启动docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi‐user.target.wants/docker.service to
/usr/lib/systemd/system/docker.service.
6、停止docker
systemctl stop docker
附录常用命令:
1.镜像操作
操作 | 命令 | 说明 |
检索 | docker search 关键字 eg:docker search redis | 我们经常去docker hub上检索镜像信息,如镜像的TAG |
拉取 | docker pull 镜像名:tag | :tag是可选的,tag表示标签,多为软件的版本,默认是latest |
列表 | docker images | 查看所有的本地镜像 |
删除 | docker rmi image-id | 删除指定的本地镜像 |
2.容器操作
软件镜像(QQ安装程序)----运行镜像----产生一个容器(正在运行的软件,运行的QQ);步骤:
1、搜索镜像
[root@localhost ~]# docker search tomcat
2、拉取镜像
[root@localhost ~]# docker pull tomcat
3、根据镜像启动容器
docker run ‐‐name mytomcat ‐d tomcat:latest
4、docker ps
查看运行中的容器
5、 停止运行中的容器
docker stop 容器的id
6、查看所有的容器
docker ps ‐a
7、启动容器
docker start 容器id
8、删除一个容器
docker rm 容器id
9、启动一个做了端口映射的tomcat
[root@localhost ~]# docker run ‐d ‐p 8888:8080 tomcat
‐d:后台运行
‐p: 将主机的端口映射到容器的一个端口 主机端口:容器内部的端口
10、为了演示简单关闭了linux的防火墙
service firewalld status ;查看防火墙状态
service firewalld stop:关闭防火墙
11、查看容器的日志
docker logs container‐name/container‐id
更多命令参看
https://docs.docker.com/engine/reference/commandline/docker/
可以参考每一个镜像的文档
一般正常情况就会安装成功.
但是我在安装docker的时候,就遇到了问题。安装完以后,启动报错
[root@bogon ~]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2019-09-25 16:02:32 CST; 19s ago
Docs: http://docs.docker.com
Process: 2268 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)
Main PID: 2268 (code=exited, status=1/FAILURE)
Sep 25 16:02:29 bogon systemd[1]: Starting Docker Application Container Engine...
Sep 25 16:02:29 bogon dockerd-current[2268]: time="2019-09-25T16:02:29.893186084+08:00" level=warning msg="could not change group /var/run/docker.sock to docker: group docker not found"
Sep 25 16:02:29 bogon dockerd-current[2268]: time="2019-09-25T16:02:29.903117120+08:00" level=info msg="libcontainerd: new containerd process, pid: 2273"
Sep 25 16:02:32 bogon dockerd-current[2268]: Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a newer kernel or disable selinux in docker (--se...-enabled=false)
Sep 25 16:02:32 bogon systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Sep 25 16:02:32 bogon systemd[1]: Failed to start Docker Application Container Engine.
Sep 25 16:02:32 bogon systemd[1]: Unit docker.service entered failed state.
Sep 25 16:02:32 bogon systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
后来通过一系列操作进行成功启动:
1.防火墙和selinux都关了(可以参考上一篇文章Centos7防火墙和selinux问题)
2.修改/etc/docker/daemon.json这个文件(就这样粘贴复制,别多逗号)
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
3.重启docker,在不行重启虚拟机(直接建议重启虚拟机,因为selinux修改后需要重启才能生效)
systemctl daemon-reload
systemctl restart docker