惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
B
Blog RSS Feed
小众软件
小众软件
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 聂微东
博客园_首页
B
Blog
雷峰网
雷峰网
S
SegmentFault 最新的问题
N
Netflix TechBlog - Medium
D
Docker
博客园 - 司徒正美
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
U
Unit 42
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
腾讯CDC
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
Jina AI
Jina AI
WordPress大学
WordPress大学
D
DataBreaches.Net
V
V2EX
V
Visual Studio Blog
Know Your Adversary
Know Your Adversary
P
Privacy & Cybersecurity Law Blog
F
Full Disclosure
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
The Hacker News
The Hacker News
Security Archives - TechRepublic
Security Archives - TechRepublic
IT之家
IT之家
P
Privacy International News Feed

Alpine Linux

Alpine 3.23 发布了 AlpineLinux 3.19 发布了 Why AlpineLinux - V2EX 在 iOS 上安装了 iSH,大家有什么推荐的玩法吗? - V2EX AlpineLinux 3.12 发布 - V2EX alpine Linux 跑 docker? Docker 容器中基于 Alpine Linux 镜像, kill 命令不起作用? - V2EX 有牛人么? alpine 改用 networkmanager 问题。 docker 的 alpine 不支持 i18n,对 Java 后端开发有啥影响吗? - V2EX 请教 alpine 大牛如何在 alpine 使用 curl 安装 caddy,并添加服务到自启动 - V2EX Alpine Linux 如何安装 Google TCP-BRR 加速? - V2EX 既然 alpine 体积这么小,为什么其它软件官方镜像不把它作为基础镜像? - V2EX 小型系统,用 alpine Linux 真真是极好的。 - V2EX 分享两份自己用的 alpine-php-fpm 的 Dockerfile - V2EX Alpine Linux 大法好!这个没有 GNU, Systemd 和其他莫名的系统,这个简洁、基于脚本的系统,在我折腾 Linux 一年时,让我真正体验到 Unix 系统的精神和原理。 - V2EX
在用 alpine 构建一个运行静态编译的 nginx 的 docker 镜像时遇到的用户问题 - V2EX
fourstring · 2018-12-08 · via Alpine Linux

这是一个创建于 2745 天前的主题,其中的信息可能已经有所发展或是发生改变。

Dockerfile 如下:

FROM ubuntu:latest AS build
LABEL author="fourstring"

ARG NGINX_VER=1.15.7
ARG NGINX_URL=http://nginx.org/download/nginx-${NGINX_VER}.tar.gz
ARG OPENSSL_VER=1.1.1a
ARG OPENSSL_URL=https://www.openssl.org/source/openssl-${OPENSSL_VER}.tar.gz
ARG PCRE_VER=8.42
ARG PCRE_URL=https://ftp.pcre.org/pub/pcre/pcre-${PCRE_VER}.tar.gz
ARG ZLIB_VER=1.2.11
ARG ZLIB_URL=https://zlib.net/zlib-${ZLIB_VER}.tar.gz
ARG NGINX_BUILD_PARAS='--prefix=/usr/local/nginx --with-cc-opt=-static --with-ld-opt=-static --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --with-openssl=../openssl-${OPENSSL_VER} --with-pcre=../pcre-${PCRE_VER} --with-pcre-jit --with-zlib=../zlib-${ZLIB_VER}'
ARG APT_PACKAGES='build-essential wget tar upx'
ARG APT_REMOVE_PACKAGES='build-essential upx'
ARG MAX_THREADS=3

RUN groupadd -g 50000 www && \
    useradd -g 50000 -u 50000 -s /sbin/nologin www

RUN apt -y update && \
    apt -y install ${APT_PACKAGES} && \
    cd /usr/local/src && \
    wget ${ZLIB_URL} && \
    wget ${PCRE_URL} && \
    wget ${OPENSSL_URL} && \
    wget ${NGINX_URL} && \
    tar xzf nginx-${NGINX_VER}.tar.gz && \
    tar xzf openssl-${OPENSSL_VER}.tar.gz && \
    tar xzf zlib-${ZLIB_VER}.tar.gz && \ 
    tar xzf pcre-${PCRE_VER}.tar.gz && \
    cd nginx-${NGINX_VER} && \
    ./configure ${NGINX_BUILD_PARAS} && \
    make -j${MAX_THREADS} && \
    make install && \
    upx /usr/local/nginx/sbin/nginx && \
    mkdir -p /usr/local/nginx/conf/vhost 

FROM alpine

RUN adduser -g 50000 -u 50000 -s /sbin/nologin -D -H www 

COPY --from=build --chown=www:www /usr/local/nginx /usr/local/nginx
COPY nginx.conf /usr/local/nginx/conf
COPY xxx.conf /usr/local/nginx/conf/vhost

EXPOSE 80
EXPOSE 443
USER www
CMD [ "/usr/local/nginx/sbin/nginx","-g","daemon off;" ]

现在遇到了一些诡异的用户问题。

  1. 如果我不使用最后的USER www指令,那么会报错getpwnam("www") (No such file or directory),由于一般使用不存在的用户运行 nginx 的报错并不会出现(No such file or directory),我用 Google 搜索后找到一个解释说当使用指定的用户以外的用户运行 nginx 就会出现这个错误,加USER www指令后这个报错确实也消失了
  2. 但是由于使用低权限运行,nginx 无法使用 80 和 443 端口
  3. 1.里面提到的那个解释我也表示存疑,因为一般情况下 nginx 主进程需要以高权限开启,并不会报这样的错误

那么请问我应该如何处理这个用户问题?还是我对 Linux 或者 nginx 用户机制的理解有问题呢?谢谢

fourstring

1

fourstring      2018 年 12 月 8 日

另外直接使用 nobody 和 nogroup 运行也依然会出现上面的问题

Lax

2

Lax      2018 年 12 月 8 日   ❤️ 1

看一下执行命令时的工作目录是什么。
手上没环境没法现在测了

fourstring

3

fourstring      2018 年 12 月 8 日

@Lax #2 把 CMD 换成了 pwd 命令,返回结果就是根目录

zbinlin

4

zbinlin      2018 年 12 月 8 日   ❤️ 1

去掉
RUN groupadd -g 50000 www && \
useradd -g 50000 -u 50000 -s /sbin/nologin www

RUN adduser -g 50000 -u 50000 -s /sbin/nologin -D -H www

这两句,再把 `--chown=www:www` 也去掉,试试,还有 `USER www`

fourstring

5

fourstring      2018 年 12 月 9 日

@zbinlin #4 nginx: [emerg] getpwnam("nobody") failed (2: No such file or directory)
我觉得有点奇怪,如果说用自定义的用户不行的话为啥 nobody 也不行呢?我一开始怀疑是不同镜像里 uid 不一样,但是后来手动打开 ubuntu 和 alpine 镜像发现 nobody 用户的 uid 和 gid 都是一样的