1
\$\begingroup\$

What follows is a Dockerfile for my Vim settings, so I could use it anywhere.

While it is public, it is not intended for mass usage, and so the face that it creates the password in the build process isn't a problem. There is no COMMAND at the end because it is intended to be run with mount. The command I run it with docker run -itv /:/tmp/real_root uberhumus/vim-anywhere:latest vi <Filename> Was I supposed to COPY the .vimrc later? Or use ADD instead? Am I too splurgy with the layers? Is there a smarter way to do the RUN, WORKDIR, RUN situations I ran into?

Thanks!


ENV DEBIAN_FRONTEND=noninteractive
ARG TZ=Asia/Jerusalem
RUN apt-get update; \
    apt-get dist-upgrade -y && \
    apt-get autoremove -y && \
    apt-get autoclean -y && \
    apt-get install -y vim tmux bash-completion shellcheck ssh git pylint flake8 python sudo expect curl cmake build-essential python3-dev golang npm openjdk-11-jre exuberant-ctags && \
    echo vim-anywhere > /etc/hostname

ARG USERNAME=yotam
RUN PASSWORD=$(openssl rand -base64 16 | tr -d "=") && \
    useradd -m -s /bin/bash $USERNAME && \
    usermod -aG sudo $USERNAME && \ 
    echo "$USERNAME:$PASSWORD" | chpasswd && \
    echo $PASSWORD

WORKDIR /home/$USERNAME
COPY .vimrc .
RUN mkdir -p ./.vim/pack/plugins/start 
WORKDIR /home/$USERNAME/.vim/pack/plugins/start
RUN git clone https://github.com/tpope/vim-fugitive.git/ && \
    git clone --depth 1 https://github.com/dense-analysis/ale.git && \
    git clone https://github.com/ycm-core/YouCompleteMe.git
WORKDIR /home/$USERNAME/.vim/pack/plugins/start/YouCompleteMe
RUN git submodule update --init --recursive && \
    python3 install.py --all && \
    chown -R $USERNAME:$USERNAME /home/$USERNAME
USER $USERNAME```
\$\endgroup\$
0
\$\begingroup\$

The best I've got is:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
ARG TZ=Asia/Jerusalem
ARG USERNAME=yotam
RUN apt-get update; \
    apt-get dist-upgrade -y && \
    apt-get autoremove -y && \
    apt-get autoclean -y && \
    apt-get install -y vim tmux bash-completion shellcheck ssh git pylint flake8 python sudo expect curl cmake build-essential python3-dev golang npm openjdk-11-jre exuberant-ctags && \
    useradd -m -s /bin/bash $USERNAME && \
    usermod -aG sudo $USERNAME && \ 
    echo vim-anywhere > /etc/hostname

WORKDIR /home/$USERNAME
COPY .vimrc .
RUN mkdir -p ./.vim/pack/plugins/start 
WORKDIR /home/$USERNAME/.vim/pack/plugins/start
RUN git clone https://github.com/tpope/vim-fugitive.git/ && \
    git clone --depth 1 https://github.com/dense-analysis/ale.git && \
    git clone https://github.com/ycm-core/YouCompleteMe.git
WORKDIR /home/$USERNAME/.vim/pack/plugins/start/YouCompleteMe
RUN git submodule update --init --recursive && \
    python3 install.py --all && \
    chown -R $USERNAME:$USERNAME /home/$USERNAME && \
    PASSWORD=$(openssl rand -base64 16 | tr -d "=") && \
    echo "$USERNAME:$PASSWORD" | chpasswd && \
    echo $PASSWORD
WORKDIR /home/$USERNAME
USER $USERNAME

This gives me only minor advantages which are:

  1. The password is echoed at the end of the build and is easier to find in the output.
  2. The return to the homedir at the end is more what you'd intuitively expect.
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Why not pass the PASSWORD as a --build-arg? \$\endgroup\$ – masseyb Mar 11 at 1:04
  • \$\begingroup\$ @masseyb answer it, it's a good point. \$\endgroup\$ – Uberhumus Mar 11 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.