我在Mac上使用它。创建和运行docker镜像工作正常。但是使用docker-compose时出现以下错误:
"exec: \"./boot.sh\": permission denied": unknown
Dockerfile:
FROM python:3.7-alpine
RUN adduser -D teamreacher
WORKDIR /home/teamreacher
# copy and install dependencies
COPY ./requirements.txt requirements.txt
RUN python -m venv venv
RUN venv/bin/pip install --upgrade pip
RUN venv/bin/pip install -r requirements.txt
# copy the app
COPY . .
RUN chmod +x boot.sh # Giving execution permissions here...
RUN chown -R teamreacher:teamreacher ./
USER teamreacher
# expose port and run server
EXPOSE 5000
CMD ["./boot.sh"] # ...so why do I get permission denied here?
Docker撰写文件:
version: '3'
services:
teamreacher-server:
build: ./server
volumes:
- ./server:/home/teamreacher
ports:
- 5000:5000
我已经浏览过类似的问题,但没有一个问题可以回答我的具体问题。
boot.sh
#!/bin/sh
source venv/bin/activate
exec gunicorn -b :5000 --access-logfile - --error-logfile - wsgi:app
答案 0 :(得分:2)
通过将./server
目录绑定安装到容器上boot.sh
所在的相同位置,您将重写权限,使其不再可执行。
请参见以下示例:
TJs-MacBook-Pro:stackoverflow tj$ ls -lah
total 8
drwxr-xr-x 4 tj wheel 128B Dec 23 14:58 .
drwxrwxrwt 15 root wheel 480B Dec 23 15:05 ..
-rw-r--r-- 1 tj wheel 143B Dec 23 14:57 docker-compose.yaml
drwxr-xr-x 6 tj wheel 192B Dec 23 15:03 server
TJs-MacBook-Pro:stackoverflow tj$ ls -lah server/
total 24
drwxr-xr-x 6 tj wheel 192B Dec 23 15:03 .
drwxr-xr-x 4 tj wheel 128B Dec 23 14:58 ..
-rw------- 1 tj wheel 177B Dec 23 15:06 .ash_history
-rw-r--r-- 1 tj wheel 508B Dec 23 14:56 Dockerfile
-rw-r--r-- 1 tj wheel 105B Dec 23 14:56 boot.sh
-rw-r--r-- 1 tj wheel 0B Dec 23 14:56 requirements.txt
TJs-MacBook-Pro:stackoverflow tj$ docker-compose build
Building teamreacher-server
Step 1/13 : FROM python:3.7-alpine
---> 020295c920c6
Step 2/13 : RUN adduser -D teamreacher
---> Using cache
---> 7dbd3131c941
Step 3/13 : WORKDIR /home/teamreacher
---> Using cache
---> d2754b1b8dc2
Step 4/13 : COPY ./requirements.txt requirements.txt
---> Using cache
---> 2d468491a297
Step 5/13 : RUN python -m venv venv
---> Using cache
---> 0c135fa6f980
Step 6/13 : RUN venv/bin/pip install --upgrade pip
---> Using cache
---> ea7df7153a5a
Step 7/13 : RUN venv/bin/pip install -r requirements.txt
---> Using cache
---> db540a631c19
Step 8/13 : COPY . .
---> 174a91493622
Step 9/13 : RUN chmod +x boot.sh # Giving execution permissions here...
---> Running in b9cedb0f163a
Removing intermediate container b9cedb0f163a
---> 6d5ce7df1969
Step 10/13 : RUN chown -R teamreacher:teamreacher ./
---> Running in 2e672e8ac6ef
Removing intermediate container 2e672e8ac6ef
---> 48342c4c31e3
Step 11/13 : USER teamreacher
---> Running in 4d3bc99fb515
Removing intermediate container 4d3bc99fb515
---> 11bdc7be7f84
Step 12/13 : EXPOSE 5000
---> Running in 0924db9c175b
Removing intermediate container 0924db9c175b
---> 0d96d773f42f
Step 13/13 : CMD ["./boot.sh"] # ...so why do I get permission denied here?
---> Running in 4a33ab4e342a
Removing intermediate container 4a33ab4e342a
---> a9acefb4eeac
Successfully built a9acefb4eeac
Successfully tagged stackoverflow_teamreacher-server:latest
TJs-MacBook-Pro:stackoverflow tj$ docker run stackoverflow_teamreacher-server ls -lah /home/teamreacher
total 24
drwxr-sr-x 1 teamreac teamreac 4.0K Dec 23 20:07 .
drwxr-xr-x 1 root root 4.0K Dec 23 19:56 ..
-rw------- 1 teamreac teamreac 177 Dec 23 20:06 .ash_history
-rw-r--r-- 1 teamreac teamreac 508 Dec 23 19:56 Dockerfile
-rwxr-xr-x 1 teamreac teamreac 105 Dec 23 19:56 boot.sh
-rw-r--r-- 1 teamreac teamreac 0 Dec 23 19:56 requirements.txt
drwxr-sr-x 1 teamreac teamreac 4.0K Dec 23 19:59 venv
TJs-MacBook-Pro:stackoverflow tj$ docker run -v $(pwd)/server:/home/teamreacher stackoverflow_teamreacher-server ls -lah /home/teamreacher
total 16
drwxr-xr-x 6 teamreac teamreac 192 Dec 23 20:03 .
drwxr-xr-x 1 root root 4.0K Dec 23 19:56 ..
-rw------- 1 teamreac teamreac 177 Dec 23 20:06 .ash_history
-rw-r--r-- 1 teamreac teamreac 508 Dec 23 19:56 Dockerfile
-rw-r--r-- 1 teamreac teamreac 105 Dec 23 19:56 boot.sh
-rw-r--r-- 1 teamreac teamreac 0 Dec 23 19:56 requirements.txt
答案 1 :(得分:0)
事实证明,我还必须在Mac上授予文件boot.sh执行权限。这意味着运行:
chmod +x boot.sh
在我的项目目录中。