编写Dockerfile制作Web应用系统nginx镜像


文章目录


题目要求:

编写Dockerfile制作Web应用系统nginx镜像,生成镜像nginx:v1.1,并推送其到私有仓库。具体要求如下:

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

一、创建文档,编写Dockerfile文件

css 复制代码
1、创建文档来存放本次需要写入的东西
[root@redhat ~]# mkdir -p dockertest
[root@redhat ~]# 
[root@redhat ~]# cd dockertest/
[root@redhat dockertest]# 
[root@redhat dockertest]# mkidr test1
[root@redhat dockertest]# cd test1/
2、编写一个html的前端文件,内容随便
[root@redhat test1]# vim index.html
[root@redhat test1]# 
[root@redhat test1]# cat index.html 
hello hello hello hello hello hello hello
3、编写Dockerfile
[root@redhat test1]# vim Dockerfile
[root@redhat test1]# cat Dockerfile 
FROM centos   //题目要求从cetenos镜像
MAINTAINER "Tej <Tej@163.com>" //指定的是创建这个镜像的作者信息
ADD http://nginx.org/download/nginx-1.24.0tar.gz /usr/local/src  //类似于copy指令,支持使用TAR文件和URL路径
COPY index.html /usr/share/nginx/  // 从上下文目录中复制文件或目录到容器里指定的路径
EXPOSE 80 // 端口号为80端口
CMD ["/usr/sbin/nginx","-g","daemon off"] // CMD指令的首要目的在于为启动的容器指定默认要运行的程序,且其运行结束后,容器也将终止;不过,CMD指定的命令可以被docker run的命令行选项所覆盖

可以将harbor仓库去启动先起来

css 复制代码
[root@redhat ~]# cd /usr/local/harbor/
[root@redhat harbor]# ls
common     docker-compose.yml    harbor.yml       install.sh  prepare
common.sh  harbor.v2.4.1.tar.gz  harbor.yml.tmpl  LICENSE
[root@redhat harbor]# 
[root@redhat harbor]# ./install.sh 
输入./install.sh 就行,之前的密码和账户都没有发生改变,不要看见remove就急忙退出了,他只是在重新启动,

二、运行Dockerfile,构建nginx镜像

css 复制代码
[root@redhat test1]# vim Dockerfile 
[root@redhat test1]# docker build -t nginx:v1.1 ./
[+] Building 43.8s (9/9) FINISHED   

出现这个界面就表示nginx安装成功了,如果不放心的可以去docker images查看,看镜像是否运行了。

三、推送导私有仓库,也就是我们的harbor仓库

在harbor仓库里新建一个项目, 我这里是叫test1,创建项目就在界面最显眼的地方,下面第一张图就是默认的,第二张就是已经创建好了的。

css 复制代码
#首先登录到私有仓库
[root@node2 demo01]# docker login -u admin -p Harbor12345 192.168.198.200
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
 
Login Succeeded
 
#给镜像打上合适的标签
[root@node2 demo01]# docker tag nginx:v1.1 192.168.198.200/test1/nginx
[root@redhat ~]# docker images | grep test1
192.168.11.131/test1/nginx      v1.1      d24d91713c2d   56 minutes ago   232MB

 
#推送镜像到私有仓库
[root@node2 demo01]# docker push 192.168.198.200/test1/nginx:v1.1
The push refers to repository [192.168.198.200:80/demo01/nginx]
02dfab95c1be: Pushed 
74ddd0ec08fa: Pushed 
v1.1: digest: sha256:888ed81c26b452ff94686c7709f1a6b668aeb2f2f7f80e4225eb83257428a8a7 size: 736
[root@node2 demo01]#

传输完毕!


相关推荐
tangdou3690986553 小时前
Docker系列-5种方案超详细讲解docker数据存储持久化(volume,bind mounts,NFS等)
docker·容器
漫无目的行走的月亮6 小时前
在Docker中运行微服务注册中心Eureka
docker
大道归简9 小时前
Docker 命令从入门到入门:从 Windows 到容器的完美类比
windows·docker·容器
zeruns80210 小时前
如何搭建自己的域名邮箱服务器?Poste.io邮箱服务器搭建教程,Linux+Docker搭建邮件服务器的教程
linux·运维·服务器·docker·网站
爱跑步的程序员~10 小时前
Docker
docker·容器
疯狂的大狗10 小时前
docker进入正在运行的容器,exit后的比较
运维·docker·容器
长天一色11 小时前
【Docker从入门到进阶】01.介绍 & 02.基础使用
运维·docker·容器
伊玛目的门徒11 小时前
docker 搭建minimalist-web-notepad
运维·docker·notepad
theo.wu13 小时前
使用Buildpacks构建Docker镜像
运维·docker·容器
wusam1 天前
螺蛳壳里做道场:老破机搭建的私人数据中心---Centos下Docker学习04(环境准备)
学习·docker·centos