一. Dockerfile
FROM gogs/gogs:0.11.34
MAINTAINER 潘志勇 <sd4015700@126.com>
LABEL Description="基于gogs/gogs:0.11.34做成的org.pzy/gogs:1.0" Version="1.0"
# 将时区设置为东八区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
解决问题
- 在官方镜像基础上, 将系统时区修改为东八区
二. 打造自己的启动脚本
# 重复执行start命令并不会重复启动
echo "gogs容器操作脚本,用于容器的启动,停止,删除以及状态查看!"
containerId=`docker ps -a | grep "gogs" | grep "Up" | awk '{print $1}'`
if [ "$1" = "start" ]; then
# 检查mysql57容器启动状态
containerId=`docker ps -a | grep "mysql57" | grep "Up" | awk '{print $1}'`
if [ -z "$containerId" ]; then
# 容器id为空,说明mysql未启动,或已停止
echo "容器mysql57状态: "`docker ps -a | grep "mysql57"`
echo "要启动gogs,请先启动mysql57容器!"
else
containerId=`docker network ls | grep backend | awk '{print $1}'`
if [ -z "$containerId" ]; then
# 说明backend网络不存在,创建backend网络
echo "自动创建backend网络!"
docker network create backend
fi
containerId=`docker ps -a | grep "gogs" | grep "Up" | awk '{print $1}'`
if [ -z "$containerId" ]; then
# 容器id为空,说明gogs未启动,或已停止
echo "容器gogs状态: "`docker ps -a | grep "gogs"`
containerId=`docker ps -a | grep "gogs" | grep "Exited" | awk '{print $1}'`
if [ -n "$containerId" ]; then
# 容器id为空, 说明容器已停止
echo "重启容器: gogs"
docker start gogs
else
# 容器id不为空, 说明容器未启动
echo "启动容器: gogs"
docker run -d -p 10022:22 -p 10080:3000 --name=gogs --net=backend -v /Users/pan/docker/volume/gogs:/data org.pzy/gogs:1.0
fi
fi
containerId=`docker ps -a | grep "gogs" | grep "Up" | awk '{print $1}'`
if [ -n "$containerId" ]; then
echo "容器gogs已启动,并已加入backend网络!"
echo "使用[/Users/pan/docker/volume/gogs]作为gogs数据目录!"
echo "gogs的22端口被映射到宿主机的10022端口[10022:22], 3000的http端口被映射到宿主机的10080端口[10080:3000的]!"
echo "gogs的配置文件地址:[/Users/pan/docker/volume/gogs/gogs/conf/app.ini]!"
echo "打开浏览器: http://localhost:10080 即可访问!"
else
echo "容器gogs启动异常! 请使用[docker logs]命令容器名称查看日志"
fi
echo "容器gogs状态: "`docker ps -a | grep "gogs"`
fi
elif [ "$1" = "stop" ]; then
if [ -n "$containerId" ]; then
# 容器哦id非空, 表示容器已启动,执行容器停止命令
echo "停止gogs!"
docker stop gogs
containerId=`docker ps -a | grep "gogs" | grep "Exited" | awk '{print $1}'`
if [ -z "$containerId" ]; then
# 容器id为空, 表示容器未成功停止
echo "容器gogs停止失败! 请使用[docker logs]命令查看具体日志!"
else
echo "容器gogs已停止!"
fi
echo "容器gogs状态: "`docker ps -a | grep "gogs"`
else
echo "容器gogs已停止!"
echo "容器gogs状态: "`docker ps -a | grep "gogs"`
fi
elif [ "$1" = "status" ]; then
if [ -z "$containerId" ]; then
echo "容器gogs未启动!"
else
echo "容器gogs已启动!"
fi
echo "容器gogs状态: "`docker ps -a | grep "gogs"`
elif [ "$1" = "remove" ]; then
containerId=`docker ps -a | grep "gogs" | awk '{print $1}'`
if [ -n "$containerId" ]; then
echo "删除容器gogs!"
docker stop gogs
docker rm gogs
containerId=`docker ps -a | grep "gogs" | awk '{print $1}'`
if [ -n "$containerId" ]; then
echo "容器gogs删除失败!请使用[docker logs]命令查看详细日志!"
else
echo "容器gogs已删除!"
fi
else
echo "容器gogs已删除!"
fi
else
echo "(前提条件:必须先启动mysql57容器,并且将mysql57容器加入backend网络中)正确使用脚本的方式:"
echo "./gogs start #启动gogs,多次执行该命令并不会重复启动gogs,请放心使用!"
echo "./gogs stop #停止gogs"
echo "./gogs status #查看gogs状态"
echo "./gogs remove #删除gogs状态,无论gogs处于什么状态!"
echo "./gogs help #查看脚本使用方式!"
fi
三. 附注说明
启动脚本,请根据自己的实际情况, 修改之后再使用
网友评论