安排容器的问题
我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是您正在使用Ofelia的
exec
作业,该作业试图将docker exec
纳入运行容器,该容器失败。您正在寻找的是
运行
作业,根据 docs ,运行新容器或启动现有容器。因此,我相信您应该更改标签的定义:文档说您在尝试执行
container
参数时必须在尝试执行Docker Start
时传递。我不确定您第一次运行时如何播放,但是我假设app
是第一次和以后的时间 ofelia 再次启动容器。I think the issue is that you're using ofelia's
exec
job, which tries todocker 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:The docs say you have to pass in the
container
parameter when trying to do adocker start
. I am not sure how it plays when you run it for the first time, but I assume thatapp
runs on its own the first time and later timesofelia
starts the container again.