Skip to content

Instantly share code, notes, and snippets.

@Rafisto
Last active June 23, 2024 18:15
Show Gist options
  • Save Rafisto/e927c2f6c6546260360d840cc7c56277 to your computer and use it in GitHub Desktop.
Save Rafisto/e927c2f6c6546260360d840cc7c56277 to your computer and use it in GitHub Desktop.

SSH Tunneling example with Docker

docker compose up -d
docker exec -it 6af7afd6e6b1 /bin/bash
ssh -L 80:localhost:80 root@ubuntu2
Ubuntu image with SSH Server and Apache
# Use the official Ubuntu base image
FROM ubuntu:latest

# Install Apache HTTP server
RUN apt-get update && apt-get install -y apache2

# Install SSH server
RUN apt-get install -y openssh-server

# Configure SSH
RUN mkdir /var/run/sshd
RUN echo 'root:password' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# Expose SSH and Apache ports
EXPOSE 22
EXPOSE 80

# Start SSH and Apache services
CMD service ssh start && /usr/sbin/apache2ctl -D FOREGROUND
Ubuntu image with SSH client
FROM ubuntu:latest

RUN apt-get update && apt-get install -y openssh-server openssh-client curl

RUN mkdir /var/run/sshd
RUN echo 'root:password' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

Docker compose

version: "3"

services:
  ubuntu1:
    build: ./ssh
  ubuntu2:
    build: ./apache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment