It often makes sense to create a custom images that include the dependencies, scripts, preferences necessary for development. For information on how to create, build push Docker images, follow this tutorial by Docker.
As a start, we recommdend you start by extending one of our Enterprise Example Images and extending them. If you need to use another base image, we recommend reading over our image minimums to ensure the image works with most Coder features.
FROM codercom/enterprise-base:ubuntu
RUN apt-get install -y ...
COPY file ./
...
📝: You can build most images inside a Coder workspace! Check out this image for info.
- Ben's Coder Images (referenced in Coffee and Coder and the Coder blog)
- Enterprise Sample Images
Coder-specific code snippets for writing custom Dockerfiles and configure scripts.
Replace [IDE]
with the name of the IDE in lowercase. To find the corresponding [CODE]
, use this reference.
# Dockerfile
FROM ...
USER root # Install IDEs as root
RUN mkdir -p /opt/[IDE]
RUN curl -L "https://download.jetbrains.com/product?code=[CODE]&latest&distribution=linux" | tar -C /opt/[IDE] --strip-components 1 -xzvf
RUN ln -s /opt/[IDE]/bin/clion.sh /usr/bin/[IDE]
ex. (CLion IDE):
# Dockerfile
FROM ...
USER root
# install CLion
RUN mkdir -p /opt/clion
RUN curl -L "https://download.jetbrains.com/product?code=CL&latest&distribution=linux" | tar -C /opt/clion --strip-components 1 -xzvf
RUN ln -s /opt/clion/bin/clion.sh /usr/bin/clion
The configure
script will run once your workspace has started and your the home directory has been mounted.
Some good things to do in the configure script:
- Run coder-cli commands
- Clone a GitHub repo
- Install global npm packages
- Run scripts that use CODER_* environment variables
Create the configure
file in the same directory as your Dockerfile:
$ touch configure
$ chmod +x configure
# Dockerfile
FROM ...
COPY configure /coder/configure
If you're extending a Coder image that has a configure script, you can use this workaround to avoid overriting the original script. This will run AFTER the initial script runs.
$ touch configure
$ chmod +x configure
# configure
echo "Doing more stuff..."
# Dockerfile
FROM codercom/enterprise-configure:ubuntu
# Append to the original configure script
COPY configure /coder/configure-2
RUN echo '' >> "/coder/configure" # Add new line
RUN echo '# [Second configure script]' >> "/coder/configure"
RUN echo 'sh /coder/configure-2' >> "/coder/configure"
# configure
coder ...
# Create a Dev URL (or update if it already exists)
coder urls create $CODER_ENVIRONMENT_NAME 3000 --name webapp
# configure
if [ ! -d "/home/coder/workspace/project" ]
then
git clone git://company.com/project.git /home/coder/workspace/project
else
echo "Project has already been cloned :)"
fi
$ touch settings.json
$ chmod +x settings.json
# configure
# Check if there are existing settings
if [ -f "/home/coder/.local/share/code-server/User/settings.json" ]
then
echo "VS Code settings are already present. Remove with and run /coder/configure to revert to defaults"
else
cp settings.json /home/coder/.local/share/code-server/User/settings.json
# Install extensions
/opt/coder/code-server/bin/code-server --install-extension esbenp.prettier-vscode
fi