FROM centos:7.9.2009
ENV TZ=Asia/Shanghai
RUN yum install -y epel-release https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm && yum install -y --setopt=tsflags=nodocs nginx redis mariadb-devel python36 python36-devel openldap-devel supervisor git gcc wget unzip net-tools sshpass rsync sshfs && yum -y clean all --enablerepo='*'
RUN pip3 install --no-cache-dir --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/
RUN pip3 install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ \
gunicorn \
mysqlclient \
cryptography==36.0.2 \
apscheduler==3.7.0 \
asgiref==3.2.10 \
Django==2.2.28 \
channels==2.3.1 \
channels_redis==2.4.1 \
paramiko==2.11.0 \
django-redis==4.10.0 \
requests==2.22.0 \
GitPython==3.0.8 \
python-ldap==3.4.0 \
openpyxl==3.0.3 \
user_agents==2.2.0
RUN localedef -c -i en_US -f UTF-8 en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
RUN echo -e '\n# Source definitions\n. /etc/profile\n' >> /root/.bashrc
RUN mkdir -p /data/repos
COPY init_spug /usr/bin/
COPY nginx.conf /etc/nginx/
COPY ssh_config /etc/ssh/
COPY spug.ini /etc/supervisord.d/
COPY redis.conf /etc/
COPY entrypoint.sh /
VOLUME /data
EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"]
好的,下面是每条指令的中文解释:
FROM centos:7.9.2009
使用CentOS 7.9.2009作为基础镜像。
ENV TZ=Asia/Shanghai
设置系统时区为Asia/Shanghai。
RUN yum install -y epel-release https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm && yum install -y --setopt=tsflags=nodocs nginx redis mariadb-devel python36 python36-devel openldap-devel supervisor git gcc wget unzip net-tools sshpass rsync sshfs && yum -y clean all --enablerepo='*'
安装epel-release和endpoint-repo.x86_64.rpm源,并使用yum安装多个软件包,包括Nginx、Redis、MariaDB开发库、Python 3.6及其开发头文件、OpenLDAP开发头文件、Supervisor、Git、GCC、Wget、Unzip、Net-tools、sshpass、rsync、sshfs等。安装完成后,清理yum缓存。
RUN pip3 install --no-cache-dir --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/
升级pip到最新版本,并使用阿里云镜像源安装Python包。
RUN pip3 install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ \
gunicorn \
mysqlclient \
cryptography==36.0.2 \
apscheduler==3.7.0 \
asgiref==3.2.10 \
Django==2.2.28 \
channels==2.3.1 \
channels_redis==2.4.1 \
paramiko==2.11.0 \
django-redis==4.10.0 \
requests==2.22.0 \
GitPython==3.0.8 \
python-ldap==3.4.0 \
openpyxl==3.0.3 \
user_agents==2.2.0
使用阿里云镜像源安装多个Python包,包括Gunicorn、MySQLClient、Cryptography、APScheduler、asgiref、Django、Channels、Channels Redis、Paramiko、Django Redis、Requests、GitPython、python-ldap、openpyxl和user_agents。
RUN localedef -c -i en_US -f UTF-8 en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
RUN echo -e '\n# Source definitions\n. /etc/profile\n' >> /root/.bashrc
设置系统的locale为en_US.UTF-8,并将其设置为环境变量LANG和LC_ALL的值。同时,在root用户的.bashrc文件中添加一个指令,以便在bash shell中可以访问/etc/profile中定义的变量。
RUN mkdir -p /data/repos
COPY init_spug /usr/bin/
COPY nginx.conf /etc/nginx/
COPY ssh_config /etc/ssh/
COPY spug.ini /etc/supervisord.d/
COPY redis.conf /etc/
COPY entrypoint.sh /
创建一个目录/data/repos,并将文件init_spug复制到/usr/bin目录中。将文件nginx.conf、ssh_config、spug.ini和redis.conf分别复制到/etc/nginx/、/etc/ssh/、/etc/supervisord.d/和/etc/目录中。将文件entrypoint.sh复制到根目录中。
VOLUME /data
EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"]
设置卷/data和将容器的80端口暴露给主机。使用entrypoint.sh作为容器启动时的入口点。