Skip to content

Docker app #5

Description

@Mgldvd

I created a Docker image. I should clarify that I’m not an expert in Docker, but this works quite well.

🚀 Easy Tutorial: Build SSH Commander Docker Image from Scratch

This guide will walk you through building and running SSH Commander inside a Docker container with persistent storage, a custom prompt, and an easy-to-use alias (ssc).


📂 Step 1: Create a New Directory

mkdir ssh-commander-docker && cd ssh-commander-docker

📜 Step 2: Create the Dockerfile

Create a file named Dockerfile inside your new directory:

nano Dockerfile

Paste the following optimized Dockerfile:

# Use Debian as the base image
FROM debian:latest

# Set environment variables
ENV SSH_COMMANDER_VERSION="1.0.30"
ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies and update certificates
RUN apt-get update && apt-get install -y --no-install-recommends \
    wget \
    ca-certificates \
    python3 \
    python3-paramiko \
    python3-yaml \
    python3-colorama \
    bash \
    && update-ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# Download and install SSH Commander
RUN wget --https-only --secure-protocol=auto -O /tmp/ssh-commander.deb "https://github.com/AthenaNetworks/ssh_commander/releases/download/v${SSH_COMMANDER_VERSION}/ssh-commander_${SSH_COMMANDER_VERSION}_amd64.deb" && \
    dpkg -i /tmp/ssh-commander.deb && \
    rm /tmp/ssh-commander.deb

# Create configuration directory and set up an alias
RUN mkdir -p /root/.config/ssh-commander && \
    echo 'alias ssc="ssh-commander"' >> /root/.bashrc

# Set custom prompt with multiple colored ▍ symbols
RUN echo 'export PS1="\n\[\033[38;2;59;88;254m\]\[\033[38;2;131;16;236m\]\[\033[38;2;229;11;143m\]\[\033[0m\] \[\033[38;2;245;110;27m\]ssh-commander \[\033[38;2;251;39;93m\]\[\033[0m\]"' >> /root/.bashrc

# Set the configuration directory as a volume
VOLUME ["/root/.config/ssh-commander"]

# Default to bash so users can interact with the container
CMD ["/bin/bash"]

What This Dockerfile Does:

  • Uses Debian as the base image.
  • Installs all dependencies (python3, wget, ca-certificates).
  • Downloads & installs SSH Commander (from a variable version).
  • Creates persistent configuration storage.
  • Sets an alias (ssc) for easy command execution.
  • Customizes the terminal prompt with colors.

🏗️ Step 3: Build the Docker Image

Run the following command in the same directory as the Dockerfile:

docker build -t ssh-commander:latest .

This process will:

  1. Download and install all required packages.
  2. Fetch and install SSH Commander.
  3. Prepare the container environment.

🚀 Once completed, your Docker image is ready to use!


📂 Step 4: Create a Persistent Config File

Since SSH Commander needs a configuration file, create one in your current directory:

touch servers.yaml

Edit it with your servers:

nano servers.yaml

Example content:

# Key-based authentication (recommended)
- hostname: web1.example.com
  username: admin
  key_file: ~/.ssh/id_rsa  # Path to your SSH key
  port: 22  # Optional, defaults to 22
  tags: [prod, web]  # Optional, defaults to ['default']

# Password authentication
- hostname: db1.example.com
  username: dbadmin
  password: your_secure_password  # Not recommended for production use
  port: 2222
  tags: [prod, db]  # Optional server tags

💡 This file will be mounted inside the container, so your configurations stay saved across runs.


🚀 Step 5: Run SSH Commander in a Docker Container

Now, launch your container with persistent storage:

docker run -it --rm \
    -v "$(pwd)/servers.yaml:/root/.config/ssh-commander/servers.yaml" \
    -v "$(pwd):/root/.config/ssh-commander" \
    ssh-commander:latest

🔥 Step 6: Use SSH Commander Inside Docker

Once inside, run:

ssc add

or

ssh-commander list

🚀 The terminal should look like this:

▍▍▍  ssh-commander ❱ 

Your SSH Commander setup is now complete! 🎉


🎯 Step 7: (Optional) Automate with a Shell Script

For even easier usage, create a run script:

nano run.sh

Paste:

#!/bin/bash
docker run -it --rm \
    -v "$(pwd)/servers.yaml:/root/.config/ssh-commander/servers.yaml" \
    -v "$(pwd):/root/.config/ssh-commander" \
    ssh-commander:latest

Save and give it execution permission:

chmod +x run.sh

Now, simply run SSH Commander with:

./run.sh

🚀 No need to type long Docker commands anymore!


📌 Recap

  1. Create a working directory for SSH Commander.
  2. Write a Dockerfile to set up the container.
  3. Build the image using docker build.
  4. Create a servers.yaml config file to store servers.
  5. Run the container with persistent storage.
  6. Use SSH Commander inside the Docker container.
  7. (Optional) Automate with a shell script.

🎉 Done! Now SSH Commander is Ready in Docker!

🚀 You can now securely manage SSH connections in a persistent, isolated environment! 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions