You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker构建脚本执行报错:环境变量未设置与Compose端口配置异常

问题解决:Docker Compose环境变量警告与端口配置错误

问题描述

在Ubuntu 22.04系统上使用Docker Compose v2.5.0,执行./docker-build.sh脚本时收到大量环境变量未设置的警告,同时docker-compose.yml文件存在端口配置类型错误、端口项重复的报错;执行docker compose up -d命令时也出现同类警告及端口项不唯一的问题。

执行./docker-build.sh的错误信息

WARNING: The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARNING: The "HTTPS_HOST" variable is not set. Defaulting to a blank string.
WARNING: The "HTTP_HOST" variable is not set. Defaulting to a blank string.
WARNING: The "HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARNING: The "HTTP_PORT" variable is not set. Defaulting to a blank string.
WARNING: The "LETSENCRYPT_MODE" variable is not set. Defaulting to a blank string.
WARNING: The "ADMIN_EMAIL" variable is not set. Defaulting to a blank string.
WARNING: The "POSTGRESQL_MAX_CONNECTIONS" variable is not set. Defaulting to a blank string.
WARNING: The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARNING: The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.jenkins.ports contains an invalid type, it should be a number, or an object
services.jenkins.ports contains an invalid type, it should be a number, or an object
services.geonode.ports contains an invalid type, it should be a number, or an object
services.geonode.ports contains an invalid type, it should be a number, or an object
services.jenkins.ports value [':', ':', '50000:50000'] has non-unique elements

执行docker compose up -d的错误信息

WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "LETSENCRYPT_MODE" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTPS_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "HTTP_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "ADMIN_EMAIL" variable is not set. Defaulting to a blank string.
WARN[0000] The "LETSENCRYPT_MODE" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "POSTGRESQL_MAX_CONNECTIONS" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "JENKINS_HTTPS_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "COMPOSE_PROJECT_NAME" variable is not set. Defaulting to a blank string.
services.jenkins.ports array items[0,1] must be unique

关联Dockerfile内容

FROM python:3.10.2-buster
LABEL GeoNode development team

RUN mkdir -p /usr/src/communalp

# Enable postgresql-client-13
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
RUN echo "deb http://deb.debian.org/debian/ stable main contrib non-free" | tee /etc/apt/sources.list.d/debian.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

# To get GDAL 3.2.1 to fix this issue https://github.com/OSGeo/gdal/issues/1692
# TODO: The following line should be removed if base image upgraded to Bullseye
RUN echo "deb http://deb.debian.org/debian/ bullseye main contrib non-free" | tee /etc/apt/sources.list.d/debian.list

# This section is borrowed from the official Django image but adds GDAL and others
RUN apt-get update -y && apt-get upgrade -y

# Prepraing dependencies
RUN apt-get install -y \
    libgdal-dev libpq-dev libxml2-dev \
    libxml2 libxslt1-dev zlib1g-dev libjpeg-dev \
    libmemcached-dev libldap2-dev libsasl2-dev libffi-dev

RUN apt-get install -y --no-install-recommends \
    gcc zip gettext geoip-bin cron \
    postgresql-client-13 \
    sqlite3 spatialite-bin libsqlite3-mod-spatialite \
    python3-dev python3-gdal python3-psycopg2 python3-ldap \
    python3-pip python3-pil python3-lxml python3-pylibmc \
    uwsgi uwsgi-plugin-python3 \
    firefox-esr

RUN apt-get install -y devscripts build-essential debhelper pkg-kde-tools sharutils
# RUN git clone https://salsa.debian.org/debian-gis-team/proj.git /tmp/proj
# RUN cd /tmp/proj && debuild -i -us -uc -b && dpkg -i ../*.deb

# Install pip packages
RUN pip install pip --upgrade \
    && pip install pygdal==$(gdal-config --version).* \
        flower==0.9.4

# Activate "memcached"
RUN apt install -y memcached
RUN pip install pylibmc \
    && pip install sherlock

# add bower and grunt command
COPY src /usr/src/communalp/
WORKDIR /usr/src/communalp

COPY src/monitoring-cron /etc/cron.d/monitoring-cron
RUN chmod 0644 /etc/cron.d/monitoring-cron
RUN crontab /etc/cron.d/monitoring-cron
RUN touch /var/log/cron.log
RUN service cron start

COPY src/wait-for-databases.sh /usr/bin/wait-for-databases
RUN chmod +x /usr/bin/wait-for-databases
RUN chmod +x /usr/src/communalp/tasks.py \
    && chmod +x /usr/src/communalp/entrypoint.sh

COPY src/celery.sh /usr/bin/celery-commands
RUN chmod +x /usr/bin/celery-commands

COPY src/celery-cmd /usr/bin/celery-cmd
RUN chmod +x /usr/bin/celery-cmd

# # Install "geonode-contribs" apps
# RUN cd /usr/src; git clone https://github.com/GeoNode/geonode-contribs.git -b master
# # Install logstash and centralized dashboard dependencies
# RUN cd /usr/src/geonode-contribs/geonode-logstash; pip install --upgrade  -e . \
#     cd /usr/src/geonode-contribs/ldap; pip install --upgrade  -e .

RUN pip install --upgrade --no-cache-dir  --src /usr/src -r requirements.txt
RUN pip install --upgrade  -e .

# Cleanup apt update lists
RUN rm -rf /var/lib/apt/lists/*

# Export ports
EXPOSE 8000

# We provide no command or entrypoint as this image can be used to  enter code here`serve the django project or run celery tasks
# ENTRYPOINT /usr/src/communalp/entrypoint.sh

解决方案

一、补全缺失的环境变量

  1. 在项目根目录创建.env文件,填入所有需要的环境变量(根据实际需求修改值):
COMPOSE_PROJECT_NAME=my_geonode_project
HTTPS_HOST=your-domain.com
HTTP_HOST=your-domain.com
HTTPS_PORT=443
HTTP_PORT=80
LETSENCRYPT_MODE=production
ADMIN_EMAIL=admin@your-domain.com
POSTGRESQL_MAX_CONNECTIONS=100
JENKINS_HTTP_PORT=8080
JENKINS_HTTPS_PORT=8443
  1. 如果./docker-build.sh脚本需要读取这些变量,在脚本开头添加加载逻辑:
if [ -f .env ]; then
  export $(cat .env | grep -v '#' | xargs)
fi
  1. 确保docker-compose.yml中引用变量的格式正确,例如${COMPOSE_PROJECT_NAME},避免出现未替换的空值。

二、修复docker-compose.yml端口配置错误

从错误日志可知,端口配置存在无效格式和重复项问题,修改方式如下:

  1. 修正无效端口格式:删除所有仅为':'的无效条目,确保每个端口映射遵循宿主端口:容器端口的格式,或仅指定容器端口(由Docker随机分配宿主端口)。示例配置:
services:
  jenkins:
    ports:
      - "${JENKINS_HTTP_PORT}:8080"
      - "${JENKINS_HTTPS_PORT}:8443"
      - "50000:50000"
  geonode:
    ports:
      - "${HTTP_PORT}:8000"
      - "${HTTPS_PORT}:8443"
  1. 删除重复端口项:检查jenkins服务的ports列表,移除重复的条目,确保每个映射唯一。
  2. 验证配置有效性:执行docker compose config命令,确认docker-compose.yml无语法错误。

三、验证修复效果

完成上述修改后,重新执行./docker-build.sh和docker compose up -d,检查是否仍有警告或错误。

内容的提问来源于stack exchange,提问作者Lockencharly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 15:30:45