Docker Cron 未启动:“未知标志:--rm”
Posted
技术标签:
【中文标题】Docker Cron 未启动:“未知标志:--rm”【英文标题】:Docker Cron does not start: "unknown flag: --rm" 【发布时间】:2021-11-27 00:38:15 【问题描述】:遇到的问题:
命令* * * * * $(command -v docker) docker run --rm -it --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA
不会启动。这是在文件中测试的
日志电子邮件始终打印:
unknown flag: --rm
See 'docker --help'.
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
...
如果我手动运行命令(没有 cron),它就像一个魅力 (docker run --rm -it --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA
)。同样适用于docker run --rm -it --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest balance
????
我的系统:
我在 Raspberry Pi 4 上运行 ubuntu OS 20.04.3 LTS 64bit。
Docker 本身是本地安装的 (sudo apt install docker.io
)
Docker compose 是使用 Python3-pip 设置的(你知道,docker 的 aarch64 架构问题......)
docker version
的输出:
Client:
Version: 20.10.7
API version: 1.41
Go version: go1.13.8
Git commit: 20.10.7-0ubuntu1~20.04.2
Built: Fri Oct 1 14:05:40 2021
OS/Arch: linux/arm64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.8
Git commit: 20.10.7-0ubuntu1~20.04.2
Built: Fri Oct 1 03:27:17 2021
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.5.2-0ubuntu1~20.04.3
GitCommit:
runc:
Version: 1.0.0~rc95-0ubuntu1~20.04.2
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
docker info
的输出:
Client:
Context: default
Debug Mode: false
Server:
Containers: 3
Running: 2
Paused: 0
Stopped: 1
Images: 3
Server Version: 20.10.7
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version:
runc version:
init version:
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.4.0-1044-raspi
Operating System: Ubuntu 20.04.3 LTS
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 1.805GiB
Name: ubuntu
ID: JFJA:TP4G:DR7E:2ZRU:A4SL:KOQY:V2CG:5RQP:B2E4:VT4T:ZYWS:TFHO
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory TCP limit support
WARNING: No oom kill disable support
docker image inspect [imageID]
的输出:
[
"Id": "sha256:31f6111bddfcb06247fd5f8281b11f992826b088e557829c1673b2a440384bc8",
"RepoTags": [
"ghcr.io/sebastix/crypto-dca:latest"
],
"RepoDigests": [
"ghcr.io/sebastix/crypto-dca@sha256:0af2b744cba7a8a8749ea01cadcdc468dee5f144a0adbc9e2bc6afa36409e7ff"
],
"Parent": "",
"Comment": "buildkit.dockerfile.v0",
"Created": "2021-08-17T19:38:45.819153753Z",
"Container": "",
"ContainerConfig":
"Hostname": "",
"Domainname": "",
"User": "",
...
sudo crontab -e
的输出:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
#
# Bitcoin-dca by Sebastix
MAILTO="my@mail.com"
* * * * * $(command -v docker) docker run --rm -it --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA
#
【问题讨论】:
如果您删除第二个docker
出现,那么它会起作用吗? $(command -v docker)
的输出已经是 Docker 二进制文件的路径。所以试试:$(command -v docker) run --rm -it --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA
@MarkoE:这也行不通。错误:“输入设备不是 TTY”。我假设,docker
命令是强制性的,无论路径中是否出现相同的情况(在我的情况下:command -v docker
打印 /usr/bin/docker
)。
您需要删除 -it
部分,因为您将其作为 cron 脚本运行。
@MarkoE 在没有-it
的情况下运行仍然无法工作。错误:unknown flag: --rm
命令:* * * * * $(command -v docker) docker run --rm --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA
@MarkoE:非常感谢您的耐心等待!这样就解决了问题。工作命令:* * * * * $(command -v docker) run --rm --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA --yes
(我已经附加了--yes
,所以它会自动执行购买而不要求确认。
【参考方案1】:
解决方案很简单:我必须同时删除 -it
和第二个 docker
语句。
工作指令:* * * * * $(command -v docker) run --rm --env-file=/home/ubuntu/.env ghcr.io/sebastix/crypto-dca:latest buy 10 ADA --yes
附加的-yes
会自动执行购买,无需确认。
#感谢@MarkoE 帮助我解决了我的问题!
【讨论】:
很高兴我能帮上忙,祝 Cardano 好运。 :)以上是关于Docker Cron 未启动:“未知标志:--rm”的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Docker 容器中以非 root 用户身份启动 cron?
在我将 cron 文件重新保存在 docker 容器中之前,Cron 作业不起作用