Docker-compose文件:不允许附加属性env_files,如何丰富我的env?

q8l4jmvw  于 2023-03-29  发布在  Docker
关注(0)|答案(1)|浏览(379)

无法丰富.env文件
docker-compose.yml

version: '19.03.0'
services:
    alva-back-mobile-strapi4:
        image: node:14.19.1-alpine
        env_file: alva-back-mobile-strapi4/.env
        volumes: 
            - strapi4-data:/var/home/app/data
            - ./alva-back-mobile-strapi4:/alva-back-mobile-strapi4
        working_dir: /alva-back-mobile-strapi4
        command: sh -c "npm install && npm run build && npm run develop"
        ports:
        - ${PORT}:${PORT}
    my-pets-back:
        image: node:16.3.0-alpine
        env_files: MyPetsBack/.env
        volumes:
            - mobile-data:/var/home/app/data
            - ./MyPetsBack:/MyPetsBack
        working_dir: ./MyPetsBack
        command: sh -c "npm install && npm run build && npm run develop"
        ports:
          - ${PORT}:${PORT}
    my-pets-front:
        image: node:16.3.0-alpine
        env_file: MyPetsFront/.env
        volumes:
            - front-data:/var/home/app/petData
            - ./MyPetsFront:/MyPetsFront
        working_dir: /MyPetsFront
        command: sh -c "npm install && npm run build && npm run develop"
        ports:
        - ${PORT}:${PORT}
    redis:
      image: redis:latest
volumes: 
  strapi4-data:
  mobile-data:
  front-data:

文件夹的结构(.env在文件夹内)enter image description here
结果

time="2023-03-28T22:44:12+03:00" level=warning msg="The \"PORT\" variable is not set. Defaulting to a blank string."
time="2023-03-28T22:44:12+03:00" level=warning msg="The \"PORT\" variable is not set. Defaulting to a blank string."
time="2023-03-28T22:44:12+03:00" level=warning msg="The \"PORT\" variable is not set. Defaulting to a blank string."
time="2023-03-28T22:44:12+03:00" level=warning msg="The \"PORT\" variable is not set. Defaulting to a blank string."
time="2023-03-28T22:44:12+03:00" level=warning msg="The \"PORT\" variable is not set. Defaulting to a blank string."
time="2023-03-28T22:44:12+03:00" level=warning msg="The \"PORT\" variable is not set. Defaulting to a blank string."
services.my-pets-back Additional property env_files is not allowed

我尝试用. ./nameOfProject/.env /nameOfProject/.env nameOfProject/.env指定env_file的路径,但它不起作用。我希望它能起作用。

6qfn3psc

6qfn3psc1#

./添加到env文件路径

version: '19.03.0'
services:
    alva-back-mobile-strapi4:
        image: node:14.19.1-alpine
        env_file: ./alva-back-mobile-strapi4/.env
        volumes: 
            - strapi4-data:/var/home/app/data
            - ./alva-back-mobile-strapi4:/alva-back-mobile-strapi4
        working_dir: /alva-back-mobile-strapi4
        command: sh -c "npm install && npm run build && npm run develop"
        ports:
        - ${PORT}:${PORT}
    my-pets-back:
        image: node:16.3.0-alpine
        env_files: ./MyPetsBack/.env
        volumes:
            - mobile-data:/var/home/app/data
            - ./MyPetsBack:/MyPetsBack
        working_dir: ./MyPetsBack
        command: sh -c "npm install && npm run build && npm run develop"
        ports:
          - ${PORT}:${PORT}
    my-pets-front:
        image: node:16.3.0-alpine
        env_file: ./MyPetsFront/.env
        volumes:
            - front-data:/var/home/app/petData
            - ./MyPetsFront:/MyPetsFront
        working_dir: /MyPetsFront
        command: sh -c "npm install && npm run build && npm run develop"
        ports:
        - ${PORT}:${PORT}
    redis:
      image: redis:latest
volumes: 
  strapi4-data:
  mobile-data:
  front-data:

相关问题