安排容器的问题

发布于 2025-02-01 10:08:25 字数 2399 浏览 1 评论 0原文

我的Docker-Compose看起来像这样:

version: '3.7'

services:
  app:
    container_name: container1
    #restart: unless-stopped
    build:
      context: .
      dockerfile: Dockerfile
    labels:
      ofelia.enabled: "true"
      ofelia.job-exec.app.schedule: "@every 30m"
      ofelia.job-exec.app.command: "/app/Final_DM_For_All_Clients.py"

  ofelia:
    image: mcuadros/ofelia:latest
    #restart: unless-stopped
    depends_on:
      - app
    command: daemon --docker
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:r

第一次运行后,第二次作业跑步不会在30分钟内发生,我得到了 在第二次运行中以下错误。

container1-ofelia-1  | 2022-05-24T22:59:02.037Z  common.go:121 ▶ ERROR [Job "app" (3d8aab0fe293)] Finished in "3.322350449s", failed: true, skipped: false, error: error creating exec: API error (409): Container 65f90ee04e25d1164d29ab911197d239873da3eafbc34823873d3ba2d791a0ad is not running

我的Docker文件看起来像这样:

FROM python:3.8 

#ADD Final_DM_For_All_Clients.py /
RUN /usr/local/bin/python -m pip install --upgrade pip
RUN pip install pandas
RUN pip install numpy 
RUN pip install datetime
RUN pip install uuid 
RUN apt-get update && apt-get install -y gcc unixodbc-dev 
RUN pip install pyodbc

# install SQL Server drivers
#RUN apt-get update \
#    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
#    && curl https://packages.microsoft.com/config/debian/9/prod.list \
#        > /etc/apt/sources.list.d/mssql-release.list \
#        msodbcsql17


RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
RUN curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list

RUN apt-get update 
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools

RUN curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose



RUN apt-get update && apt-get install -y cron && apt-get install vim -y




COPY . /app
WORKDIR /app

ADD df_curr.csv .
ADD df_prev.csv .
ADD df_roster.csv .
ADD df.csv .
ADD manager_name.csv .
ADD name_data.csv .

EXPOSE 8080 

CMD python Final_DM_For_All_Clients.py

第一次运行后,具有代码0的容器退出,表示成功运行,但在第二个计划运行IE IE IE时,由于容器停止,Scheduler无法在第二个脚本中运行该脚本跑步。

My docker-compose looks like this:

version: '3.7'

services:
  app:
    container_name: container1
    #restart: unless-stopped
    build:
      context: .
      dockerfile: Dockerfile
    labels:
      ofelia.enabled: "true"
      ofelia.job-exec.app.schedule: "@every 30m"
      ofelia.job-exec.app.command: "/app/Final_DM_For_All_Clients.py"

  ofelia:
    image: mcuadros/ofelia:latest
    #restart: unless-stopped
    depends_on:
      - app
    command: daemon --docker
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:r

After the first run, the second job run does not happen in 30 mins and I am getting the
following error during the second run.

container1-ofelia-1  | 2022-05-24T22:59:02.037Z  common.go:121 ▶ ERROR [Job "app" (3d8aab0fe293)] Finished in "3.322350449s", failed: true, skipped: false, error: error creating exec: API error (409): Container 65f90ee04e25d1164d29ab911197d239873da3eafbc34823873d3ba2d791a0ad is not running

My docker file looks like this:

FROM python:3.8 

#ADD Final_DM_For_All_Clients.py /
RUN /usr/local/bin/python -m pip install --upgrade pip
RUN pip install pandas
RUN pip install numpy 
RUN pip install datetime
RUN pip install uuid 
RUN apt-get update && apt-get install -y gcc unixodbc-dev 
RUN pip install pyodbc

# install SQL Server drivers
#RUN apt-get update \
#    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
#    && curl https://packages.microsoft.com/config/debian/9/prod.list \
#        > /etc/apt/sources.list.d/mssql-release.list \
#        msodbcsql17


RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
RUN curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list

RUN apt-get update 
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools

RUN curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose



RUN apt-get update && apt-get install -y cron && apt-get install vim -y




COPY . /app
WORKDIR /app

ADD df_curr.csv .
ADD df_prev.csv .
ADD df_roster.csv .
ADD df.csv .
ADD manager_name.csv .
ADD name_data.csv .

EXPOSE 8080 

CMD python Final_DM_For_All_Clients.py

After the first run the container exits with code 0 indicating a successful run but on the second scheduled run i.e. at 1 hr, since the container is stopped, the scheduler is not able to run the script during the second run.

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

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

发布评论

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

评论(1

梦里人 2025-02-08 10:08:25

我认为问题是您正在使用Ofelia的exec作业,该作业试图将docker exec纳入运行容器,该容器失败。

您正在寻找的是运行作业,根据 docs ,运行新容器或启动现有容器。因此,我相信您应该更改标签的定义:

ofelia:
   ...  # Your configs

   labels: 
      ofelia.enabled: "true"
      ofelia.job-run.app.schedule: "@every 30m"
      ofelia.job-run.app.container: "container1"

   ...  # Your configs

文档说您在尝试执行container参数时必须在尝试执行Docker Start时传递。我不确定您第一次运行时如何播放,但是我假设app是第一次和以后的时间 ofelia 再次启动容器。

I think the issue is that you're using ofelia's exec job, which tries to docker exec into a running container, which fails.

What you are looking for is the run job which, according to the docs, either runs a new container or starts an existing one. So I believe you should change your labels definition like this:

ofelia:
   ...  # Your configs

   labels: 
      ofelia.enabled: "true"
      ofelia.job-run.app.schedule: "@every 30m"
      ofelia.job-run.app.container: "container1"

   ...  # Your configs

The docs say you have to pass in the container parameter when trying to do a docker start. I am not sure how it plays when you run it for the first time, but I assume that app runs on its own the first time and later times ofelia starts the container again.

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