centos7 下安装docker
docker 架构:client客户端 docker_host服务 registry远程仓库
docker_host:images 镜像 ;containers 容器
1.删除已经安装的旧版本
[root@localhost /]#
yum remove docker
docker-client
docker-client-latest
docker-common
docker-latest
docker-latest-logrotate
docker-logrotate
docker-engine
2.根据官方文档进行安装
yum install -y yum-utils
设置镜像仓库(这里用的是阿里云的)
yum-config-manager
--add-repo
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新
yum makecache fast
安装docker相关
yum install docker-ce docker-ce-cli containerd.io
启动docker 测试hello-world
启动: systemctl start docker
查看版本: docker version(查看是否启动安装成功)
测试运行hello-world
docker run hello-world(下载镜像并运行)
3卸载依赖
yum remove docker-ce docker-ce-cli containerd.io
删除资源
rm -rf /var/lib/docker
docker 命令学习
docker --help 查看文档
镜像查看:
docker images
docker images -a
docker images -q
下载镜像并运行
docker pull mysql 默认最新版本镜像
指定版本下载
docker pull mysql:5.7
搜索
docker serach mysql
删除 docker rmi 镜像id
容器命令:
下载一个最新版本centos
docker pull centos
docker rm 1f1dc26dcdf0 //删除容器
启动:
docker run [可选参数] images
--name="name" 容器名称用来区分容器
-d 后台方式运行
-it 使用交互方式运行,进入容器查看内容
-p 指定容器的端口 -p8080:8080
-p ip:主机端口:容器端口
-P 主机端口:容器端口(常用)
-p 容器端口
-p 随机指定端口
、
demo 启动进入容器
docker run -it centos /bin/bash
docker start 容器id
stop 停止
restart 重启
kill 强制停止
其他常用命令:
docker run -d centos 后台启动了
docker ps 却没有 被停掉了 因为没有前台进程
查看日志命令:
docker logs
docker logs -tf --tail 服务id/条数
docker logs -tf --tail 条数 服务id
查看容器中的进程信息
docker top 容器id
查看镜像的元数据
docker inspect 镜像id
(后台运行后)进入正在运行的命令
1.docker exec -it 容器id /bin/bash 打开新的终端命令行 常用
2. docker attach 容器id 不会启动新的进程 正在执行当前的代码
容器数据的拷贝到物理机考出
docker cp 容器id:容器内路径 当前路径