Docker容器学习:Dockerfile制作Web应用系统nginx镜像

目录

编写Dockerfile

1.文件内容需求:

2.编写Dockerfile:

3.开始构建镜像

 4.现在我们运行一个容器,查看我们的网页是否可访问

推送镜像到私有仓库

1.把要上传的镜像打上合适的标签

2.登录harbor仓库

3.上传镜像


编写Dockerfile

1.文件内容需求:

  1. 基于centos基础镜像。
  2. 指定作者信息。
  3. 安装nginx服务,将提供的dest目录(提供默认主页index.html)传到镜像内,并将dest目录内的前端文件复制到nginx的工作目录。
  4. 暴露80端口。
  5. 设置服务自启动。验证镜像。

2.编写Dockerfile

[root@node4 web]# pwd
/dockerfile/web
[root@node4 web]# ll
total 8
-rw-r--r-- 1 root root 362 Aug 20 23:23 Dockerfile
-rw-r--r-- 1 root root  36 Aug 20 22:55 index.html

[root@node4 web]# more index.html 
This is a nginx test for Dockerfile

[root@node4 web]# more Dockerfile 
# 基于centos:7基础镜像
FROM centos:7

# 指定作者信息
MAINTAINER "Xcgouge <xcgouge@163.com>"

# 安装nginx
RUN yum -y update && \
    yum -y install epel-release && \
    yum -y install nginx && \
    yum clean all

# 默认主页
COPY index.html /usr/share/nginx/html/

# 暴露端口
EXPOSE 80

# 原神 启动!
CMD ["nginx","-g","daemon off;"]

3.开始构建镜像

[root@node4 web]# docker build -t zly-nginx:v1.1 ./

查看构建结果

[root@node4 web]# docker images | grep zly-nginx
zly-nginx                       v1.1      00e97313c118   29 minutes ago      397MB

 4.现在我们运行一个容器,查看我们的网页是否可访问

[root@node4 web]# docker run --name web -d -p 81:80 zly-nginx:v1.1
783c2c4f17fc9cd48fca5e3bfcdc621385799da7378c1d3779f9b764e77b01f7

浏览器访问

推送镜像到私有仓库

上一篇文章提到如何搭建自己的私有仓库harborDocker容器学习:搭建私有镜像仓库Harbor&操作_一路喝狗狗的博客-CSDN博客

1.把要上传的镜像打上合适的标签

[root@node4 web]# docker tag zly-nginx:v1.1 docker:80/demo/zly-nginx:v1.1
 

注意docker:80/demo/是指定harbor仓库的地址,docker:80是你的镜像仓库地址,/demo/zly-nginx是你想要创建的镜像仓库中的项目和镜像名称(路径),v1.1是新的标签。

2.登录harbor仓库

[root@node4 harbor]# docker login docker:80
Username (admin): admin
Password:
Login Succeeded

3.上传镜像

[root@node4 web]# docker push docker:80/demo/zly-nginx:v1.1 

 

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一路喝狗狗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值