我想使用Bitnami's Nginx base image服务静态网站。我有一个多阶段的Dockerfile,如下所示:
# build stage
FROM node:lts-alpine as build-stage
COPY ./ /app
WORKDIR /app
COPY .npmrc .npmrc
RUN npm install && npm run build
# Production stage
FROM bitnami/nginx:1.16 as production-stage
COPY --from=build-stage --chown=1001 /app/dist /app
COPY nginx.conf /opt/bitnami/nginx/conf/nginx.conf
COPY --chown=1001 entrypoint.sh /
RUN chmod +w /entrypoint.sh
CMD ["/entrypoint.sh"]
我使用entrypoint.sh
用环境变量替换某些文件内容,例如:
#!/bin/bash
function join_by { local IFS="$1"; shift; echo "$*"; }
vars=$(env | grep VUE_APP_ | awk -F = '{print "$"$1}')
vars=$(join_by ' ' $vars)
for file in /app/js/app.*;
do
### T H I S L I N E T H R O W S E R R O R ###
cp $file $file.tmpl
envsubst "$vars" < $file.tmpl > $file
rm $file.tmpl
done
exec "$@"
在cp
命令中,它将引发错误:
cp:无法创建常规文件'/app/js/app.042ea3b0.js.tmpl':权限被拒绝
如您所见,我已经复制了dist文件和带有entrypoint.sh
(Bitnami图像中的默认用户)的--chown=1001
,但是没有任何好处。
是因为图像文件夹app
是exposed by a volume by default吗?如何复制和修改移入图像的文件?
PS:它在OpenShift环境中运行。
答案 0 :(得分:0)
Bitnami映像在postunpack.sh script中执行一些操作,此脚本从Dokerfile中调用。脚本执行的操作之一与配置权限有关,这是由于运行nginx的用户是非root用户。您可以尝试实现与您的需求类似的东西。
答案 1 :(得分:0)
原来是Openshift的行为在这里陈述的:
How can I enable an image to run as a set user ID?:
部署应用程序时,它将以运行该项目的唯一用户ID身份运行。这将覆盖应用程序映像定义其要运行的用户ID。
... 最好的解决方案是构建应用程序映像,以便它可以作为任意用户ID运行。
因此,必须适当设置文件的访问级别(require(future)
plan(multiprocess)
longRunningFunction <- function(value) {
random1<- runif(min= 5 ,max = 30,n = 1)
Sys.sleep(random1)
return(value)
}
arr = list()
#changed starting number to 1 since R lists start at 1, not 0
i=1
#If the number of futures generated is more than the number of cores available, then the main thread will block until the first future completes and allows more futures to be started
while(i < 6)
{
arr[[i]] = future(longRunningFunction(i))
i = i + 1
}
while(all(!resolved(arr))){ }
raceresults_from_future<-lapply(arr[resolved(arr)], value)
print(paste("raceresults_from_future: ",raceresults_from_future) )
),而不是复制文件并修改文件的所有者(chown
)。