2

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

启动-停止-守护进程 --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

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

CMD ["bash", "start-stop-daemon", "--quiet", "--oknodo", "--start", "--pidfile", "/run/myprocess.pid", "--背景”、“--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 语法有问题。有任何想法吗?

4

4 回答 4

2

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

CMD ["/full_path_to_the_bin_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"]

而不是CMD,您可能想要使用ENTRYPOINT

于 2015-01-02T22:45:40.887 回答
1

你想做bash -c <command>的不仅仅是bash <command>.

将您更改CMD为:

CMD ["bash", "-c", "start-stop-daemon", ...]
于 2015-01-02T10:21:33.837 回答
1

你不需要翻译你的命令,使用 CMD 指令的shell 形式CMD command 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
于 2015-01-02T19:12:26.517 回答
1

使用主管似乎是更优雅的解决方案:https ://docs.docker.com/articles/using_supervisord/

[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
于 2015-01-19T17:00:57.693 回答