Dockerfile 解析错误第 18 行:ARG 名称不能为空

Azp*_*ect 2 python docker dockerfile docker-compose

这是 Dockerfile,我在第 18 行收到错误,即 ARG DEV =false,我创建了一个 requests.dev.txt 文件,因此这些依赖项不应在生产中执行,而只能在开发中执行。

我在 .yml 文件中将该文件重写为 true。

Dockerfile:

# Install Python 3.9 image
FROM python:3.9-alpine3.13 

 # maintainer of the image
LABEL maintainer="tenz8"

 # for faster response
ENV PYTHONBUFFERED 1 


COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./app /app
WORKDIR /app
EXPOSE 8000

#getting overrided in decker-compose.yml
ARG DEV = false 
# &&/  used to create new lines for lighter dockerfile
RUN python -m venv /py && \
    /py/bin/pip install --upgrade pip && \    
    /py/bin/pip install -r /tmp/requirements.txt && \
    #if condition in shell scripting
    if [ $DEV = "true" ]; \
        then /py/bin/pip install -r /tmp/requirements.dev.txt ; \
    # fi means end of if condition
    fi && \  
    rm -rf /tmp && \    
    adduser \
        --disabled-password \
        --no-create-home \
        django-user    

ENV PATH="/py/bin:$PATH"

USER django-user

Run Code Online (Sandbox Code Playgroud)

docker-compose.yml:

version: "3.9"

services:
  app:
    build:
      context: .
      args:
        - DEV=true
    ports:
      - "8000:8000"
    volumes:
      - ./app:/app      
    command: >
      sh -c "python manage.py runserver 0.0.0.0:8000"
Run Code Online (Sandbox Code Playgroud)

Mah*_*rus 9

赋值时参数不应有任何空格。

只需删除空格即可。

ARG DEV = false // Incorrect Approach  
ARG DEV=false // Correct Approach 
Run Code Online (Sandbox Code Playgroud)