编写Dockerfile制作Web应用系统nginx镜像,生成镜像名为nginx:v1.1,并推送其到私有仓库。
1、基于centos7基础镜像;
2、指定作者为Chinaskill;
3、安装nginx服务,将提供的dest目录传到镜像内,并将dest目录内的前端文件复制到nginx的工作目录;
4、暴露80端口;
5、设置服务自启动。
第一步:开机启动docker服务,编写Dockerfile
[root@localhost nginx]# vim Dockerfile FROM centos:7 MAINTAINER Chinaskill RUN yum install -y epel-release && yum install -y nginx COPY index.html /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
第二步:创建nginx目录,切换到nginx目录输入nginx test page.到index.html文件中
[root@localhost nginx]# ll total 4 -rw-r--r--. 1 root root 177 Mar 14 17:58 Dockerfile [root@localhost nginx]# echo "nginx test page." > index.html [root@localhost nginx]# [root@localhost nginx]# ll total 8 -rw-r--r--. 1 root root 177 Mar 14 17:58 Dockerfile -rw-r--r--. 1 root root 17 Mar 14 18:01 index.html
第三步:构建nginx镜像
[root@localhost nginx]# docker build -t reg.openlab.cn/opelab/nginx:v1 ./ --load [+] Building 5.0s (9/9) FINISHED docker-container:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 277B 0.0s => [internal] load metadata for docker.io/library/centos:7 2.4s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [1/3] FROM docker.io/library/centos:7@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4 0.0s => => resolve docker.io/library/centos:7@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4 0.0s => [internal] load build context 0.0s => => transferring context: 91B 0.0s => CACHED [2/3] RUN yum install -y epel-release && yum install -y nginx0.0s => CACHED [3/3] COPY index.html /usr/share/nginx/html 0.0s => exporting to docker image format 2.5s => => exporting layers 0.0s => => exporting manifest sha256:8df860d4693fa88eda1d7eee03d585aef46080ec8485e64f4893e1f29ee06546 0.0s => => exporting config sha256:9e9b09d588cc320e6a3ba0c99f01137a6df98dd0308be9e613f0e20b1d5b263d 0.0s => => sending tarball 2.5s => importing to docker
第四步:启动容器
[root@localhost nginx]# docker run -d -P reg.openlab.cn/opelab/nginx:v1 fe1369e8838c13dc0dd2cf9596ff175d9128034d65429d06dc2e7e363de38dfd [root@localhost nginx]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fe1369e8838c reg.openlab.cn/opelab/nginx:v1 "nginx -g 'daemon of…" 4 seconds ago Up 3 seconds 0.0.0.0:32768->80/tcp nervous_easley 2c14347c4f15 moby/buildkit:buildx-stable-1 "buildkitd" 15 minutes ago Up 15 minutes buildx_buildkit_default
第五步:根据端口号到浏览器输入IP地址
案例完成!
还没有评论,来说两句吧...