Using docker to run a node application i am unable to access it via SSH in the azure portal. I have added an ssh config file and am using apk add openssh. The app runs fine without adding the commands to add SSH. No clue how to get it to work correctly. Getting azure connection refused
FROM node:14-alpine as builder
WORKDIR /app/
COPY package.json yarn.lock /app/
RUN yarn
ADD . .
RUN yarn build
FROM node:14-alpine as runner
WORKDIR /app/
ENV NODE_ENV=production
COPY --from=builder /app/build /app/
COPY --from=builder /app/package.json /app/yarn.lock /app/
COPY src/database/prisma/schema.prisma /app/prisma/
RUN yarn
COPY docker/sshd_config /etc/ssh/
RUN mkdir /var/run/sshd
RUN apk add openssh && echo "root:MyP@ssword1" | chpasswd
#EXPOSE 8080
#CMD node web_server/index.js
EXPOSE 8080 2222
CMD /usr/sbin/sshd &; node web_server/index.js
If your app runs fine, try to add the followings:
Add a sshd_config
file to your repository, like the following example.
Port 2222
ListenAddress 0.0.0.0
LoginGraceTime 180
X11Forwarding yes
Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
MACs hmac-sha1,hmac-sha1-96
StrictModes yes
SyslogFacility DAEMON
PasswordAuthentication yes
PermitEmptyPasswords no
PermitRootLogin yes
Subsystem sftp internal-sftp
In your Dockerfile, try to add the following commands:
# ssh
COPY docker/sshd_config /etc/ssh/
RUN mkdir /var/run/sshd
RUN apk add openssh && echo "root:MyP@ssword1" | chpasswd
COPY sshd_config /etc/ssh/
COPY init.sh /usr/local/bin/
EXPOSE 8080 2222
CMD ["bash","init.sh"]
Add init.sh
in the root folder of your project.
#!/bin/bash
set -e
echo "Starting SSH ..."
service ssh start
node web_server/index.js
Or, change your last code to CMD ["/usr/sbin/sshd","-D", "node web_server/index.js"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.