# golang:latest镜像
FROM ee23292e2826
# 作者
MAINTAINER dechao@qq.com
# 添加Golang环境变量
ENV GOPROXY https://goproxy.cn,direct
ENV GO111MODULE on
ENV GOROOT /usr/local/go
# 配置apt-get源
ADD sources.list /etc/apt/
# 更新apt-get源 安装ssh服务 修改root密码 配置ssh服务允许root远程登录 写"开启ssh服务 写地址信息到/root/ip.txt 并tail -f"到/root/ip.sh 赋予ip.sh执行权限
RUN apt-get update \
&& apt-get -y install ssh \
&& echo "root:1" | chpasswd \
&& echo "PermitRootLogin yes" >> /etc/ssh/sshd_config \
&& echo "service ssh start && ip addr | grep global > /root/ip.txt && tail -f /root/ip.txt" > /root/ip.sh \
&& chmod +x /root/ip.sh \
# 解决ssh连接ENV环境变量不生效问题
&& echo "export GOPROXY=$GOPROXY" >> /root/.bashrc \
&& echo "export GOROOT=$GOROOT" >> /root/.bashrc \
&& echo "export GOPATH=$GOPATH" >> /root/.bashrc \
&& echo "export GO111MODULE=$GO111MODULE" >> /root/.bashrc \
&& echo "export PATH=$PATH" >> /root/.bashrc
# 启动时执行
ENTRYPOINT ["sh","-l"]
CMD ["/root/ip.sh"]
-p 主机地址:主机端口:容器端口
-v 主机卷:容器卷
docker run -itd -p 2222:22 -v /root/fserver/:/go/src/fserver a9c8