Skip to content

Instantly share code, notes, and snippets.

@sagarpanda
Created August 10, 2025 08:01
Show Gist options
  • Select an option

  • Save sagarpanda/9706d9bafeff5d893d29536b00eb3f43 to your computer and use it in GitHub Desktop.

Select an option

Save sagarpanda/9706d9bafeff5d893d29536b00eb3f43 to your computer and use it in GitHub Desktop.
SSH enabled Ubuntu container

SSH enabled Ubuntu container

# Dockerfile
FROM ubuntu:latest
LABEL maintainer="Your Name <[email protected]>"

# Install OpenSSH server and sudo
RUN apt update && apt install -y openssh-server sudo

# Create SSH directory and set permissions
RUN mkdir /var/run/sshd

# Set root password (for demonstration, use a strong password in production)
RUN echo 'root:your_secure_password' | chpasswd

# Permit root login (for demonstration, consider creating a dedicated user in production)
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config

# Expose SSH port
EXPOSE 22

# Start SSH daemon
CMD ["/usr/sbin/sshd", "-D"]
docker build -t ubuntu-ssh:latest .
# playbook.yml
- hosts: localhost
  connection: local
  gather_facts: no

  tasks:
    - name: Ensure docker-py is installed
      pip:
        name: docker-py

    - name: Run SSH-enabled Ubuntu container
      docker_container:
        name: my-ubuntu-ssh-container
        image: ubuntu-ssh:latest
        state: started
        ports:
          - "2222:22" # Map host port 2222 to container port 22
ansible-playbook playbook.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment