How can I start my PyTorch-based Docker container with a ssh server, and keep it alive?

Published

I have to create a Docker container based on the PyTorch base image, such that the ssh server starts automatically when the container starts, and the container stays alive. This way, I can connect through ssh as root (don’t ask). Instead, the container exits immediately. Here’s a minimal Dockerfile:

ARG PYTORCH="1.6.0"
ARG CUDA="10.1"
ARG CUDNN="7"

FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel

ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX"
ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all"
ENV CMAKE_PREFIX_PATH="$(dirname $(which conda))/../"

# SSH SERVER
RUN apt-get update && apt-get install openssh-server sudo -y
RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
RUN echo 'root:root' | chpasswd

WORKDIR /

EXPOSE 22
CMD ["service ssh start"]

NOTE: the actual Dockerfile is much more complex than this, so I need an answer with minimal modifications to this Dockerfile.

The Docker image builds nicely. However when I do

docker run -d -p 7224:22 --name ssh-server-test ssh-server-image

the container exits immediately, showing that the ssh server didn’t stay alive. As a matter of fact, if I launch the container in interactive mode:

docker run -it -d -p 7224:22 --name ssh-server-test ssh-server-image /bin/bash

and I connect with docker attach ssh-server-test, then the top command doesn’t show any ssh server running. Also, if I now manually execute

[email protected]:/# service ssh start
 * Starting OpenBSD Secure Shell server sshd  

the ssh server finally starts, proving that:

  • it was installed correctly
  • the issue is clearly in my Dockerfile.

Source: Docker Questions

Published
Categorised as docker, pytorch, server, ssh Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq