DarkLeafyGreen
DarkLeafyGreen

Reputation: 70406

Translate bash command to dockers CMD

I have a command that perfectly runs in the 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

Now I want to run this command from a docker container on startup. So at the bottom of the Dockerfile I have:

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"]

However the container exits with an error:

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

I think there is something wrong with the CMD syntax. Any ideas?

Upvotes: 2

Views: 781

Answers (4)

DarkLeafyGreen
DarkLeafyGreen

Reputation: 70406

Using supervisor seems to be the more elegant solution: 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

Upvotes: 1

Jiri Kremser
Jiri Kremser

Reputation: 12837

Find out what is the full path to the start-stop-daemon by running which start-stop-daemon and then use:

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"]

instead of CMD, you may want to use ENTRYPOINT

Upvotes: 2

Mario Marín
Mario Marín

Reputation: 131

You don't need to translate your command, use the shell form for the CMD instruction: 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

Upvotes: 1

manojlds
manojlds

Reputation: 301077

You want to do bash -c <command> instead of just bash <command>.

Change your CMD to:

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

Upvotes: 1

Related Questions