Skip to content

Instantly share code, notes, and snippets.

@NinoFocus
Last active November 7, 2019 14:43
Show Gist options
  • Save NinoFocus/4530ede443068d812df05ae21f8aed64 to your computer and use it in GitHub Desktop.
Save NinoFocus/4530ede443068d812df05ae21f8aed64 to your computer and use it in GitHub Desktop.
将前端本地构建任务代理到docker上执行
#/bin/sh
# 依赖的node版本
requiredNodeVersion="8.12.0"
# docker image
requiredImage="node:${requiredNodeVersion}"
# 本机已经安装的node images版本
installedNodeImageVersions=`docker images node --format "{{json .Tag}}"`
if [[ $installedNodeImageVersions =~ $requiredNodeVersion ]]
then
echo "${*}"
else
echo "不存在镜像 ${requiredImage},启动下载..."
docker pull $requiredImage
fi
# 当前项目路径
projectPath=`pwd`
# 执行命令
docker run -it -v $projectPath:/project $requiredImage /bin/sh -c "cd /project && ${*}"
@NinoFocus
Copy link
Author

NinoFocus commented Nov 7, 2019

比如在项目目录下执行

./dockerrun.sh yarn install
./dockerrun.sh yarn start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment