Wondering what I may be doing wrong, currently trying to revise this CMD to the proper format but it’s not running right. The original w/ no edit is running good, but using the array version is not. Does combining commands not work in the proper format, or what may I be missing? Modified version when run immediately exits once it starts
Original:
CMD sshd & cd /app && npm start
Modified:
CMD ["sshd", "&", "cd", "/app", "&&", "npm", "start"]
My complete dockerfile:
FROM node:10-alpine
WORKDIR /app
COPY . /app
RUN npm install && npm cache clean --force
# CMD sshd & cd /app && npm start
# CMD ["sshd", "&", "cd", "/app", "&&", "npm", "start"]
2
Answers
Define a script and put all of your commands into this script.
Eg: I call this script is
startup.sh
And call this script in CMD
You should:
sshd
: it’s not installed in your image, it’s unnecessary, and it’s all but impossible to set up securely.cd
part, since theWORKDIR
declaration above this has already switched into that directory.CMD
is just a simple command.If you want to run multiple commands or attempt to launch an unmanaged background process, all of these things require a shell to run and you can’t usefully use the
CMD
exec form. In the form you show in the question the main command issshd
only, and it takes 6 arguments including the literal strings&
and&&
.