本地镜像默认工作目录为:/tmp/project,根据该镜像运行容器时报错,原因是:挂载的目录为/tmp/client/,而执行 npm i 命令时,进入的是client目录,解决方式:将命令修改为以下即可:
cd /tmp/client/ && npm i
docker 运行时报错:
+ docker run -e GIT_SSL_NO_VERIFY=1 -v /home/workspace/student_PR-112:/tmp/client/ test/basis/web:v1 sh -c 'cd client && npm i' docker: Error response from daemon: OCI runtime create failed: container_linux.go:318: starting container process caused "chdir to cwd (\"/tmp/project\") set in config.json failed: no such file or directory": unknown. time="2023-05-10T15:37:43+08:00" level=error msg="error waiting for container: context canceled"
修改后的代码:
docker run -e GIT_SSL_NO_VERIFY=1 -v /home/workspace/student_PR-112:/tmp/client/ test/basis/web:v1 sh -c 'cd /tmp/client/ && npm i'