Li Jiang
Li Jiang

Reputation: 11

How docker enable ssh connection

guys. I wanna set an ssh connection for my docker. Here are my steps.
My information:

Ubuntu:
  1. pull docker

    docker pull citybrainchallenge/cbengine:0.1.1
    
  2. go into the container, steps 2-5 are executed in the docker

    docker run -it citybrainchallenge/cbengine:0.1.1 bash
    
  3. install dependencies

    apt-get update
    apt-get install passwd openssl openssh-server openssh-clients
    
  4. change password

    passwd
    
  5. set the configuration, remove #

    vim /etc/ssh/sshd_config
    
    PubkeyAuthentication yes 
    PermitRootLogin yes 
    Port 22 
    
  6. save the container

    1. commit to a new container
    docker ps # check the container id 
    docker commit container_id new_image_id(I set: citybrainchallenge/cbengine:2.2)
    
  7. run the new container and test it

    docker run -it citybrainchallenge/cbengine:2.2 bash
    

    In the container, restart ssh

    service restart ssh 
    service --status-all # check ssh is +
    
  8. open a new terminal, Test its connection

    docker ps 
    docker port container_id 22
    

    However, it didn't work.

Upvotes: 1

Views: 385

Answers (1)

Sahil Kandroo
Sahil Kandroo

Reputation: 149

When you are running the container can you pass port forwarding argument and check if that is working docker run -p 22:22

Upvotes: 1

Related Questions