Skip to content

Attach to job using SSH

Yurii Rebryk edited this page Jan 13, 2019 · 1 revision

1. Create a Dockerfile

Create a docker image with ssh server. Example of the Dockerfile:

# Dockerfile
FROM ufoym/deepo:all-py36

# Install req
RUN apt-get update &&  \
    apt-get -y install openssh-server wget curl rsync vim git htop less && \
    apt-get clean && \
    rm /var/lib/apt/lists/*_* # to keep container small

RUN mkdir -p /var/run/sshd
RUN mkdir -p /root/.ssh
ADD id_rsa.pub /root/.ssh/id_rsa.pub
RUN cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
RUN chmod 700 /root/.ssh/
RUN chmod 600 /root/.ssh/authorized_keys

RUN echo "export PATH=$PATH" >> /etc/profile && \
  echo "ldconfig" >> /etc/profile

# add run script
CMD ["/usr/sbin/sshd", "-D"]

# expose port 
EXPOSE 22

Notice that we use id_rsa.pub, but in your case it can be another filename, e.g neuromation_rsa.pub, so check your ~/.ssh/ folder and change Dockerfile.

2. Build a Docker image

Copy your ssh public key in current working directory containing the Dockerfile and build an image:

$ cp ~/.ssh/id_rsa.pub .
$ docker build -t my_first_ssh .
Successfully built 939e6605a254
Successfully tagged my_first_ssh:latest

3. Upload your image

$ neuro image push my_first_ssh:latest

4. Create a job

Enable SSH port forwarding to container:

$ neuro job submit --ssh 22 --volume storage://<USERNAME>:/data:rw registry.staging.neuromation.io/<USERNAME>/my_first_ssh:latest

5. Attach to the job

Attach to the job using private key:

$ neuro job ssh --key ~/.ssh/id_rsa job-9e5dd0e7-1583-4581-a413-f0bf809a08c2
...  
root@job-9e5dd0e7-1583-4581-a413-f0bf809a08c2:~#

Enjoy!