【问题标题】:New code changes exist in live container but are not reflected in the browser实时容器中存在新的代码更改,但未反映在浏览器中
【发布时间】:2020-01-25 15:47:27
【问题描述】:

我正在使用带有开源 BI 工具 Apache Superset 的 Docker。我添加了一个新文件,特别是 CountryMap 目录中的 .geojson 文件。现在,当我尝试使用docker-compose up --build 构建或在前端进行更改时,Docker 没有完全更新,并且在尝试运行查询时出现文件未找到错误。当我通过docker exec -it container_id bash 查看容器内部时,新文件就在那里。

Dockerfile:

FROM python:3.6-jessie

RUN useradd --user-group --create-home --no-log-init --shell /bin/bash superset

# Configure environment
ENV LANG=C.UTF-8 \
    LC_ALL=C.UTF-8

RUN apt-get update -y

# Install dependencies to fix `curl https support error` and `elaying package configuration warning`
RUN apt-get install -y apt-transport-https apt-utils

# Install superset dependencies
# https://superset.incubator.apache.org/installation.html#os-dependencies
RUN apt-get install -y build-essential libssl-dev \
    libffi-dev python3-dev libsasl2-dev libldap2-dev libxi-dev

# Install extra useful tool for development
RUN apt-get install -y vim less postgresql-client redis-tools

# Install nodejs for custom build
# https://superset.incubator.apache.org/installation.html#making-your-own-build
# https://nodejs.org/en/download/package-manager/
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
    && apt-get install -y nodejs

WORKDIR /home/superset

COPY requirements.txt .
COPY requirements-dev.txt .
COPY contrib/docker/requirements-extra.txt .

RUN pip install --upgrade setuptools pip \
    && pip install -r requirements.txt -r requirements-dev.txt -r requirements-extra.txt \
    && rm -rf /root/.cache/pip

RUN pip install gevent

COPY --chown=superset:superset superset superset

ENV PATH=/home/superset/superset/bin:$PATH \
    PYTHONPATH=/home/superset/superset/:$PYTHONPATH

USER superset

RUN cd superset/assets \
    && npm ci \
    && npm run build \
    && rm -rf node_modules

COPY contrib/docker/docker-init.sh .
COPY contrib/docker/docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

HEALTHCHECK CMD ["curl", "-f", "http://localhost:8088/health"]

EXPOSE 8088

docker-compose.yml:

version: '2'
services:
  redis:
    image: redis:3.2
    restart: unless-stopped
    ports:
      - "127.0.0.1:6379:6379"
    volumes:
      - redis:/data

  postgres:
    image: postgres:10
    restart: unless-stopped
    environment:
      POSTGRES_DB: superset
      POSTGRES_PASSWORD: superset
      POSTGRES_USER: superset
    ports:
      - "127.0.0.1:5432:5432"
    volumes:
      - postgres:/var/lib/postgresql/data

  superset:
    build:
      context: ../../
      dockerfile: contrib/docker/Dockerfile
    restart: unless-stopped
    environment:
      POSTGRES_DB: superset
      POSTGRES_USER: superset
      POSTGRES_PASSWORD: superset
      POSTGRES_HOST: postgres
      POSTGRES_PORT: 5432
      REDIS_HOST: redis
      REDIS_PORT: 6379
      # If using production, comment development volume below
      #SUPERSET_ENV: production
      SUPERSET_ENV: development
#      PYTHONUNBUFFERED: 1
    user: root:root
    ports:
      - 8088:8088
    depends_on:
      - postgres
      - redis
    volumes:
      # this is needed to communicate with the postgres and redis services
      - ./superset_config.py:/home/superset/superset/superset_config.py
      # this is needed for development, remove with SUPERSET_ENV=production
      - ../../superset:/home/superset/superset

volumes:
  postgres:
    external: false
  redis:
    external: false

为什么会出现未找到的错误?

【问题讨论】:

  • 您的地图体积将覆盖图像中的任何新事物
  • 你能提供一个minimal reproducible example吗? (注意最小=我们不需要安装> 50MB,完整=不取决于您的问题中未包含的文件,并且可重复=我们可以在我们自己的机器上运行它)
  • @Adiii 我不确定我是否理解正确。你的意思是我向 Maps 目录添加一个新文件并不重要,因为最终音量会保持不变?
  • 如果您随时构建映像,但它只会选择映射的卷数据。尝试删除音量,你会从更新的图像中看到。
  • @BMitch 不幸的是,我认为我不能将问题压缩成一个可以在您的机器上运行的 1 个 .py 和 1 个 .js 文件的简约问题,因为许多文件是相互连接的

标签: docker docker-compose dockerfile apache-superset


【解决方案1】:

尝试在volumes:中使用绝对路径

volumes:
  - /home/me/my_project/superset_config.py:/home/superset/superset/superset_config.py
  - /home/me/my_project/superset:/home/superset/superset

【讨论】:

  • 改变路径有什么不同?
  • 使用绝对路径将映射现有文件夹,使用相对 docker 将创建空卷
  • 据我所知,情况并非如此。正如文档所说:You can mount a relative path on the host, which expands relative to the directory of the Compose configuration file being used. Relative paths should always begin with . or ...,除此之外,您将失去可移植性,因为其他用户将不得不创建相同的用户等...
  • 切换到绝对路径没有任何改变
【解决方案2】:

这是因为docker-compose 正在使用缓存。如果 dockerfiledocker-compose.yml 未更改,则不会重新创建容器映像。为避免这种情况,您应该使用以下标志:

 --force-recreate

--强制重新创建

即使没有配置和镜像,也要重新创建容器 改变了。

出于开发目的,我也喜欢使用以下开关:

-V, --renew-anon-volumes

重新创建匿名卷,而不是从以前的容器中检索数据。

【讨论】:

  • 我在使用 force-recreate 标志时得到了相同的结果。我在问题的评论中提到了它
  • 你能告诉我们更多CountryMap目录在哪里吗?您是如何添加上述文件的?
  • 您好,该目录位于可视化文件夹superset/assets/src/visualizations/CountryMap/countries。我按照以下步骤添加了地图:superset.incubator.apache.org/…
  • 从源代码安装 superset 时,我可以看到地图并与之交互,但使用 Docker 我得到未找到错误
  • 嗯,你的构建上下文是context: ../../,你的音量是../../superset:/home/superset/superset,你确定你需要这些吗:../../
猜你喜欢
  • 2021-09-08
  • 2021-01-14
  • 2019-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多