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

Dealing with Docker Image Sizes #5179

Unanswered
Sharpz7 asked this question in Q&A
May 9, 2022 · 3 comments · 8 replies
Discussion options

Hi,

Right now I am installing all the programs I use into a Docker image. this makes my image very big, roughly 5GB. I feel this cannot be the right way to do it, here is what I am thinking in my head:

  • There might be some way to get this image size down, maybe by only installing parts of software, special cleanup etc. Right now I reckon Python, Docker and PHP are the main culprits.
  • Run all my programs for Containers already running those programs: This is a much more docker way of doing things, but since my codeserver is running inside a container, getting volumes to work correctly becomes a much more difficult task that I have not managed.

Suggestions for either of these points would be greatly appreciated. Here is the current (private) dockerfile.

# https://hub.docker.com/r/codercom/code-server/tags
FROM codercom/code-server:4.4.0
USER root
# wget and curl install
RUN apt-get update && apt-get install -y wget
# Golang install
RUN wget https://dl.google.com/go/go1.18.1.linux-amd64.tar.gz && \
 tar -xvf go1.18.1.linux-amd64.tar.gz && \
 mv go /usr/local
ENV GOROOT /usr/local/go
ENV GOPATH /home/coder/code-server/go
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH
# Python 3.10 install
RUN apt-get install -y \
 python3.10 \
 python3-pip &&\
 pip3 install pipenv &&\
 pip3 install pylint
# PHP and Composer Install
RUN apt-get install php -y && \
 php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" &&\
 php composer-setup.php &&\
 php -r "unlink('composer-setup.php');" &&\
 mv composer.phar /usr/local/bin/composer
# Julia, Elixir Install
RUN apt-get install -y julia elixir
# Typescript install
RUN apt install -y npm && \
 npm install -g npm && \
 npm install -g typescript node ts-node nodemon
# Docker Install
COPY ./buildfiles/get-docker.sh .
RUN sh get-docker.sh &&\
 curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose &&\
 chmod +x /usr/local/bin/docker-compose
# neofetch, zsh and zsh plugins
RUN apt-get install -y zsh neofetch &&\
	chsh -s /bin/zsh &&\
 touch /home/coder/.zshrc &&\
 usermod -m -d /home/coder coder
ENV SHELL /usr/bin/zsh
RUN chown -R coder:coder /home/coder
USER coder
# Install Rust
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ENV PATH="/home/coder/.cargo/bin:${PATH}"
You must be logged in to vote

Replies: 3 comments 8 replies

Comment options

So an update, I have spent some time improving the image, and reduced it down to 4.35GB. Not bad considering where I was before. Here is what I've done.

# https://hub.docker.com/r/codercom/code-server/tags
FROM codercom/code-server:4.4.0
USER root
# Everything to be installed by apt-get
RUN apt update && apt install -y \
 wget \
 python3.9 \
 python3-pip \
 julia \
 elixir \
 php \
 npm \
 zsh \
 neofetch && \
 rm -rf /var/lib/apt/lists/*
# Golang install
RUN wget https://dl.google.com/go/go1.18.1.linux-amd64.tar.gz && \
 tar -xvf go1.18.1.linux-amd64.tar.gz && \
 mv go /usr/local && \
 rm go1.18.1.linux-amd64.tar.gz
ENV GOROOT /usr/local/go
ENV GOPATH /home/coder/code-server/go
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH
# Python 3.9 install
RUN pip3 install pipenv pylint flake8
# Composer Install
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" &&\
 php composer-setup.php &&\
 php -r "unlink('composer-setup.php');" &&\
 mv composer.phar /usr/local/bin/composer && \
# Typescript install
RUN npm install -g npm && \
 npm install -g typescript node ts-node nodemon
# Get Docker
RUN curl -fsSL https://get.docker.com -o get-docker.sh && \
 sh get-docker.sh &&\
 curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose &&\
 chmod +x /usr/local/bin/docker-compose
# Install Rust
ENV CARGO_HOME /cargo
ENV RUSTUP_HOME=/rust
ENV PATH=/cargo/bin:/rust/bin:$PATH
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
# zsh plugins
RUN chsh -s /bin/zsh &&\
 touch /home/coder/.zshrc &&\
 usermod -m -d /home/coder coder && \

I now:

  • Delete the golang tar
  • Use apt instead of apt-get
  • Use apt only in one RUN and clear its cache afterwards using rm -rf /var/lib/apt/lists/*

Any other suggestions still welcome ;)

You must be logged in to vote
6 replies
Comment options

So i'm not sure what you mean with purging, but I know with autoclean / cleaning docker recommends to do what I've used using rm -rf /var/lib/apt/lists/*. Maybe I am missing something but I imagine they both have the same outcome?

See: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#apt-get

Comment options

Oops sorry it's autoremove. I believe it's executed like so:

apt autoremove --purge
Comment options

That clears as much data as it could.

Comment options

Hmm. That is interesting, might produce unwanted sideffects but I shall give it a go. Cheers ;))

Comment options

Hey man, so that change seems to have made no difference. Still 3.72 GB. Cheers tho, I shall keep it in just in case.

RUN apt update && apt install -y --no-install-recommends \
 wget \
 python3.9 \
 python3-pip \
 julia \
 elixir \
 php \
 npm \
 zsh \
 neofetch && \
 rm -rf /var/lib/apt/lists/* && \
 apt autoremove --purge
Comment options

Now at 3.72 GB by not installing the recommended tools by apt. Might regret this, we shall see.

You must be logged in to vote
2 replies
Comment options

2.5 years later, and I'm curious where people have gotten to with image size... Also curious what the latest and greatest strategies are to make image size less relevant when using this to set up a cloud-based dev environment via helm charts.

Comment options

@trailstrider This depends on the programming language and required tool set:

i️ These images are intended for Data Scientists, ML/AI Engineers, and the like 🧑‍💻.

Footnotes

  1. The glcr.b-data.ch/jupyterlab/python/base:3.12-devtools image – which is suitable to build code-server itself, is 2.92 GB (compressed 876 MB)

Comment options

@trailstrider @benz0li

Now, I find that my network speeds on my nodes + the storage I have means I have stopped caring about this. Coder has also made my life easier for managing everything, so the size matters less.

I can keep a code-server container online for 6 months usually, and by that time I usually do think I benefit from re-installing things, and having that complete purge. Granted, I only really use Python/Go nowadays.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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