2015-01-02 93 views
2

我有一个完美的外壳运行命令:翻译bash命令到码头工人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

现在我想从启动泊坞窗容器中运行这个命令。因此,在这Dockerfile的底部我:

CMD ["bash", "start-stop-daemon", "--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语法。有任何想法吗?

回答

0

使用主管似乎是更好的解决方案: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 
0

你想要做bash -c <command>而不是只有bash <command>

更改CMD到:

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

这会有所帮助,但现在我得到的错误:启动 - 停止守护:需要--start或--stop或--status之一。看起来该命令没有正确解析。 –

0

你并不需要翻译你的命令,使用shell form的CMD命令: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 
1

找出什么是完整路径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