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

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

How to reslove permission denied while building docker compose

问题

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

  1. 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:

  1. version: '3.7'
  2. services:
  3. postgre-db:
  4. container_name: postgre-db
  5. image: postgres:12.2-alpine
  6. environment:
  7. POSTGRES_PASSWORD: postgres
  8. POSTGRES_USER: postgres
  9. POSTGRES_DB: postgres
  10. ports:
  11. - "5432:5432"
  12. volumes:
  13. - pgdata:/var/lib/postgresql/data
  14. doc8server:
  15. container_name: doc8server
  16. image: {IMAGE_NAME}
  17. env_file:
  18. - doc8.env
  19. build:
  20. context: .
  21. dockerfile: Dockerfile.doc8server.multistage
  22. ports:
  23. - "{PORT}:{PORT}"
  24. volumes:
  25. - doc8data:/opt/app/assets/pdfs
  26. - doc8data:/opt/app/assets/pdfs/originalFiles
  27. depends_on:
  28. - postgre-db
  29. volumes:
  30. pgdata: {}
  31. doc8data: {}

这是我的运行命令:

  1. docker compose up -d

这是我的Dockerfile:

  1. FROM golang:latest as builder
  2. LABEL maintainer="Doc8 <example@gmail.com>"
  3. WORKDIR /app/invos_server_golang
  4. COPY go.mod go.sum ./
  5. RUN go mod download
  6. COPY . .
  7. WORKDIR /app/invos_server_golang
  8. RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o doc8 .
  9. FROM rastasheep/ubuntu-sshd:latest
  10. WORKDIR /opt/app
  11. COPY --from=builder /app/invos_server_golang/doc8 .
  12. COPY --from=builder /app/invos_server_golang/doc8.env .
  13. EXPOSE {PORT}
  14. CMD ["./doc8"]

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

英文:

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

  1. 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:

  1. version: &#39;3.7&#39;
  2. services:
  3. postgre-db:
  4. container_name: postgre-db
  5. image: postgres:12.2-alpine
  6. environment:
  7. POSTGRES_PASSWORD: postgres
  8. POSTGRES_USER: postgres
  9. POSTGRES_DB: postgres
  10. ports:
  11. - &quot;5432:5432&quot;
  12. volumes:
  13. - pgdata:/var/lib/postgresql/data
  14. doc8server:
  15. container_name: doc8server
  16. image: {IMAGE_NAME}
  17. env_file:
  18. - doc8.env
  19. build:
  20. context: .
  21. dockerfile: Dockerfile.doc8server.multistage
  22. ports:
  23. - &quot;{PORT}:{PORT}&quot;
  24. volumes:
  25. - doc8data:/opt/app/assets/pdfs
  26. - doc8data:/opt/app/assets/pdfs/originalFiles
  27. depends_on:
  28. - postgre-db
  29. volumes:
  30. pgdata: {}
  31. doc8data: {}

this my run command

  1. docker compose up -d

And this my dockerfile

  1. FROM golang:latest as builder
  2. LABEL maintainer=&quot;Doc8 &lt;example@gmail.com&gt;&quot;
  3. WORKDIR /app/invos_server_golang
  4. COPY go.mod go.sum ./
  5. RUN go mod download
  6. COPY . .
  7. WORKDIR /app/invos_server_golang
  8. RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o doc8 .
  9. FROM rastasheep/ubuntu-sshd:latest
  10. WORKDIR /opt/app
  11. COPY --from=builder /app/invos_server_golang/doc8 .
  12. COPY --from=builder /app/invos_server_golang/doc8.env .
  13. EXPOSE {PORT}
  14. CMD [&quot;./doc8&quot;]

Please let me know if I am doing anything wrong

答案1

得分: 1

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

在Dockerfile中进行以下修改:

  1. # 添加可执行权限到可执行文件
  2. RUN chmod +x ./doc8
  3. 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:

  1. # Add execute permissions to the executable
  2. RUN chmod +x ./doc8
  3. 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:

确定