Code Monkey home page Code Monkey logo

vscode-tutorial's Introduction

VScode Connects to remote Docker over SSH for Deep Learning Research

This is a tutorial on using VScode and Docker over SSH. If you would like to use VScode and Docker on a local computer, please refer to this tutorial.

We assume that you have successfully installed Docker engine in the remote machine. You need to know the basic knowledge about docker.
In gerenal, we first configure SSH service in docker container and then use the VScode Remote-SSH Extension to connect to the docker container.

Step 1 Configure SSH service in docker container:

  1. First connect to the remote machine. Refer to the Dockerfile of this repo, and create your own Dockerfile in a folder, for example /docker.
    The provided Dockerfile will configure the SSH service in docker container automatically.
    In Dockerfile, we install the openssh-server with the below command:
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y openssh-server    

Then, we modify /etc/ssh/sshd_config by setting UsePAM no and PermitRootLogin yes:

RUN \    
  sed -i "s/UsePAM yes/#UsePAM yes/" /etc/ssh/sshd_config && \
  sed -i "s/PermitRootLogin/#PermitRootLogin/" /etc/ssh/sshd_config && \
  echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && \
  echo 'UsePAM no' >> /etc/ssh/sshd_config 

We echo a command to /etc/bash.bashrc to start the SSH service when we open a bash:

RUN echo 'service ssh start' >> /etc/bash.bashrc

Finally, we can echo a password for the root of docker container in Dockerfile:

RUN echo 'root:your_password' | chpasswd       
  1. Enter in the folder that includes the Dockerfile and build a docker image in a termintal as follow:
$ cd ~/docker
$ docker build -t docker_image .
  1. Then create a docker container with docker_image and map the port 22 of this container to the other port of the remote machine with -p xxxx:22 :
$ docker run -it --shm-size 8G -p 1234:6006 -p 1022:22 --ipc host --name docker_container --gpus all -v ~/your_project:/workspace docker_image  /bin/bash   
$ (currently, you should be in the docker container as root)
  1. If you did not set your password in Dockerfile, then set a password for SSH connection manually, type passwd in the terminal and enter your password twice. (Skip this step, if your Dockerfile contains RUN echo 'root:your_password' | chpasswd)
    pic1
    Now we have finished the configuration of the SSH service in container.

Step 2 Connect to the docker container with VScode:

  1. Open VScode as a New Window. Then, click the Extensions. Search and install extenion Remote Development. This extension set consists of the Remote-SSH and other remote extensions:
    pic2

  2. Choose the the Remote-SSH: Open configuration file and open the /xxx/.ssh/config file as the following figure:
    pic3
    pic4

  3. Edit the config file as figure:
    pic5

  4. Click the left bottom icon again and select Remote-SSH:Connect Current Window to Host. Then choose the Hostname that you wrote in the config file:
    pic6
    pic7

  5. Enter the password you set for container root:
    pic8

  6. Now you have connected to the remote docker successfully. Install extensions in SSH:docker and enjoy your coding in remote docker.
    pic9
    pic10

Note: Remember that the container should be always started first when we connect it with VScode.

vscode-tutorial's People

Contributors

sarahgao-1995 avatar yuxiangsun avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.