windows打包docker镜像,并上传到私有仓库

2019-12-12  本文已影响0人  简栋梁

项目描述

前提:Dockerfile、基础镜像已准备好

安装docker for windows

官方地址

https://docs.docker.com/v17.09/docker-for-windows/install/

配置私有仓库地址

创建脚本&配置基本信息

创建脚本
cd 项目目录
vim build_upload.sh
// build_upload.sh
#!/bin/bash

# 解析配置文件
host=$(grep -Po '(?<=host": ").*?(?=")' build.config.json)
username=$(grep -Po '(?<=username": ").*?(?=")' build.config.json)
password=$(grep -Po '(?<=password": ").*?(?=")' build.config.json)
version=$(grep -Po '(?<=version": ").*?(?=")' build.config.json)
path=$(grep -Po '(?<=path": ").*?(?=")' build.config.json)

# 获取当前目录名, 作为镜像名
string=$(pwd)
OLD_IFS="$IFS"
IFS="/"
array=($string)
IFS="$OLD_IFS"
length=${#array[@]}
nameLastIndex=${array[length-1]}

yarn build
docker build -t "$nameLastIndex:$version" .
docker login -u $username -p $password $host
docker tag "$nameLastIndex:$version" "$host$path/$nameLastIndex:$version"
docker push "$host$path/$nameLastIndex:$version"

echo '-------------------'
echo 'finish!'
echo '-------------------'
配置基本信息
vim build.config.json
// build.config.json
{
    "host": "ip:端口",
    "path": "/项目目录",
    "username": "用户名",
    "password": "密码",
    "version": "版本号"
}

运行脚本,一键打包并上传

// package.json
"scripts": {
    "auto": "./build_upload.sh"
  },
yarn auto
上一篇下一篇

猜你喜欢

热点阅读