近期docker的镜像仓库不好用了,很多国内的源也无法使用了,所有今天给大家分享一下怎么从零制作一个CentOS镜像。
- mkdir /centos7.9-root
-
- # 在该目录准备centos的最小环境
- sudo yum --installroot=/centos7.9-root --releasever=7 install -y centos-release
- sudo yum --installroot=/centos7.9-root --releasever=7 groupinstall -y "Core"
-
- mkdir centos7
- cd centos7
- mv /centos7.9-root ./
-
- # 编写Dockerfile文件
- # 这是Docker提供的一个相当于是空白的镜像,直接就可以用的不用下载
- cat > Dockerfile << EOF
- FROM scratch
- ADD centos7.9-root /
- CMD ["/bin/bash"]
- EOF
-
- # 构建镜像
- docker build -t centos:7.9 .
- [root@bogon centos7]# docker build -t centos:7.9 .
- [+] Building 33.3s (5/5) FINISHED docker:default
- => [internal] load build definition from Dockerfile 0.0s
- => => transferring dockerfile: 89B 0.0s
- => [internal] load .dockerignore 0.0s
- => => transferring context: 2B 0.0s
- => [internal] load build context 14.5s
- => => transferring context: 1.37GB 14.5s
- => [1/1] ADD centos7.9-root / 7.7s
- => exporting to image 10.9s
- => => exporting layers 10.9s
- => => writing image sha256:359d4c8ae6f4f9d700d847f38066f52344c628789d868e196 0.0s
- => => naming to docker.io/library/centos:7.9 0.0s
- [root@bogon ~]# docker run -it --rm centos:7.9 bash
- [root@c74f76deee3d /]#