安装Docker
1.准备工作
首先启动linux
环境,使用VMware虚拟机软件,操作系统:CentOS
7
使用命令ifconfig
查看当前虚拟机IP地址
使用Xshell
工具连接该虚拟机
新建连接
使用ll
命令展示文件列表或者ls
命令(只显示文件名)
pwd
命令查看当前路径
rm -rf redis-3.0.0.tar.gz
命令删除之前tomcat的压缩包
如果之前安装过旧版本的Docker,可以使用下面命令卸载(选做)
yum remove docker \docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine \ docker-ce
安装yum
工具,用于下载依赖包的,包管理工具,CentOS自带有
yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 --skip-broken
更新本地镜像源:使用阿里云镜像(加速)
yum-config-manager \ --add-repo \ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's/download.docker.com/mirrors.aliyun.com/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
2.开始安装
使用命令yum install -y docker-ce
安装docker
安装完成使用docker -v
查看安装版本
启动docker前,一定要关闭防火墙后!!(关闭虚拟机的防火墙,不然其他端口都是封死状态,无法访问)
# 关闭
systemctl stop firewalld
# 禁止开机启动防火墙
systemctl disable firewalld
通过命令启动docker
# 启动docker服务
systemctl start docker
# 停止docker服务
systemctl stop docker
# 重启docker服务
systemctl restart docker
docker官方镜像仓库网速较差,我们需要设置国内镜像服务:
参考阿里云的镜像加速文档:cr.console.aliyun.com/cn-hangzhou…
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ea7com97.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
3.常见命令
# 查找镜像
docker search 镜像名
# 拉取镜像
docker pull redis:latest(冒号后面是版本号) 不加版本号默认获取最新版本
# 查看镜像
docker images
# 删除镜像
docker rmi 镜像名或id
# 查看所有的容器命令如下:docker ps查看正在运行的容器
docker ps -a
# 启动容器
docker start 容器名/容器id
# docker 的服务是在后台运行 -d 指定容器的运行模式。
docker run -itd --name ubuntu-test ubuntu /bin/bash
# 进入容器内部
docker exec -it 243c32535da7 bash
# 删除容器
docker rm -f 1e560fca3906