DEV Community

RAHUL DHOLE
RAHUL DHOLE

Posted on

Docker Devtools Stage | Powerlevel, OhMyZSH, tmux, fuzzy finder, autocomplete etc

Introduction

Developers rely on a plethora of tools and configurations to streamline their workflow, but setting up these essentials consistently across different Docker images can be a daunting task. From fuzzy finders to terminal themes, ensuring a seamless and productive environment often involves repetitive manual configurations. In this post, we'll explore a solution that revolutionizes this process and have your favorite developer setup always ready merge in with any docker container.

Image description

Problem

Picture this: you're diving into a new project, spinning up a Docker image, only to find yourself missing critical developer tools like tmux, htop, or even a personalized terminal theme. Not only does this hinder productivity, but it also detracts from the overall developer experience, leaving you feeling disconnected from your familiar setup.

Introducing the Docker Devtools Volume

My solution? Create a Docker devtools volume once and reuse the same configuration across any Docker image. By encapsulating essential developer tools, terminal configurations, and themes within a single volume, developers can instantly feel at home in any environment, allowing them to focus on what matters most: writing code.

Following is a Dockerfile which has devtools stage which can be used in your workflow:
Download Dockerfile.devtools

# ##########################################################
# Dockerfile for Developer Tools.
# Description: This Dockerfile is for adding a devtools stage.
#
# Author information:
# Name: Rahul Dhole
# Email: rdhole95@gmail.com
# GitHub: https://github.com/rahuldhole
#
# Dockerfile description:
# - The devtools stage can be based on top of debian images.
# - It has tmux, OhMyZSH, Powerlevel etc neccessary tools.
# - For more details checkout my blog
# https://dev.to/rahuldhole/docker-devtools-stage-powerlevel-ohmyzsh-tmux-fuzzy-finder-autocomplete-etc-8g1
# ###########################################################
# TODO: PREQUISITES #########################################
# 1. You need to install below nerd fonts `MesloLGSNF`
# and set it as your terminal font. read my blog to know more.
#
# 2. Add users home directory as volume to save devtools settings
# and terminal history.
# ex. -v devtools-home:/home/<username>
#############################################################
# IMPORTANT NOTES: ##########################################
# 1. Use `p10k configure` command to reconfigure powerline UI.
#
# 2. You may customize ~/.zshrc ~/.tmux.conf and ~/.p10k.conf
#
# 3. Inside container now you may `su <ADMIN_USER>`
# to do some admin tasks.
#############################################################
# TODO: Update user details
ARG USERNAME=devtools
ARG ADMIN_USER=admin
ARG ADMIN_PASSWORD=admin
#? DEBIAN BASE ##############################################
## TODO: Choose your any other debian base image
FROM debian as base
ARG USERNAME
ARG ADMIN_USER
ARG ADMIN_PASSWORD
## Setting up the work directory
WORKDIR /app
## TODO: .... Write your code here ....
## create a non-root user for security
RUN useradd -m -s /bin/bash $USERNAME
#* DEVTOOLS ################################################
FROM base as devtools
ARG USERNAME
ARG ADMIN_USER
ARG ADMIN_PASSWORD
## Install devtools
RUN apt update && apt-get -y --no-install-recommends install nano zsh curl tmux fontconfig git ca-certificates \
build-essential # Add build essentials for compiling code
## Add admin user
RUN useradd ${ADMIN_USER} && \
echo "${ADMIN_USER}:${ADMIN_PASSWORD}" | chpasswd && \
apt-get update && \
apt-get -y --no-install-recommends install sudo && \
echo "${ADMIN_USER} ALL=(ALL) ALL" >> /etc/sudoers
## User settings
### Set default ZSH
RUN chsh -s /bin/zsh $USERNAME
### select User
USER $USERNAME
### Install tmux plugins and theme
RUN git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && \
touch ~/.tmux.conf && \
echo 'set -g default-terminal "screen-256color"' >> ~/.tmux.conf && \
echo '#Toggle status bar by Prefix+I (default ctrl+b+I)' >> ~/.tmux.conf && \
echo 'bind b run-shell "tmux setw -g status \$(tmux show -g -w status | grep -q off && echo on || echo off)"' >> ~/.tmux.conf && \
echo 'set -g mouse on' >> ~/.tmux.conf && \
echo 'set -g @plugin "tmux-plugins/tpm"' >> ~/.tmux.conf && \
echo 'set -g @plugin "tmux-plugins/tmux-resurrect"' >> ~/.tmux.conf && \
echo 'set -g @plugin "jimeh/tmux-themepack"' >> ~/.tmux.conf && \
echo 'set -g @themepack "powerline/double/green"' >> ~/.tmux.conf && \
echo 'run-shell "~/.tmux/plugins/tpm/tpm"' >> ~/.tmux.conf && \
~/.tmux/plugins/tpm/bin/install_plugins
### Install Oh My Zsh
RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
RUN git clone --depth=1 https://github.com/romkatv/powerlevel10k.git \
${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k && \
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting && \
git clone https://github.com/zsh-users/zsh-autosuggestions \
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && \
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install --all
RUN sed -i -e 's/ZSH_THEME="robbyrussell"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc && \
sed -i -e 's/plugins=(git)/plugins=(git zsh-syntax-highlighting zsh-autosuggestions fzf tmux)/' ~/.zshrc && \
echo 'export PATH="$PATH:/home/rails/.local/bin"' >> ~/.zshrc && \
echo 'POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true' >> ~/.zshrc
## Solve nerd font font issue
USER root
RUN apt-get install -y --no-install-recommends locales && \
locale-gen en_US.UTF-8 && \
sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen en_US.UTF-8 && \
update-locale LANG=en_US.UTF-8
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8 \
TERM=xterm-256color
## Install additional tools
RUN apt-get -y --no-install-recommends install \
vim \
less \
htop \
wget \
tree
### Clear cache
RUN rm -rf /var/lib/apt/lists/*
USER $USERNAME
CMD ["/bin/zsh"]
#? DEVELOPMENT ############################################
FROM devtools as development
ARG USERNAME
ENV APP_ENV development
COPY . .
## TODO: .... Write your development layers below ...

Implementation Guide

Let's dive into the implementation steps:

  1. Setup Prerequisites: Ensure you have the required nerd fonts installed and set as your terminal font.

Following is script to install nerd fonts on debian based distro.

sh -c '\
    wget -P ~/Downloads \
    https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf && \
    wget -P ~/Downloads \
    https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf && \
    wget -P ~/Downloads \
    https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf && \
    wget -P ~/Downloads \
    https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf && \
    mkdir -p ~/.local/share/fonts/ && mv ~/Downloads/*.ttf ~/.local/share/fonts/ && \
    fc-cache -f -v \
Enter fullscreen mode Exit fullscreen mode

For windows

You can simply download the font and double-click install. Go to settings and set it as the default terminal font.

Download MesloLGS NF Regular.ttf

Download MesloLGS NF Bold.ttf

Download MesloLGS NF Italic.ttf

Download MesloLGS NF Bold Italic.ttf

  1. Create the Devtools Volume: At the time of running the container mount devtools user home directory as a docker volume to save the devtools config.

Example:

## Build once
docker build -f Dockerfile.devtools --target devtools -t debian:devtools .

docker run --rm -it -v debian-devtools:/home/<USERNAME> debian:devtools

## Reuse the volume and add devootls Dockerfile stage in your dockerfile before development or test stage
docker run --rm -it -v debian-devtools:/home/<USERNAME> node:development
docker run --rm -it -v debian-devtools:/home/<USERNAME> ubuntu:test
Enter fullscreen mode Exit fullscreen mode

You may customize your configuration, tailor your ~/.zshrc, ~/.tmux.conf, and ~/.p10k.conf files to suit your preferences. Don't forget to run p10k configure to fine-tune your Powerline UI.

Enjoy seamless development with your Docker devtools volume in place, every Docker image becomes an extension of your personalized development environment. Say goodbye to repetitive setups and hello to enhanced productivity!

Conclusion

In conclusion, the Docker Devtools Volume offers an amazing solution for developers seeking consistency and productivity in their Docker-based workflows. By centralizing essential tools and configurations, developers can focus on what they do best: building amazing software. Try out our solution today and experience the difference firsthand.

Let me know in the comments below if you want the same for Alpine-based images.

Ready to elevate your development experience? Dive deeper into Docker devtools volumes and explore more insightful content on our blog.

Happy coding!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay