释放双眼,带上耳机,听听看~!
编写Dockerfile
进入到/opt下,下载并解压nginx-1.24.0
编译好的软件包
我的软件包也在kylin-server-10系统下build编译的,所以如果是麒麟可以直接使用
下载编译包
cd /opt
wget https://d.frps.cn/file/tools/nginx/nginx-1.24.0.tar.gz
tar xf nginx-1.24.0.tar.gz
- Dockerfile文件如下
vim Dockerfile && Dockerfile需要和nginx-1.24.0在同一目录下
FROM abcdocker9/kylin:10-sp2-b09
WORKDIR /opt
COPY ./nginx-1.24.0 /opt/nginx-1.24.0
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "alias ls='ls --color'" >> ~/.bashrc \
&& echo "alias ll='ls -l'" >> ~/.bashrc \
&& useradd nginx -s /sbin/nologin -M \
&& ln -sf /dev/stdout /opt/nginx-1.24.0/logs/access.log \
&& ln -sf /dev/stderr /opt/nginx-1.24.0/logs/error.log
# 配置环境变量
EXPOSE 80
ENTRYPOINT ["/opt/nginx-1.24.0/sbin/nginx","-g","daemon off;"]
CMD ["-c","conf/nginx.conf"]
构建测试镜像
[root@abcdocker nginx]# docker build -t test:v8 .
Sending build context to Docker daemon 382.8 MB
Step 1/7 : FROM kylin-server-10-sp2-aarch64:b09
---> 907d7ff37c7c
Step 2/7 : WORKDIR /opt
---> Using cache
---> 4f70334717b5
Step 3/7 : COPY ./nginx-1.24.0 /opt/nginx-1.24.0
---> 567136ea0a02
Removing intermediate container d1a0f938cee6
Step 4/7 : RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "alias ls='ls --color'" >> ~/.bashrc && echo "alias ll='ls -l'" >> ~/.bashrc && useradd nginx -s /sbin/nologin -M && ln -sf /dev/stdout /opt/nginx-1.24.0/logs/access.log && ln -sf /dev/stderr /opt/nginx-1.24.0/logs/error.log
---> Running in a39e5cf98d20
---> d6a88909de5f
Removing intermediate container a39e5cf98d20
Step 5/7 : EXPOSE 80
---> Running in a0ab08477493
---> e308ee2c9ad4
Removing intermediate container a0ab08477493
Step 6/7 : ENTRYPOINT /opt/nginx-1.24.0/sbin/nginx -g daemon off;
---> Running in 96a6370f55cc
---> 4240a993bba4
Removing intermediate container 96a6370f55cc
Step 7/7 : CMD -c conf/nginx.conf
---> Running in e5bf93cb441e
---> bb7165c6646c
Removing intermediate container e5bf93cb441e
Successfully built bb7165c6646c
启动镜像测试
#不使用持久化
docker run -itd -p 82:80 --privileged --name=nginx-test-v8-2 test:v8
#挂持久化 (需要在/tmp/nginx/conf/conf.d创建nginx.conf)
docker run -itd -p 82:80 --privileged --name=nginx-test-v8-2 -v /tmp/nginx/conf/conf.d:/opt/nginx-1.24.0/conf/conf.d/ test:v8
查看容器
[root@localhost nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
469d10af7b99 test:v8 "/opt/nginx-1.24.0..." 4 seconds ago Up 3 seconds 0.0.0.0:82->80/tcp nginx-test-v8-2
访问容器测试
[root@localhost nginx]# curl 127.0.0.1:82
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@localhost nginx]# curl 127.0.0.1:82
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
查看访问日志
[root@localhost nginx]# docker logs -f 469d10af7b99
172.17.0.1 - - [06/Nov/2023:10:44:07 +0800] "GET / HTTP/1.1" 200 615 "-" "curl/7.66.0"
172.17.0.1 - - [06/Nov/2023:10:44:08 +0800] "GET / HTTP/1.1" 200 615 "-" "curl/7.66.0"