将bash命令转换为dockers CMD

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

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

现在我想在启动时从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语法有问题。 有任何想法吗?

通过运行which start-stop-daemon来查找start-stop-daemon的完整path,然后使用:

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

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

将您的CMD更改为:

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

您不需要翻译您的命令,使用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 

使用主pipe似乎是更优雅的解决scheme: 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