1、dockerfile构建nginx镜像,准备nginx.repo文件
[root@localhost dockerfile]# cat nginx.repo [nginx] name = nginx repo baseurl = http://nginx.org/packages/centos/7/$basearch/ enabled = 1 gpgcheck = 0 [root@localhost dockerfile]#
2、编写dockerfile文件
[root@localhost dockerfile]# cat dockerfile FROM centos:centos7 MAINTAINER MichselHo COPY nginx.repo /etc/yum.repos.d/ RUN yum install -y nginx EXPOSE 80 CMD ["nginx","-g","daemon off;"] [root@localhost dockerfile]#
3、要确保这两个文件在同一个目录下
[root@localhost dockerfile]# ls dockerfile nginx.repo
4、通过docker build构建镜像
[root@localhost dockerfile]# docker build -t nginx:v3 . [+] Building 23.3s (8/8) FINISHED => [internal] load build definition from dockerfile 1.0s => => transferring dockerfile: 242B 0.0s => [internal] load .dockerignore 0.7s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/centos:centos7 19.1s => [internal] load build context 0.5s => => transferring context: 91B 0.0s => [1/3] FROM docker.io/library/centos:centos7@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4 0.0s => CACHED [2/3] COPY nginx.repo /etc/yum.repos.d/ 0.0s => CACHED [3/3] RUN yum install -y nginx 0.0s => exporting to image 0.2s => => exporting layers 0.0s => => writing image sha256:14be8875682a93dda41826c2c4f95b60a338ea0d4e9dad2aa993130784c3f370 0.1s => => naming to docker.io/library/nginx:v3 0.1s [root@localhost dockerfile]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql 8.0 041315a16183 11 days ago 565MB nginx v3 14be8875682a 2 weeks ago 426MB [root@localhost dockerfile]#