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:
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
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
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