Home linux Permission Denied in Docker

Permission Denied in Docker

Author

Date

Category

created a simple dockerfile:

from golang
Expose 8080 80 443
# Set Pwd To The Go Folder
Workdir $ {Gopath}
RUN APT-GET UPDATE -Y & AMP; & AMP; \
  APT-GET INSTALL -Y \
  Nano.
Run Go Get GitHub.com/gorLla/mux & amp; & amp; Go Get GitHub.com/go-sql-driver/mysql
Copy $ {Project_path} / Go / CMS
RUN CD / GO / CMS & AMP; & AMP; go Build & amp; & amp; CHMOD + X CMS
Expose 8080.
Cmd ["./cms"]

but I get an error

error: for b5ceea118913_cms_web_1 Cannot Start Service Web: OCI
Runtime Create Failed: Container_Linux.go: 345: Starting Container
Process CauseD “Exec: \” ./ CMS \ “: permission denied”: unknown

Error: for Web Cannot Start Service Web: OCI Runtime Create Failed:
Container_Linux.go: 345: Starting Container Process CauseD “Exec:
\ “./ CMS \”: Permission Denied “: unknown

What is missing here?

docker run -it cms_web sh -c "pwd & amp; & amp; ls -al"

Shows:

total 10828
DrWXR-XR-X 1 ROOT ROOT 4096 Feb 28 09:04.
DrWXRWXRWX 1 ROOT ROOT 4096 Feb 28 09:04 ..
-RW-RW-R-- 1 root root 35 Feb 26 16:24. Nenv
-RW-RW-R-- 1 root root 13 Feb 26 16:24 .env.example
DrWXRWXRWX 8 ROOT ROOT 4096 Feb 28 08:06 .git
-RWXRWXRWX 1 ROOT ROOT 32 Feb 27 08:20 .gitignore
DrWXRWXRWX 3 ROOT ROOT 4096 Feb 28 09:03.idea
-RWXRWXRWX 1 ROOT ROOT 166 Feb 26 15:56 Database
-RWXRWXRWX 1 Root Root 330 Feb 28 09:03 Dockerfile
DrWXRWXRWX 7 ROOT ROOT 4096 Feb 27 15:04 _Local_Mysql_data
DrWXRWXRWX 6 ROOT ROOT 4096 Feb 26 12:52 APP
-rwsrws - T 1 Root Root 11025893 Feb 28 09:04 CMS
-RWXRWXRWX 1 Root Root 940 Feb 27 08:38 Docker-Compose.yml
-RW-RW-R-- 1 root root 384 Feb 26 16:29 Main.go
DrWXRWXRWX 2 ROOT ROOT 4096 Feb 28 08:13 Migrations
DrWXRWXRWX 3 ROOT ROOT 4096 Feb 20 08:26 Templates

Answer 1

Do you workdir cost $ {gopath} , despite the fact that then you do CD / Go / CMS , at the end of all Equally WORKDIR will $ {goPath} (in this case it is just / GO )

Therefore, you need to either specify the full path to the CMD executable file ["/ go / cms / cms"] , or change the working directory

workdir / go / cms
Cmd ["./cms"]

Update to answer a comment

we have
main.go

package main
Import "fmt"
FUNC MAIN () {
  FMT.PrintLN ("Hello World")
}

docker.env

project_path =.

dockerfile

from golang
# Set Pwd To The Go Folder
Workdir $ {Gopath}
Run Go Get GitHub.com/gorLla/mux & amp; & amp; Go Get GitHub.com/go-sql-driver/mysql
Copy $ {Project_path} / Go / CMS
RUN CD / GO / CMS \
  & amp; & amp; Go Build \
  & amp; & amp; CHMOD + X CMS \
  & amp; & amp; Ls -al
Workdir / GO / CMS
Cmd ["./cms"]

Bildim

Docker Build -t Test -f Dockerfile.

Perform

➜ Docker Run -it Test
Hello World.

From DockerFile Remove Workdir / Go / Cms , Buildim, perform and get

Docker: Error Response from Daemon: OCI Runtime Create Failed:
Container_Linux.go: 346: Starting Container Process CauseD “Exec:
\ “./ CMS \”: Permission Denied “: unknown.

Because there is no executable file. How to make sure?

docker run -it test sh -c "pwd & amp; & amp; ls -al"
/ go.
Total 24.
DrWXRWXRWX 1 ROOT ROOT 4096 Feb 28 09:25.
DrWXR-XR-X 1 ROOT ROOT 4096 Feb 28 09:27 ..
DrWXRWXRWX 2 ROOT ROOT 4096 Feb 27 03:48 Bin 
DrWXR-XR-X 1 ROOT ROOT 4096 Feb 28 09:25 CMS
DrWXR-XR-X 3 ROOT ROOT 4096 Feb 28 09:25 PKG
DrWXRWXRWX 1 Root Root 4096 Feb 28 09:25 SRC

bt.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions