Containers-Best Practices PDF
Containers-Best Practices PDF
May 2020
Reference: https://docs.openshift.com/enterprise/3.0/creating_images/guidelines.html
But then…
FROM bitnami/minideb:buster
LABEL maintaner "Juan Ariza Toledano <[email protected]>"
EXPOSE 80 443
ENTRYPOINT ["nginx"]
CMD ["-c", "/etc/nginx/nginx.conf", "-g", "daemon off;"]
FROM bitnami/minideb:buster
LABEL maintaner "Juan Ariza Toledano <[email protected]>"
EXPOSE 80 443
USER 1001
ENTRYPOINT ["nginx"]
CMD ["-c:", "/etc/nginx/nginx.conf", "-g", "daemon off;"]
EXPOSE 80 443
USER 1001
$ docker run --rm --name nginx --publish 8080:8080 --user 1002 my-nginx:v4
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13:
We have a non-root NGINX
Permission denied)
2020/04/23 11:25:48 [warn] 1#1: the "user" directive makes sense only if the master container, great!!
process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2020/04/23 11:25:48 [emerg] 1#1: mkdir() "/var/lib/nginx/body" failed (13: Permission
denied)
But does it support arbitrary
UIDs?
apt-get upgrade -y && \
rm -r /var/lib/apt/lists /var/cache/apt/archives
EXPOSE 8080
USER 1001
if ! whoami &> /dev/null; then You can use this library to Unless the application requires
if [ -w /etc/passwd ]; then
echo "${USER_NAME:-default}:x:$(id dynamically define custom a valid username, don’t do
-u):0:${USER_NAME:-default}
user:${HOME}:/bin/bash" >> /etc/passwd
passwd and group files. anything
fi
fi Pros: Pros:
• You don’t need to edit /etc/passwd • 100% compatible with arbitrary UIDs
• 100% compatible with arbitrary UIDs • The non-root user still needs writing • An “ugly” prompt
permission in the custom passwd
Cons: and group files
• Very insecure
https://github.com/juan131/dockerfile-best-practices