docker安装centos
docker库地址https://hub.docker.com/
尝试使用centos7试了几次超时 换了个版本就可以了
docker pull centos:centos7.9.2009
有时候需要更新资源地址 可以使用
vim /etc/docker/daemon.json
配置其他资源地址
{"registry-mirrors": ["http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn","https://cr.console.aliyun.com","https://mirror.ccs.tencentyun.com"]
}
配置后重新加载文件,重启docker生效
systemctl daemon-reload
systemctl restart docker
下载镜像后启动centos
#docker run -it --name 自定义容器名 镜像名:镜像tag /bin/bash
docker run -it --name centostest centos:centos7.9.2009 /bin/bash
进入容器
docker exec -it centostest /bin/bash
#这里:
#-i 保持STDIN开放,即使没有附加也是如此。
#-t 分配一个伪终端。
#my_centos_container 是你的容器的名称或ID。
#/bin/bash 是你想要在容器内部执行的命令,这里是启动一个新的bash会话。
#如果你发现容器中没有安装bash(虽然CentOS镜像通常包含bash),你可以尝试使用/bin/sh来代替:
yum安装mysql时报错(参考https://www.imooc.com/article/315620)
cd /etc/yum/pluginconf.d/
cat -n fastestmirror.conf
sed -i '2s/enabled=1/enabled=0/' fastestmirror.conf
—————————————————————————————
上面的是分步操作,可以合并在Dockerfie文件里面,进行统一管理
mkdir Dockerfile
vim Dockerfile
设置构建文件
在这里插入代码片