I am having a weird problem.

I am not able to ssh to docker container having ip address

I am getting following error:

$ ssh
ssh: connect to host port 22: Connection refused

My Dockerfile does contain openssh-server installation step:

RUN apt-get -y install curl runit openssh-server

And also step to start ssh:

RUN service ssh start

What could be the issue?

When I enter into container using nsenter and start ssh service then I am able to ssh. But while creating container ssh-server doesn't seems to start.

What should I do?


Container vs. Image

The RUN statement is used to run commands when building the docker image.
With ENTRYPOINT and CMD you can define what to run when you start a container using that image.
See Dockerfile Reference for explanations how to use them.


There is not preinstalled init-system in the containers, so you cannot use service ... start in a container.
Consider starting the process in the CMD statement as foreground process or use an init-system like Phusion or Supervisord.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.