生产案例:基于 Ubuntu 基础镜像制作 Nginx 镜像
[root@ubuntu2404 ~]
[root@ubuntu2404 ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 24.04 a04dc4851cbc 8 weeks ago 78.1MB
[root@ubuntu2404 ~]
[root@ubuntu2404 ~]
[root@ubuntu2404 1.26-ubuntu2404]
[root@ubuntu2404 1.26-ubuntu2404]
[root@ubuntu2404 1.26-ubuntu2404]
[root@ubuntu2404 1.26-ubuntu2404]
FROM ubuntu:24.04
LABEL maintainer="caoge <ywxe@aliyun.com>"
COPY sources.list /etc/apt/sources.list.d/ubuntu.sourcesRUN apt update&& apt install -y nfs-kernel-server nfs-common gcc openssh server lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev unzip zip make
ADD nginx-1.26.3.tar.gz /usr/local/src
WORKDIR /usr/local/src/nginx-1.26.3
RUN ./configure --prefix=/apps/nginx && make && make install && ln -s /apps/nginx/sbin/nginx /usr/bin && rm -rf /usr/local/src/nginx-1.26.3*
ADD nginx.conf /apps/nginx/conf/nginx.conf
ADD index.html /data/nginx/html/index.html
RUN groupadd -g 2019 nginx && useradd -g nginx -s /usr/sbin/nologin -u 2019 nginx && chown -R nginx:nginx /apps/nginx /data/nginx
EXPOSE 80 443
CMD ["nginx"]
[root@ubuntu2404 1.26-ubuntu2404]
TAG=$1
docker build -t nginx-ubuntu:$TAG .
[root@ubuntu2404 1.26-ubuntu2404]
build.sh Dockerfile index.html nginx-1.26.3.tar.gz nginx.conf sources.list
[root@ubuntu2404 1.26-ubuntu2404]
[root@ubuntu2404 1.26-ubuntu2404]
[root@ubuntu2404 1.26-ubuntu2404]
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-ubuntu v1.1 99951e989855 46 seconds ago 525MB
[root@ubuntu2404 1.26-ubuntu2404]
a527c7f3e2c874c18780dba78df40aea1223710b382d1464e288389cc1445dcc
[root@ubuntu2404 1.26-ubuntu2404]
hello nginx-ubuntu2404
[root@ubuntu2404 1.26-ubuntu2404]
hello nginx-ubuntu2404
[root@ubuntu2404 1.26-ubuntu2404]
root@a527c7f3e2c8:/usr/local/src/nginx-1.26.3
/data/nginx/html/index.html
root@a527c7f3e2c8:/usr/local/src/nginx-1.26.3
hello nginx-ubuntu2404
root@a527c7f3e2c8:/usr/local/src/nginx-1.26.3
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 4548 3072 ? Ss 05:37 0:00 nginx: master process nginx
nginx 7 0.0 0.0 6344 3568 ? S 05:37 0:00 nginx: worker process
root 8 0.0 0.0 4588 3840 pts/0 Ss 05:37 0:00 bash
root 18 0.0 0.1 7888 4096 pts/0 R+ 05:38 0:00 ps aux
root@a527c7f3e2c8:/usr/local/src/nginx-1.26.3
exit