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
設置構建文件
在這里插入代碼片