You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 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: localhostconnection: localgather_facts: notasks:
- name: Ensure docker-py is installedpip:
name: docker-py
- name: Run SSH-enabled Ubuntu containerdocker_container:
name: my-ubuntu-ssh-containerimage: ubuntu-ssh:lateststate: startedports:
- "2222:22"# Map host port 2222 to container port 22