Repository navigation
Description
There are multiple improvements we could do to the current Dockerfile that runs coder server.
- Drop privileges from
root(e.g.nobody, or a system user) - Move cache directory from
/tmpto aVOLUME(CODER_CACHE_DIRECTORY, note Cache directory env variable forcoder serveris missingCODER_prefix #2199) - Put
coderinPATH(e.g./opt=>/usr{/local,}/bin) - Mount
tmpfsonto/tmpto avoid issues if container is run with read-only filesystem- This change would most likely only be done in our
docker-compose.yaml
- This change would most likely only be done in our
- Change
ENTRYPOINTto["coder"](only) and addCMD ["server"](alternativelyCMD ["coder", "server"]only) - Considering installing Terraform on the system level
Drop privileges from root (e.g. nobody, or a system user)
It's best practice to run with as few permissions as possible. If we need to perform some initialization as root, we should consider dropping privileges afterwards e.g. via gosu, su-exec, or similar.
Move cache directory from /tmp to a VOLUME (CODER_CACHE_DIRECTORY, note #2199)
It'd make sense for the cache directory to persist across server restarts (the assumption for /tmp should always be that it does not persist). Without this change, a server restart is not guaranteed to be successful if there are network issues or a problem downloading TF.
Put coder in PATH (e.g. /opt => /usr{/local,}/bin)
We probably want users to be able to use the coder binary in the image, this is now slightly awkward (esp. with need to modify entrypoint as well):
docker run -it --rm -v /home/user/.config/coderv2:/home/user/.config/coderv2 --entrypoint /opt/coder ghcr.io/coder/coder:v0.6.4-amd64 login https://...
Mount tmpfs onto /tmp to avoid issues if container is run with read-only filesystem
Best practice to not write onto non-volumes on container filesystem, for security reasons users may choose to have it read-only.
Change ENTRYPOINT to ["coder"] (only) and add CMD ["server"] (alternatively CMD ["coder", "server"] only)
Makes it easier to user coder from within the Docker image:
docker run -it --rm --entrypoint /bin/sh ghcr.io/coder/coder:v0.6.4-amd64
# coder login https://...
Considering installing Terraform on the system level
This allows us to better tie Coder releases to Terraform versions. The idea behind Docker images is that once they're built, they always work and are immutable. This is not the case when we rely on network and downloading binaries at runtime.
Activity
[-]Improve docker image[/-][+]Improve Docker image[/+]kylecarbs commentedon Jun 9, 2022
PInning the version of
alpinewould be good too!github-actions commentedon Aug 9, 2022
This issue is becoming stale. In order to keep the tracker readable and actionable, I'm going close to this issue in 7 days if there isn't more activity.
[-]Improve Docker image[/-][+]Improve Coder Docker image[/+]github-actions commentedon Oct 24, 2022
This issue is becoming stale. In order to keep the tracker readable and actionable, I'm going close to this issue in 7 days if there isn't more activity.