Dockerfile parse错误第18行:ARG名称不能为空白

发布于 2025-02-08 04:57:21 字数 1369 浏览 1 评论 0原文

这是Dockerfile,我在第18行中遇到错误 我创建了一个要求。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

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"

This is the Dockerfile, I am getting error at Line 18 i.e. ARG DEV =false,
I created a requirements.dev.txt file so those dependencies should not execute on the production but only on the development.

I am overridding that file as true in a .yml file.

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

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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半寸时光 2025-02-15 04:57:21

分配值时不应该有任何空间。

只需删除空间。

ARG DEV = false // Incorrect Approach  
ARG DEV=false // Correct Approach 

Arguments should not have any space while assigning the value.

Just remove the space.

ARG DEV = false // Incorrect Approach  
ARG DEV=false // Correct Approach 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文