默认环境:debian11、go1.20。
创建文件Dockerfile,写入一下内容
FROM golang:1.20.4
MAINTAINER cdx cdxccx@outlook.com
ENV password="root"
RUN echo 'root:$password' |chpasswd
RUN apt update && \
apt-get install -y openssh-server && \
apt clean && \
rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp* && \
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && \
echo "export PATH=/usr/local/go/bin:$PATH" >> /root/.bashrc
RUN mkdir /var/run/sshd
EXPOSE 22
VOLUME ["/code"]
CMD ["/usr/sbin/sshd","-D"]
执行命令编译成镜像:
docker build -t ssh_golang .