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
相关推荐
chen94523 分钟前
mysql 3节点mgr集群部署
运维·后端
LH_R1 小时前
OneTerm开源堡垒机实战(三):功能扩展与效率提升
运维·后端·安全
dessler2 小时前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
少妇的美梦20 小时前
logstash教程
运维
容器魔方20 小时前
Bloomberg 正式加入 Karmada 用户组!
云原生·容器·云计算
chen94520 小时前
k8s集群部署vector日志采集器
运维
chen94520 小时前
aws ec2部署harbor,使用s3存储
运维
muyun28001 天前
Docker 下部署 Elasticsearch 8 并集成 Kibana 和 IK 分词器
elasticsearch·docker·容器
東雪蓮☆1 天前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
qq_264220891 天前
LVS负载均衡群集和LVS+Keepalived群集
运维·负载均衡·lvs