我是一个docker的新手。我正在尝试在docker容器中运行我的应用程序。
Dockerfile
FROM node:14.16.0-alpine
ARG SSH_KEY
RUN apk update && apk add openssh-client git \
&& addgroup myuser \
&& adduser myuser -G myuser -D /home/myuser -u 999 \
&& mkdir -p /home/myuser/.ssh \
&& chmod 0700 /home/myuser/.ssh \
&& ssh-keyscan github.com > /home/myuser/.ssh/known_hosts \
&& chown -R myuser:myuser /home/myuser
USER myuser:myuser
RUN mkdir -p /home/myuser/app/spa-proxy && chown -R myuser:myuser /home/myuser/app/spa-proxy
COPY package.json /home/myuser/app/spa-proxy
COPY package-lock.json /home/myuser/app/spa-proxy
WORKDIR /home/myuser/app/spa-proxy
ARG INSTALL_ENV="--production"
RUN echo "$SSH_KEY" > /home/myuser/.ssh/id_rsa && chmod 0600 /home/myuser/.ssh/id_rsa \
&& npm install ${INSTALL_ENV} \
&& rm /home/myuser/.ssh/id_rsa
COPY . /home/myuser/app/spa-proxy
ENV PATH $PATH:./node_modules/.bin/
RUN tsc
EXPOSE 8001
CMD ["node", "./.build/src/index.js"]
我创建了一个名为myuser的用户组。还尝试将所有权授予myuser。但是在尝试构建镜像时,出现了以下错误:
构建命令:
sudo docker build --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" -t testfolder .
错误:
error TS5033: Could not write file '/home/myuser/app/spa-proxy/.build/src/types/index.js': EACCES: permission denied, open '/home/myuser/app/spa-proxy/.build/src/types/index.js'.
The command /bin/sh -c tsc returned a non-zero code: 2
当Docker运行命令RUN tsc时,会发生错误。 它试图将构建文件写入创建的工作目录,但由于权限问题而无法创建。
如果有人能帮我解决这个问题,我将非常感激,因为我最终想要学习Docker。
注:如果我们可以编写更好的Dockerfile或docker-compose.yml,请纠正我。