2015-01-02 94 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