Dockerfile
FROM ubuntu:latest
RUN apt update && apt install openssh-server sudo -y
RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 test
RUN echo 'test:test' | chpasswd
RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]
构建镜像
docker build -t IMAGE_NAME .
启动容器
docker run IMAGE_NAME -p 2222:22
SSH测试
ssh test@ip_address -p 2222