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