对于Windows 10上的Docker,如何在脚本中设置文件权限,以便在Docker不运行后删除文件?

问题描述

我正在Windows 10上运行Docker19。我有一个包含多个容器的docker-compose文件,其中一个是React应用程序...

version: '3'

services:
  MysqL:
    restart: always
    image: MysqL:8.0
    cap_add:
      - SYS_NICE  # CAP_SYS_NICE
    environment:
      MysqL_DATABASE: 'directory_data'
      # So you don't have to use root,but you can if you like
      MysqL_USER: 'root'
      # You can use whatever password you like
      MysqL_PASSWORD: 'password'
      # Password for root access
      MysqL_ROOT_PASSWORD: 'password'
    ports:
      - "3406:3306"
    volumes:
      - my-db:/var/lib/MysqL
    command: ['MysqLd','--character-set-server=utf8mb4','--collation-server=utf8mb4_unicode_ci']

  web:
    restart: always
    build: ./web
    ports:           # to access the container from outside
      - "8000:8000"
    env_file: .env
    environment:
      DEBUG: 'true'
    command: /usr/local/bin/gunicorn directory.wsgi:application --reload -w 2 -b :8000
    volumes:
    - ./web/:/app
    depends_on:
      - MysqL

  client:
    build:
      context: ./client
    volumes:
      - ./client:/app
    ports:
      - '3001:3000'
    restart: always
    container_name: web-app
    environment:
      - NODE_ENV=dockerdev
    depends_on:
      - web
    stdin_open: true
    command: /bin/bash /app/install_and_run.sh

  apache:
    restart: always
    build: ./apache/
    ports:
      - "9090:80"
    links:
      - web:web
      - client:client

volumes:
  my-db:

客户端Dockerfile的结构如下

FROM node:10-alpine AS alpine
  
RUN apk update && apk add bash

RUN apk add dos2unix

# A directory within the virtualized Docker environment
# Becomes more relevant when using Docker Compose later
workdir /my-app/

# copies package.json and package-lock.json to Docker environment
copY install_and_run.sh ./

# Installs all node packages
RUN npm install --force -g yarn

RUN dos2unix /my-app/install_and_run.sh

带有如下所示的“ install_and_run.sh”脚本

#!/bin/bash
  
cd /app

# install everythiing
yarn

# Run it
REACT_APP_PROXY=http://localhost:9090 npm start

当我运行“ docker-compose up”然后退出其中时,我在文件系统上看到具有以下权限的文件(使用Cygwin)

drwxr-xr-x+ 1 lared lared 0 Sep 27 16:18 webpack-dev-middleware
drwxr-xr-x+ 1 lared lared 0 Sep 27 16:18 webpack-dev-server
drwxr-xr-x+ 1 lared lared 0 Sep 27 16:18 webpack-log
drwxr-xr-x+ 1 lared lared 0 Sep 27 16:18 webpack-manifest-plugin
drwxr-xr-x+ 1 lared lared 0 Sep 27 16:18 workBox-webpack-plugin
drwxr-xr-x+ 1 lared lared 0 Sep 27 16:18 worker-farm
drwxr-xr-x+ 1 lared lared 0 Sep 27 16:18 write

但是,即使我以拥有所有权的用户身份登录,我似乎也无法删除文件,但出现类似以下的错误

rm: cannot remove 'client/node_modules/workBox-webpack-plugin/node_modules/.bin/webpack': Permission denied
rm: cannot remove 'client/node_modules/worker-farm/node_modules/.bin/errno': Permission denied
rm: cannot remove 'client/node_modules/write/node_modules/.bin/mkdirp': Permission denied

我想知道的是我需要在Dockerfile / script中做些什么来赋予文件权限,以便在Docker停止或不存在时可以删除它们(作为我登录用户)在我的系统上完全没有?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)