Dockerfile: centos,jdk,nginx
可以开启一个对应基础镜像版本的docker,进去测试Dockerfile的命令:
docker run -it --name mycontainer --network=bridge --privileged centos:7.9.2009 bash
docker exec -it a359bc85980d bash
#Dockerfile:
FROM centos:centos7.9.2009 # 安装必要的工具和依赖项 RUN yum install -y curl tar && \ yum clean all && \ rm -rf /var/cache/yum/* # 下载并安装 JDK8u141 RUN curl -LOk --cookie "oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz && \ mkdir -p /usr/java && \ tar -xzf jdk-8u141-linux-x64.tar.gz -C /usr/java && \ rm -f jdk-8u141-linux-x64.tar.gz # 设置环境变量 ENV JAVA_HOME /usr/java/jdk1.8.0_141 ENV PATH $JAVA_HOME/bin:$PATH # 安装 Nginx 1.24 RUN yum install -y epel-release && \ yum install -y nginx && \ yum clean all && \ rm -rf /var/cache/yum/* # 设置 Nginx 配置文件 #COPY nginx.conf /etc/nginx/nginx.conf # 开放 Nginx 端口 EXPOSE 80 # 启动 Nginx 服务 CMD ["nginx", "-g", "daemon off;"]
孙ser给的答案:
FROM centos:centos7.9.2009 RUN yum update -y && yum install -y java-1.8.0-openjdk.x86_64 && yum clean all ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk ENV PATH=$PATH:$JAVA_HOME/bin RUN java -version
FROM centos:centos7.9.2009
RUN yum install -y epel-release \
&& yum install -y wget \
&& yum clean all
RUN cd /tmp \
&& wget http://nginx.org/download/nginx-1.24.0.tar.gz \
&& tar -zxvf nginx-1.24.0.tar.gz
RUN yum install -y gcc \
&& yum install -y pcre-devel \
&& yum install -y openssl-devel \
&& yum install -y zlib-devel \
&& yum install -y make \
&& yum install -y gettext
WORKDIR /tmp/nginx-1.24.0
RUN ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module \
&& make \
&& make install \
&& rm -rf /tmp/nginx* \
&& useradd nginx \
&& mkdir /var/cache/nginx \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& mkdir /docker-entrypoint.d
COPY docker-entrypoint.sh /
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
COPY 30-tune-worker-processes.sh /docker-entrypoint.d
RUN chmod 777 /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

浙公网安备 33010602011771号