一. Dockerfile
FROM sonatype/nexus3:3.9.0-01
MAINTAINER 潘志勇 <sd4015700@126.com>
LABEL Description="sonatype/nexus3:3.9.0-01做成的org.pzy/nexus3.9:1.0" Version="1.0"
# 将时区设置为东八区
USER root
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 切换回nexus用户
USER nexus
解决问题
- 基于官方镜像, 将系统时区改为东八区
二. 打造自己的启动脚本
# 重复执行start命令并不会重复启动
echo "nexus3容器操作脚本,用于容器的启动,停止,删除以及状态查看!"
echo "入参:"$1
containerId=`docker ps -a | grep "nexus3" | grep "Up" | awk '{print $1}'`
if [ "$1" = "start" ]; then
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 "nexus3" | grep "Up" | awk '{print $1}'`
if [ -z "$containerId" ]; then
# 容器id为空,说明nexus未启动,或已停止
echo "容器nexus3状态: "`docker ps -a | grep "nexus3"`
containerId=`docker ps -a | grep "nexus3" | grep "Exited" | awk '{print $1}'`
if [ -n "$containerId" ]; then
# 容器id非空, 说明容器已停止
echo "重启容器: nexus3"
docker start nexus3
else
# 容器id不为空, 说明容器未启动
echo "启动容器: nexus3"
docker run -d -p 8081:8081 --net=backend --name nexus3 -v /Users/pan/docker/volume/nexus/data:/nexus-data org.pzy/nexus3.9:1.0
fi
fi
containerId=`docker ps -a | grep "nexus3" | grep "Up" | awk '{print $1}'`
if [ -n "$containerId" ]; then
echo "容器nexus3已启动,并已加入backend网络!"
echo "使用[/Users/pan/docker/volume/nexus/data]作为数据目录!"
echo "打开浏览器: http://localhost:8081 即可访问!"
else
echo "容器nexus3启动异常! 请使用[docker logs]命令容器名称查看日志"
fi
echo "容器nexus3状态: "`docker ps -a | grep "nexus3"`
elif [ "$1" = "stop" ]; then
if [ -n "$containerId" ]; then
# 容器哦id非空, 表示容器已启动,执行容器停止命令
echo "停止nexus3!"
docker stop nexus3
containerId=`docker ps -a | grep "nexus3" | grep "Exited" | awk '{print $1}'`
if [ -z "$containerId" ]; then
# 容器id为空, 表示容器未成功停止
echo "容器nexus3停止失败! 请使用[docker logs]命令查看具体日志!"
else
echo "容器nexus3已停止!"
fi
echo "容器nexus3状态: "`docker ps -a | grep "nexus3"`
else
echo "容器nexus3已停止!"
echo "容器nexus3状态: "`docker ps -a | grep "nexus3"`
fi
elif [ "$1" = "status" ]; then
if [ -z "$containerId" ]; then
echo "容器nexus3未启动!"
else
echo "容器nexus3已启动!"
fi
echo "容器nexus3状态: "`docker ps -a | grep "nexus3"`
elif [ "$1" = "remove" ]; then
containerId=`docker ps -a | grep "nexus3" | awk '{print $1}'`
if [ -n "$containerId" ]; then
echo "删除容器nexus3!"
docker stop nexus3
docker rm nexus3
containerId=`docker ps -a | grep "nexus3" | awk '{print $1}'`
if [ -n "$containerId" ]; then
echo "容器nexus3删除失败!请使用[docker logs]命令查看详细日志!"
else
echo "容器nexus3已删除!"
fi
else
echo "容器nexus3已删除!"
fi
else
echo "正确使用脚本的方式:"
echo "./nexus start #启动nexus3,多次执行该命令并不会重复启动nexus3,请放心使用!"
echo "./nexus stop #停止nexus3"
echo "./nexus status #查看nexus3状态"
echo "./nexus remove #删除nexus3状态,无论nexus3处于什么状态!"
echo "./nexus help #查看脚本使用方式!"
fi
三. 附注说明
启动脚本,请根据自己的实际情况, 修改之后再使用
网友评论