如何解决构建Docker Compose时的权限被拒绝问题

huangapple go评论112阅读模式
英文:

How to reslove permission denied while building docker compose

问题

我正在尝试构建以下Docker文件并运行它,但是我遇到了这个错误:

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "./doc8": permission denied: unknown

我的Docker文件如下,尝试构建两个容器,一个是Go,另一个是PostgreSQL:

version: '3.7'
services:
  postgre-db:
    container_name: postgre-db
    image: postgres:12.2-alpine
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: postgres
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
  doc8server:
    container_name: doc8server
    image: {IMAGE_NAME}
    env_file:
      - doc8.env
    build:
      context: .
      dockerfile: Dockerfile.doc8server.multistage
    ports:
      - "{PORT}:{PORT}"
    volumes:
      - doc8data:/opt/app/assets/pdfs
      - doc8data:/opt/app/assets/pdfs/originalFiles
    depends_on:
      - postgre-db
volumes:  
  pgdata: {}
  doc8data: {}

这是我的运行命令:

docker compose up -d

这是我的Dockerfile:

FROM golang:latest as builder

LABEL maintainer="Doc8 <example@gmail.com>"

WORKDIR /app/invos_server_golang

COPY go.mod go.sum ./

RUN go mod download

COPY . .

WORKDIR /app/invos_server_golang

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o doc8 .

FROM rastasheep/ubuntu-sshd:latest

WORKDIR /opt/app

COPY --from=builder /app/invos_server_golang/doc8 .
COPY --from=builder /app/invos_server_golang/doc8.env .

EXPOSE {PORT}

CMD ["./doc8"]

请告诉我是否有任何错误。

英文:

I am trying to build following docker file and then run it but I'm getting this error

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: &quot;./doc8&quot;: permission denied: unknown

My docker file is as follows in that trying to build two containers one go and another id PostgreSQL:

version: &#39;3.7&#39;
services:
  postgre-db:
    container_name: postgre-db
    image: postgres:12.2-alpine
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: postgres
    ports:
      - &quot;5432:5432&quot;
    volumes:
      - pgdata:/var/lib/postgresql/data
  doc8server:
    container_name: doc8server
    image: {IMAGE_NAME}
    env_file:
      - doc8.env
    build:
      context: .
      dockerfile: Dockerfile.doc8server.multistage
    ports:
      - &quot;{PORT}:{PORT}&quot;
    volumes:
      - doc8data:/opt/app/assets/pdfs
      - doc8data:/opt/app/assets/pdfs/originalFiles
    depends_on:
      - postgre-db
volumes:  
  pgdata: {}
  doc8data: {}

this my run command

docker compose up -d

And this my dockerfile

FROM golang:latest as builder

LABEL maintainer=&quot;Doc8 &lt;example@gmail.com&gt;&quot;

WORKDIR /app/invos_server_golang

COPY go.mod go.sum ./

RUN go mod download

COPY . .

WORKDIR /app/invos_server_golang

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o doc8 .

FROM rastasheep/ubuntu-sshd:latest

WORKDIR /opt/app

COPY --from=builder /app/invos_server_golang/doc8 .
COPY --from=builder /app/invos_server_golang/doc8.env .

EXPOSE {PORT}

CMD [&quot;./doc8&quot;]

Please let me know if I am doing anything wrong

答案1

得分: 1

似乎在容器内执行"./doc8"命令时出现了权限问题。您可以修改Dockerfile,在运行之前确保可执行文件具有正确的权限。

在Dockerfile中进行以下修改:

# 添加可执行权限到可执行文件
RUN chmod +x ./doc8

CMD ["./doc8"]
英文:

It seems there is a permission issue when trying to execute the ./doc8 command within the container. You can modify the docker file to ensure the executable has the correct permissions before running it.

MODIFY THIS IN THE DOCKERFILE:

# Add execute permissions to the executable
RUN chmod +x ./doc8

CMD [&quot;./doc8&quot;]

huangapple
  • 本文由 发表于 2023年6月15日 12:49:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76479209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定