Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

When container is recreated, automatically run a dependency setup script #7338

Answered by code-asher
pcgeek86 asked this question in General
Discussion options

I am finally getting around to setting up a semi-production, private code-server instance for myself on one of my home-lab Linux servers, with an NVIDIA GPU. One of the issues I foresee is that my dependencies will get "reset" every time a new version of the container is deployed. Every week or two, I run docker compose pull && docker compose up --detach, to ensure I have the latest container images for my applications. If a new version of code-server comes out, my installed tools like Rust, PowerShell, NVIDIA tools, etc. will be gone.

I understand that the general approach is to build a custom Dockerfile.

However ....

💡 Question: Rather than building my own Dockerfile for code-server, is there a way for me to launch a persisted script (mapped into container by Docker volume) upon launching a new code-server container? I would rather run a script to install all my dependencies (eg. Rust Toolchain, PowerShell, NVIDIA utilities, etc.) than creating a Dockerfile. I generally prefer to use "stock" container images, rather than building my own, and then just inject whatever I need to at container runtime.

I am using Docker Compose to add code-server to the list of other pre-packaged application containers I am running. I'm sharing the snippet below for docker-compose.yaml, just in case anyone else is searching for it. I couldn't find it in the docs and created it myself.

 vscode:
 image: codercom/code-server:latest
 ports:
 - 10400:8080
 volumes:
 - ./code-server/.local:/home/coder/.local
 - ./code-server/.config:/home/coder/.config
 - ./code-server/project:/home/coder/project
 environment:
 - DOCKER_USER=${USER}
 user: 1000:1000
 restart: always
You must be logged in to vote

Actually you do not need to set ENTRYPOINTD, it defaults to ${HOME}/entrypoint.d, so you can mount your scripts there.

ENV ENTRYPOINTD=${HOME}/entrypoint.d

Replies: 1 comment 2 replies

Comment options

The only method that comes to my mind is to change the entrypoint to a script of your own that installs the dependencies and then executes the original entrypoint.

And, we actually have an environment variable to make doing this easier: ENTRYPOINTD (point it to a directory of scripts that you want to run before executing code-server).

# Allow users to have scripts run on container startup to prepare workspace.
# https://github.com/coder/code-server/issues/5177
if [ -d "${ENTRYPOINTD}" ]; then
find "${ENTRYPOINTD}" -type f -executable -print -exec {} \;
fi
You must be logged in to vote
2 replies
Comment options

Actually you do not need to set ENTRYPOINTD, it defaults to ${HOME}/entrypoint.d, so you can mount your scripts there.

ENV ENTRYPOINTD=${HOME}/entrypoint.d
Answer selected by pcgeek86
Comment options

Very cool, thank you for that pointer. I will give this a try.

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

AltStyle によって変換されたページ (->オリジナル) /