How Linux hosts use SSH to log in to a Docker container

Source: Internet
Author: User
Tags docker ps docker run

Host: Xubuntu 15.04 + Docker

  1. Enter terminal, sudo-i, switch root, input docker-d

  2. Open another terminal, switch root, enter the Docker search Ubuntu, probably the following result:

  3. NAME DESCRIPTION STARS Official automated
    Ubuntu Ubuntu is a debian-based Linux operating s ... 2306 [OK]
    Ubuntu-upstart Upstart is a event-based replacement for ... [OK]
    Torusware/speedus-ubuntu always updated official Ubuntu Docker imag ... [OK]
    Tleyden5iwx/ubuntu-cuda ubuntu 14.04 with Cuda drivers pre-installed [OK]
    Ubuntu-debootstrap debootstrap--variant=minbase--components ... [OK]
    Guilhem/vagrant-ubuntu [OK]

  4. Enter Docker pull Ubuntu and the system will download the image from the first one

  5. After the download is complete, you can enter Docker images to see if the image has been downloaded to a local

  6. Start an Ubuntu container and enter Bash,docker run-it Ubuntu/bin/bash,

  7. It should be possible to see [email protected]:/#, which proves that the container has been successfully activated, and that bash into the container

  8. Modify the root password of the container: passwd until you enter a new password, for example: 123456

  9. Installing Vim,apt-get Install Vim-y

  10. Install the openssh-server of the container, enter Apt-get install Openssh-server-y

  11. After successful installation, Vim/etc/ssh/sshd_config, modify the following two configurations

  12. Permitrootlogin Yes
    Usepam No

  13. Start SSH services, service ssh start

  14. Exit the container, enter exit, then enter Docker ps-a to see the container ID

  15. The commit container becomes the new image, for example, called Ubuntu-ssh, enter the Docker commit container ID ubuntu-ssh

  16. Start this mirrored container and map a local idle port (for example 10000) to the container's 22 port and start the container for sshd Docker run-d-P 10000:22 ubuntu-ssh/usr/sbin/sshd-d

  17. Now open the new terminal, enter SSH [email protected]-P 10000, if you can link successfully, will be required to enter the password, input just 123456 can enter the terminal of the container




How the Linux host uses SSH to log in to the Docker container

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.