我想以非 root 用户身份运行 postgres 容器。默认情况下,该映像具有用户 postgres (uid 999)。
当通过命令访问容器时docker exec -it mycontainer /bin/bash
,用户是root。
为了使容器更安全,我使用 Dockerfile 创建了一个新映像。我在其中定义了USER postgres
.
够了吗?更改权限是否有趣/usr/local/bin/docker-entrypoint.sh
对于用户 postgres?
简单的 docker-compose.yml:
version: "2.4"
services:
db:
container_name: mycontainer
hostname: mycontainer
restart: always
volumes:
- postgres_data:/var/lib/postgresql/data/
networks:
- default
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
build: .
image: mycontainer:1.0
volumes:
postgres_data:
networks:
default:
简单的 Dockerfile:
FROM postgres:14.1-bullseye
#Assessing whether this parameter is needed.
#RUN chown postgres:postgres /usr/local/bin/docker-entrypoint.sh
USER postgres
使用的链接:
https://github.com/docker-library/repo-info/blob/master/repos/postgres/remote/12-bullseye.md https://github.com/docker-library/repo-info/blob/master/repos/postgres/remote/12-bullseye.md
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)