dockerfile 指定运行用户案例
Dockerfile : 内容
FROM ubuntu:20.04
RUN useradd -r -s /sbin/nologin -u 2023 baimei
RUN apt-get update && \
apt-get -y install nginx openssh-server curl && \
rm -rf cache
RUN sed -ri 's/(user )www-data/\1baimei/g' /etc/nginx/nginx.conf && \
sed -i 's/80/8080/g' /etc/nginx/sites-enabled/default && \
chmod 777 -R /var/ /run/
# 指定运行服务的用户,该用户必须对服务的相关文件或目录有读或者写的权限
USER baimei
# 配置健康检查
HEALTHCHECK --interval=3s --timeout=1s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/ || exit 1
# CMD ["tail","-f","/etc/hosts"]
CMD ["nginx","-g","daemon off;"]
build.sh 内容
#!/bin/bash
docker build -t baimei-games:v1.$1 .
docker run -d baimei-games:v1.$1
docker ps -l
docker images
docker run -d baimei-games:v1.1
欢迎来撩 : 汇总all