将bash命令转换为dockers CMD

将bash命令转换为dockers CMD,docker,dockerfile,Docker,Dockerfile,我有一个在shell中完美运行的命令: start-stop守护进程--quiet--oknodo--start--pidfile/run/my.pid --后台--生成pidfile--exec/opt/socat-1.7.2.4/socat PTY,link=/dev/ttyMY,echo=0,raw,unlink close=0 TCP-LISTEN:9334,reuseaddr,fork 现在我想在启动时从docker容器运行这个命令。因此,在Dockerfile的底部,我有: CMD[

我有一个在shell中完美运行的命令:

start-stop守护进程--quiet--oknodo--start--pidfile/run/my.pid --后台--生成pidfile--exec/opt/socat-1.7.2.4/socat PTY,link=/dev/ttyMY,echo=0,raw,unlink close=0 TCP-LISTEN:9334,reuseaddr,fork

现在我想在启动时从docker容器运行这个命令。因此,在Dockerfile的底部,我有:

CMD[“bash”、“启动-停止守护程序”、“--quiet”、“--oknodo”、“--start”, “--pidfile”、“/run/myprocess.pid”、“--background”、“--make pidfile”, “--exec”、“/opt/socat-1.7.2.4/socat”, “PTY,link=/dev/ttyPROCESS,echo=0,raw,unlink-close=0”, “TCP-LISTEN:9334,reuseaddr,fork”]

但是,容器退出时出错:

/sbin/start-stop-daemon: /sbin/start-stop-daemon: cannot execute binary file

我认为CMD语法有问题。有什么想法吗?

你想做
bash-c
而不仅仅是
bash

CMD
更改为:

CMD ["bash", "-c", "start-stop-daemon", ...]

您不需要翻译命令,使用CMD指令的:
CMD命令param1 param2

CMD start-stop-daemon --quiet --oknodo --start --pidfile /run/my.pid --background --make-pidfile --exec /opt/socat-1.7.2.4/socat PTY,link=/dev/ttyMY,echo=0,raw,unlink-close=0 TCP-LISTEN:9334,reuseaddr,fork

通过运行
which start-stop-daemon
找出
start-stop-daemon
的完整路径,然后使用:

CMD[“/full\u path\u to\u the_bin\u file/start stop daemon”、“--quiet”、“--oknodo”、“--start”、“--pidfile”、“/run/my.pid”、“--background”、“--make pidfile”、“--exec”、“/opt/socat-1.7.2.4/socat”、“PTY、link=/dev/ttyMY、echo=0、raw、unlink close=0、TCP-LISTEN:9334、reuseaddr、fork”


您可能希望使用
ENTRYPOINT

而不是
CMD
,使用supervisor似乎是更优雅的解决方案:


这很有帮助,但现在我得到了一个错误:start-stop守护进程:需要一个--start或--stop或--status。命令的解析似乎不正确。
[supervisord]
nodaemon=true

[program:sshd]
command=/usr/sbin/sshd -D

[program:socat]
command=/bin/bash -c socat PTY,link=/dev/ttyCUSTOM,echo=0,raw,unlink-close=0 TCP-LISTEN:%(ENV_SERIAL_PORT)s,reuseaddr,fork