docker 搭建并运行 nexus
02 November 2024
docker 搭建并运行 nexus
在lwds920上布署 nexus: https://snip.wodedata.com/snippet/52
创建 nexus volume
# docker 创建 volume: nexus-data
docker volume create \
--driver local \
--opt type=cifs \
--opt device='//lwds920.local/data/nexus' \
--opt o="username=luowei,password=$(read PASSWORD && echo -n $PASSWORD),uid=$(id -u),gid=$(id -g),noperm" \
nexus-data
# docker 删除 volume: nexus-data
docker volume rm nexus-data
# 本地创建
docker volume create \
--opt type=none \
--opt device=/volume1/data/nexus \
--opt o=bind \
nexus-data
docker-compose.yaml 示例
services:
nexus:
image: mark.docker/nexus3/arm64:3.72.0
container_name: nexus
ports:
- 8081:8081
- 8082:8082
- 8083:8083
- 8084:8084
restart: unless-stopped
volumes:
- nexus-data:/nexus-data
# env_file:
# - .env # 引入环境变量文件
volumes:
nexus-data:
external: true # 指定这是一个外部已存在的卷
# # bind local
# volumes:
# nexus-data:
# driver: local
# driver_opts:
# type: none
# device: /$HOME/docker/nexus/data
# o: bind
# bind cifs
# volumes:
# nexus-data:
# driver: local
# driver_opts:
# type: cifs
# device: "//lwds920.local/data/nexus"
# o: "username=${CIFS_USERNAME},password=$(echo $CIFS_PASSWORD | base64 --decode)"
# bind nfs
# volumes:
# nexus-data:
# driver: local
# driver_opts:
# type: nfs
# device: ":/SSD2"
# o: "addr=lwds920.local,rw"
nexus run.sh
#!/bin/bash
# 确保提供了操作参数
if [ $# -ne 1 ]; then
echo "Usage: $0 <start|stop|restart|rm>"
exit 1
fi
ACTION=$1
# 函数:获取密码并写入 .env 文件
write_env() {
local TEMP_USERNAME="luowei"
# 获取密码并进行 Base64 编码
$HOME/bin/get_password lwds920 "$TEMP_USERNAME"
ENCODED_PASSWORD=$(echo -n "$PASSWORD" | base64)
# 写入 .env 文件
{
echo "CIFS_USERNAME=$TEMP_USERNAME"
echo "CIFS_PASSWORD=$ENCODED_PASSWORD"
} > .env
}
# 执行相应的操作
case $ACTION in
start)
echo "Starting Nexus..."
write_env # 调用函数
docker-compose up -d
;;
stop)
echo "Stopping Nexus..."
docker-compose down
;;
restart)
echo "Restarting Nexus..."
docker-compose down
write_env # 调用函数
docker-compose up -d
;;
rm)
echo "Removing Nexus..."
docker-compose down --rmi all
;;
*)
echo "Invalid action. Usage: $0 <start|stop|restart|rm>"
exit 1
;;
esac
