0

My docker-compose.yaml file is as below

version: '3'
services:
  client:
    image: thusithathilina/my_image
    ports:
      - "5000:22"
    command: ["/usr/sbin/sshd"]
    stdin_open: true
    tty: true

But this doesn't start the container in interactive mode. I want to start the ssh at container startup with interactive mode. Could someone point what I'm doing wrong here?

Host is Linux 9a65bd45c029 3.13.0-128-generic #177-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux I used

docker-compose run client
  • What is your host operating system, and what command/arguments are you using with docker-compose? – Sagar Sep 11 '17 at 13:34
  • @SagarI've updated the question with that info :) – Thusitha Thilina Dayaratne Sep 11 '17 at 15:39
  • According to https://stackoverflow.com/questions/36249744/interactive-shell-using-docker-compose, your command should've worked. The only difference is the command has an extra argument `docker-compose run --rm client`. Have you tried that? I also noticed that you're giving "client" to your docker-compose command. Can you set a name to the container, and try that instead? (not sure it will make a difference, but still) – Sagar Sep 11 '17 at 17:10
  • Can you post your dockerfile also? – Tarun Lalwani Sep 11 '17 at 17:46
  • @Sagar I dont have a seperate docker file. I just pull the image and use "docker-compose run client" to start the container. Yes I tried that too, But no luck :( – Thusitha Thilina Dayaratne Sep 12 '17 at 05:08
  • What version of docker-compose are you using? – Sagar Sep 12 '17 at 14:28

1 Answers1

0

If your container does not spawn a long-running process by itself, docker-compose run would cause it to run and the exit immediately. Alternatively you could issue a command:

docker-compose run client sh

to attach to the open shell session putting you in an interactive mode. If that's not what you're looking for, you need to make sure that the command that you specified (command: ["/usr/sbin/sshd"]) is handled correctly by your container. One way of doing it would be to end your entrypoint script with (last line in my entrypoint script):

exec "$@"

Following on the above, one reason why your container exists in spite of seemingly correct command being issued (/usr/sbin/sshd) is that perhaps your entrypoint overrides / does not keep it running.

luqo33
  • 8,001
  • 16
  • 54
  • 107