SSH into Docker? or docker on SSH? and I need command

Issue

I’m new to DL, and docker and even not familiar with Linux and internet things (SSH and port.. DNS things.. part of them are only existing in my mind). Thus, I’d be so much happy with “specific explanation + command” (or reference sites).

My basic questions are:

  1. what is superior concept between Docker and SSH? (running SSH on the Docker ? or running Docker on SSH? or both are possible?)

  2. Which specific command should I use if I want to use SSH+Docker+Pytorch+Jupyternotebook+visdom ?

    2-1) I run SSH first (which is my lab’s server, thus I am not usually root user, so if I want to run python file here, I face with permission denied often), let say SSH address is 123.456.789.999

    2-2) use docker after running ssh (however, what I found from many posts are about running docker FIRST and then access to SSH.. how’s it different?)

    2-2-1) so for this, I now I have to pull a image which includes pytorch, jupyternotebook. I’ve done it

    2-2-2) I need to RUN DOCKER using image with proper COMMAND LINE. What makes me confused is here.

    $docker run -it --[name] -p 8888:8888 [docker_image_with_pytorch]
    

this is what I found. I assume to use jupyter notebook (let’s say if I want to use 4444 instead of 8888, and visdom as 5555 instead of 8097) then I need to map port from host to docker for two times and is it right?

$docker run -it --[name] -p 4444:8888 -p 5555:8097 [docker_image_with_pytorch]

Finally I need to link SSH(let’s say SSH port num:22 as general, ip: 123.456.789.999, id=heyjude) for SSH, I also found command below.

$ ssh -L <host port>:localhost:<remote port> [email protected]

But is it general to use command after running docker instead of adding option when I first run docker? also if I assume to use that command for setting SSH, i’m confused which things I need to input ;(
(host port=22 ? for SSH? localhost is just literal expression? remote port is arbitrary thing?) Below is my assumption..

$ ssh -L <22>:localhost:<12345> [email protected] 

I know it’s so messy and you may catch how my thinking is twisted..
it would be very helpful for me to explain from the scratch..

Thank you.

Solution

Your question is somewhat unclear. I’m going to take a guess at what you’re trying to solve.

Assuming (!) that you’ve a container image that includes PyTorch and Jupyter and all their dependencies, it’s likely that Jupyter will serve content to you via a web server (via HTTP and I suspect) over port :8888.

If you docker run -it ... which is equivalent to docker run --interactive --tty ..., you should see log output from the process(es) running in the container. These logs should contain relevant information.

To access the Jupyter Notebook once the container is running on your location workstation, you should be able to just browse http://localhost:8888.

You probably do not need to use SSH if you’re running everything locally. If you are running e.g. the docker container, on a remote host, you may SSH into the remote host first, run the commands e.g. docker run... but you may alternatively simply configure your Docker client to access the remote Docker Engine.

Somewhat akin to SSH, when using Docker containers, you may execute commands in the container. But, you are able to do this using docker exec ....; you don’t need to use SSH to interact with containers.

A container image has one or more statically defined ports that the container will use to expose its services (over TCP|UDP). When you run the container, you may map the container ports to different ports on your host. This may be for necessity (if the container port is already being used on your host) or just for convenience. To do this you use --publish=[HOST-PORT]:[CONTAINER-PORT]. For a given container image, you cannot change the [CONTAINER-PORT] but you may use any available [HOST-PORT]. In your example --publish=4444:8888 would mean that the Jupyter (?) service is now accessible on your local machine via localhost:4444. Docker port forwards traffic from your host’s :4444 to the container’s :8888.

Answered By – DazWilkin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published