Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise Dockerfile with more best practices #205

Open
hawkrives opened this issue Feb 18, 2021 · 4 comments
Open

Revise Dockerfile with more best practices #205

hawkrives opened this issue Feb 18, 2021 · 4 comments

Comments

@hawkrives
Copy link
Contributor

From https://pythonspeed.com/docker


https://pythonspeed.com/articles/root-capabilities-docker-security/

FROM ubuntu:18.04
RUN useradd --create-home appuser
WORKDIR /home/appuser
USER appuser

https://pythonspeed.com/articles/docker-cache-insecure-images/

Once a week, or every night, rebuild your Docker image from scratch using docker build --pull --no-cache to ensure you have security updates.

@hawkrives
Copy link
Contributor Author

Pin to a specific Debian release as the source docker image

@hawkrives
Copy link
Contributor Author

Make it identifiable: via Docker

The problem with tags is that they’re not embedded into the image. So if you deployed yourimage:latest, you won’t know what other tags it used to have.

One solution is to embed the metadata as labels inside the image itself:

docker build -t myimage:latest --label git-commit=$GIT_COMMIT .

@hawkrives
Copy link
Contributor Author

Make it identifiable: via logs and public API

You can also use build arguments to customize the build; this allows you to pass in the git commit, store it in the image as a file, and then your application can include it in a status API endpoint, or as part of application logging on startup.

FROM centos
ARG git_commit
RUN echo $git_commit > /git-commit.txt
The ARG is a build argument you expect the image to take.

And then we can pass it in:

$ docker build -t myimage --build-arg git_commit=$GIT_COMMIT .
$ docker run -it myimage
$ docker run -ti myimage
[root@6d9d99b56d9b /]# cat /git-commit.txt
45eefe3
Your code can then load git-commit.txt and put it in logs, or include as part of a /status API endpoint.

@hawkrives
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant