0

I'm using dockerfile to create an Image And I want every time when the docker container starts the ssh connection should also start and then the ngrok should also start but I'm not able to use CMD command can you guys please help me with it.

FROM ubuntu
ENTRYPOINT  echo "Entering......"; bin/bash; ngrok tcp 22
RUN apt-get update
RUN apt-get install curl -y
RUN apt-get install openssh-server -y
RUN curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | tee /etc/apt/sources.list.d/ngrok.list && apt update && apt-get install ngrok  
RUN ngrok authtoken 25dYasdvM3C1IkDtT9QEG7ZwIWw_59Ar5Hp4NcrusbyVAu6Sv
CMD echo "SSH starting"
CMD service ssh start
CMD echo "SSH started"
CMD echo "started creating log file"
CMD echo "file created!!"
CMD ngrok tcp 22 --log=stdout > ngrok.log &
CMD echo "log file created"
CMD touch hello.txt
CMD echo "simple file created"
CMD echo "log file created and esatablished network successully"
CMD echo "working fine"
CMD echo "Starting!!!!"
  • In addition to the answers here and in the linked question, consider restructuring this setup to run only one process per container, as a foreground process, and without needing an ssh daemon. – David Maze Mar 02 '22 at 10:55

2 Answers2

0

To use multiple startup commands you need to either join them together using & or create an executable, something like this: Dockerfile:

...
CMD /start.sh

start.sh:

#!/bin/bash
service ssh start
ngrok tcp 22 --log=stdout > ngrok.log
....

Make sure the last command does not exit or the container will shutdown too. There are issues with running multiple commands like you cannot get logs using "docker logs" from the commands you ran, only the last executable etc.

RoifGroup
  • 16
  • 1
0

The can only be one CMD command, incase we provide multiple ones in a docker file the last one will take effect. https://docs.docker.com/engine/reference/builder/#cmd