dockerfile

dockerfile文件

以centos7.9为基础镜像构建nginx方向代理

dockerfile 复制代码
# 使用官方的CentOS 7.9基础镜像
FROM centos:7.9.2009

# 设置维护者信息
LABEL maintainer="dan"
# 备份yum源
RUN  mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 下载国产yum源
RUN  curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 更新yum源
RUN yum clean all && yum makecache

# 创建非特权用户 
RUN groupadd -r nginx && useradd -r -g nginx -s /sbin/nologin nginx 
 
# 拷贝Nginx
COPY nginx /usr/local/nginx
RUN chmod +x /usr/local/nginx/sbin/nginx

RUN chmod -R 755 /usr/local/nginx/logs && chown -R nginx:nginx /usr/local/nginx 
 
WORKDIR /usr/local/nginx/sbin
 
VOLUME /usr/local/nginx/conf /usr/local/nginx/logs

# 暴露端口8099
EXPOSE 8099

# 设置容器启动时执行的命令
USER nginx 
CMD ["./nginx", "-g", "daemon off;"]

构建镜像

bash 复制代码
# 在dockerfile文件目录下构建
docker build -t 镜像名:镜像版本 .
# 在dockerfile文件目录下,不适用缓存构建
docker build --no-cache -t 镜像名:镜像版本 .

试运行镜像看能否达到要求

bash 复制代码
docker run -it --rm -p 宿主机端口:容器端口 -v 宿主机目录:容器目录 镜像名:镜像版本 /bin/bash
相关推荐
小白的码BUG之路8 分钟前
Docker -- 构建redis镜像
运维·docker·容器
吴声子夜歌15 分钟前
Nginx应用与运维——Nginx Web服务应用实战(HTTPS安全服务器的搭建)
运维·前端·nginx
江湖有缘25 分钟前
Docker实战 | 使用Docker部署EspoCRM开源客户关系管理平台
docker·容器·开源
wdfk_prog26 分钟前
Wi-Fi Direct 源码分析(09):从 P2P_CONNECT 到 GO Negotiation 完成
运维·服务器·ubuntu·golang·asp.net·p2p·wifi-direct
忆挽篱笙歌27 分钟前
linux开发工具
linux·运维·ubuntu
吴声子夜歌30 分钟前
Nginx应用与运维——Nginx Web服务应用实战(伪流媒体服务器的搭建)
运维·前端·nginx
Lsetea1 小时前
OpenSSL verify报certificate signature failure:error 7与证书签名排查
运维·https·ssl证书·openssl·证书链
吴声子夜歌1 小时前
Nginx应用与运维——Nginx Web服务应用实战(HTTP增强协议服务器的搭建)
运维·前端·nginx
小白的码BUG之路1 小时前
Docker -- 构建ruoyi-auth镜像
运维·docker·容器
我叫洋洋3 小时前
涂鸦 T5+ hashcat 自动化破解 WPA2:从单缺 M2 到全自动值守的踩坑实录 破解wifi 密码
运维·单片机·自动化