Marco
Marco

Reputation: 161

Running script using docker run results in permission denied

I'm trying to run a docker image from dockerfile that I create.

the command:

docker build -t mytest .
docker run -v $(pwd):/main -p 8080:8080 -w /main mytest ./scripts/test.sh

my structure:

- test_folder
-- scripts
--- test.sh

my dockerfile:

FROM ubuntu:16.04
RUN apt-get update
EXPOSE 8080

The error:

docker run -v $(pwd):/main -p 8080:8080 -w /main mytest ./scripts/test.sh
docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"./scripts/test.sh\": permission denied": unknown.

Someone know what is wrong?

Upvotes: 1

Views: 4524

Answers (1)

Bee
Bee

Reputation: 1306

script.sh doesn't have the access permissions set that are needed for execution. The following docker run statement will set the correct permissions.

docker run -v $(pwd):/main -p 8080:8080 -w /main mytest chmod +x ./scripts/test.sh && ./scripts/test.sh

You can also just execute chmod +x ./scripts/test.sh on your host system once and then use the docker run statement that you have provided in your question.

Upvotes: 2

Related Questions