How to SSH into Docker?

前端 未结 5 1101
说谎
说谎 2020-12-02 05:25

I\'d like to create the following infrastructure flow:

5条回答
  •  暖寄归人
    2020-12-02 05:42

    Firstly you need to install a SSH server in the images you wish to ssh-into. You can use a base image for all your container with the ssh server installed. Then you only have to run each container mapping the ssh port (default 22) to one to the host's ports (Remote Server in your image), using -p :. i.e:

    docker run -p 52022:22 container1 
    docker run -p 53022:22 container2
    

    Then, if ports 52022 and 53022 of host's are accessible from outside, you can directly ssh to the containers using the ip of the host (Remote Server) specifying the port in ssh with -p . I.e.:

    ssh -p 52022 myuser@RemoteServer --> SSH to container1

    ssh -p 53022 myuser@RemoteServer --> SSH to container2

提交回复
热议问题