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
相关推荐
饿了吃洗衣凝珠7 小时前
shell
linux·运维·服务器
Decay__9 小时前
PostgreSQL 性能调优方法论 —— pg_stat_statements、EXPLAIN ANALYZE、瓶颈定位流程与参数基线
运维·数据库·sql·postgresql
always202212 小时前
AI运行时 · 06 - Kata 与 K8s 集成:RuntimeClass / CSI kata-directvolume / 性能开销与调优
人工智能·容器·kubernetes
stormsha14 小时前
中文路径让 MySQL 起不来:Failed to find valid data directory 与 Illegal byte sequence
运维·数据库·mysql
stormsha14 小时前
MySQL 报 `data directory has files in it`:初始化失败一次,之后就永久起不来
运维·数据库·mysql
csdn_aspnet16 小时前
使用 Docker 配置 PostgreSQL 和 pgAdmin 4
数据库·docker·postgresql·pgadmin4
Maiko Star17 小时前
Docker保姆级部署AI应用程序(FastAPI)
docker·容器·fastapi
沙老师20 小时前
Linux Purification Plan - More Modification
linux·运维·服务器
Decay__21 小时前
PostgreSQL 高可用与容灾架构 —— 流复制、Patroni、Keepalived+VIP、读写分离与两地三中心
运维·数据库·sql·postgresql
A-刘晨阳1 天前
Kubernetes 查询证书有效期及续签证书(适用于二进制部署)
云原生·容器·kubernetes·证书·cfssl