Code-server: Installing npm and other stuff after with docker compose

Created on 23 Sep 2019  路  9Comments  路  Source: cdr/code-server

I've encapsulated all the stuff for starting the code-server in a docker-compose.yamlbut now I need to install some deps after the start, like nodejs, npm and angular-cli. How can I achieve this?

My docker-compose.yaml

version: "2"
services:
  code-server:
    image: codercom/code-server:v2
    container_name: code-server-v2
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
      - PASSWORD=${PWD}
    volumes:
      - ${HOME}/.local/share:/home/coder/.local/share
      - ${HOME}:/home/coder
    ports:
      - 8080:8080
      - 4200:4200
    restart: always
    command: "--auth password"

I've tried it with the command but I had no luck with it, chaining with the --auth flag

question

All 9 comments

You should make your own Dockerfile if you want to pre-install packages for your code-server environment. Here's mine: https://github.com/demyxco/code-server/blob/master/tag-latest/Dockerfile

@demyxco I've just used your dockerfile and installed all the stuff I need, but the code-server is (as mentioned in the log) started, but I can't access it via localhost:8080. The code-server itself is working. Any idea?

My dockerfile:

FROM codercom/code-server:v2

LABEL disane.image disane/code-server
LABEL disane.maintainer Disane <[email protected]>
LABEL disane.url https://byte.style.de
LABEL disane.github https://github.com/disane/
LABEL disane.registry https://hub.docker.com/u/disane

ENV DEBIAN_FRONTEND noninteractive
ENV TZ America/Los_Angeles
ENV PASSWORD disane

EXPOSE 8080
EXPOSE 4200

USER root

# Install custom packages
RUN set -ex; \
    apt-get update && apt-get install -y zsh jq htop nano tzdata nodejs npm

RUN npm install @angular/cli -g

# Oh My Zsh
RUN set -ex; \
    sed -i "s|/home/coder:/bin/bash|/home/coder:/bin/zsh|g" /etc/passwd; \
    mkdir -p /home/coder/.code/data/User; \
    echo "{\n    \"terminal.integrated.shell.linux\": \"/bin/zsh\"\n}" > /home/coder/.code/data/User/settings.json; \
    chown -R coder:coder /home/coder

RUN set -ex; \
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"; \
    git clone https://github.com/zsh-users/zsh-autosuggestions.git /root/.oh-my-zsh/plugins/zsh-autosuggestions; \
    sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="ys"/g' /root/.zshrc; \
    sed -i "s/(git)/(git zsh-autosuggestions)/g" /root/.zshrc

RUN set -ex; \
    su -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" -s /bin/sh coder; \
    git clone https://github.com/zsh-users/zsh-autosuggestions.git /home/coder/.oh-my-zsh/plugins/zsh-autosuggestions; \
    sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="ys"/g' /home/coder/.zshrc; \
    sed -i "s/(git)/(git zsh-autosuggestions)/g" /home/coder/.zshrc; \
    ln -s /home/coder/.zsh_history /root

COPY entrypoint.sh /usr/local/bin/entrypoint

RUN chmod +x /usr/local/bin/entrypoint

USER coder

WORKDIR /home/coder

#ENTRYPOINT ["dumb-init", "entrypoint.sh"]

@Disane87 what's your docker-compose.yml look like? did you expose the ports in your compose file? Like this?

ports:
- 8080:8080

I guess thats my fault. Sorry, beeing pretty new to Docker :)

@demyxco But that should also work with a plain docker run [image] -p 8080, correct?

@Disane87 yes, something like docker run -dit --rm -p 8080:8080 code-image

Ok, it seems the order of the params is crucial. with docker run [image] -p 8080:8080 its running.

with docker run -p 8080:8080 [image] it doesn't work. Thank you for your assistance @demyxco! :-)

Yeah you need to define your docker run flags before the image name, anything after that is interpreted as commands when container is up.

If this is still a problem, please feel free to reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

korzq picture korzq  路  3Comments

sa7mon picture sa7mon  路  3Comments

pchecinski picture pchecinski  路  3Comments

broady picture broady  路  3Comments

infogulch picture infogulch  路  3Comments