skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search