1. Dockerfile
dockerfile所在目录结构
shell
FROM python:3.8
WORKDIR /leo
RUN apt-get install -y wget
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
# ssh免密登录
COPY id_rsa.pub /leo
RUN mkdir ~/.ssh\
&& cat /leo/id_rsa.pub >> ~/.ssh/authorized_keys
RUN touch /leo/start.sh
RUN echo "service ssh restart; while [ 1 == 1 ]; do echo '123' ; sleep 100 ; done;" > /leo/start.sh
# ssh
RUN apt-get update \
&& apt-get install -y libwrap0 openssh-server\
&& echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
# git配置自动保存密码
RUN git config --global credential.helper store \
&& git config --global user.name "LeoLi"\
&& git config --global user.email LeoLi.Li@groupm.com
ENTRYPOINT [ "bash", "/leo/start.sh"]
build
shell
docker build -f ./DockerfilePython -t python38:1.0 .
2. docker run
docker run -d -p 10001:22 -p 8888:5000 -p 9000:9000 -p 7777:7777 -v C:\Users\leoli.li\DockerShare:/leo --name=python38 leo-python38:latest
查看ssh服务是否正常启动
service ssh status
3.Vscode 免密打开项目
config
shell
Host gme
HostName 127.0.0.1
Port 10001
User root
IdentityFile C:\Users\leoli.li\.ssh\id_rsa
git
第一次拉取代码需要输入用户名密码,后面就不需要了