Dockerfile制作Nginx应用镜像

文章目录

使用Dockerfile制作基于Centos7的Nginx应用镜像

创建Dockerfile

dockerfile 复制代码
FROM centos:7
MAINTAINER "WWW"
RUN yum install -y http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.24.0-1.el7.ngx.x86_64.rpm
COPY dest/index.html /usr/share/nginx/html/
EXPOSE 80/tcp
ENTRYPOINT ["nginx", "-g", "daemon off;"]

创建镜像

bash 复制代码
#目录结构
[root@docker nginx]# tree /root/dockerfile/
/root/dockerfile/
└── nginx
    ├── dest
    │   └── index.html
    └── Dockerfile

[root@docker nginx]# docker build -t centos:v1.1 ./
[root@docker nginx]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
centos       v1.1      90714e48dcba   2 minutes ago   431MB

上传镜像-harbor

修改hosts文件

bash 复制代码
[root@docker nginx]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.110.139 www.kvm.cn

修改daemon.json

json 复制代码
{
  "registry-mirrors": ["https://hnjwpdu9.mirror.aliyuncs.com"],
  "insecure-registries": ["www.kvm.cn"]
}

重启DOCKER

bash 复制代码
[root@docker nginx]# systemctl restart docker.service

登录并上传

bash 复制代码
[root@docker nginx]# docker login www.kvm.cn
Username: admin
Password: 
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@docker nginx]# docker push www.kvm.cn/library/centos7:v1.1 
The push refers to repository [www.kvm.cn/library/centos7]
125496b805c2: Pushed 
5efa92506a53: Pushed 
174f56854903: Pushed 
v1.1: digest: sha256:8cef5e2c8b505441ed50380961288c4f82d727cb34f0590bd2f2ebad6e820c25 size: 948

测试镜像

bash 复制代码
[root@docker nginx]# docker run -d --name centos7v1.1 www.kvm.cn/library/centos7:v1.1 
8220d8c238c1d865fd896fc66b972d3394fd84fff3b887424021c5de45345cac
[root@docker nginx]# docker ps
CONTAINER ID   IMAGE                             COMMAND                  CREATED         STATUS         PORTS     NAMES
8220d8c238c1   www.kvm.cn/library/centos7:v1.1   "nginx -g 'daemon of..."   5 seconds ago   Up 5 seconds   80/tcp    centos7v1.1
[root@docker nginx]# docker exec -it centos7v1.1 /bin/bash
[root@8220d8c238c1 /]# cat /usr/share/nginx/html/index.html 
Nginx Web Test
[root@docker nginx]# curl 172.17.0.2
Nginx Web Test
相关推荐
码农小白猿27 分钟前
IACheck优化电梯定期检验报告:自动化术语审核提升合规性与效率
大数据·运维·人工智能·ai·自动化·iacheck
huoxingwen29 分钟前
Ubuntu 22.04 上 VMware Workstation 点击虚拟机窗口就消失的解决历程
linux·运维·ubuntu
姚青&1 小时前
Linux 常用命令之基本命令
linux·运维·服务器
G_H_S_3_1 小时前
【网络运维】企业级监控平台Zabbix:部署与实践指南
linux·运维·网络·zabbix
小周学学学1 小时前
Vcenter Auto Deploy安装与使用
linux·运维·服务器
MZWeiei1 小时前
docker save/load VS docker export/import
docker·容器
VekiSon2 小时前
Linux网络编程——IO多路复用
linux·运维·网络
乐维_lwops2 小时前
IT运维的核心目标和主要工作内容
运维·网络·it运维
云老大TG:@yunlaoda3602 小时前
华为云国际站代理商运维保障的具体要求有哪些?
大数据·运维·华为云
❀͜͡傀儡师2 小时前
Docker安装SQL Server并使用Navicat远程连接
运维·docker·容器