Create a docker image that supports SSH

Source: Internet
Author: User

Docker container run, generally cannot ssh, this container management brings trouble, below will explain how to create a docker image that supports SSH

  1. Download the Ubuntu image from the dock hub first

    Command: Docker pull Ubuntu

  2. Create a new Ssh_ubuntu directory

    Mkdir/ssh_ubuntu

  3. Cd/ssh_ubuntu; Touch Dockerfile

  4. VI Dockerfile

    Dockerfile Content

    From Ubuntu
    Maintainer Lincoln_zhong
    RUN apt-get Update
    RUN apt-get install-y openssh-server sudo
    RUN mkdir-p/var/run/sshd
    RUN Sed-ri ' s/session required pam_loginuid.so/#session required pam_loginuid.so/g '/etc/pam.d/sshd
    RUN Useradd Admin
    RUN echo "Admin:admin" | chpasswd
    RUN echo "admin all= (All) all" >>/etc/sudoers
    EXPOSE 22
    CMD ["/usr/sbin/sshd", "-D"]
    650) this.width=650; "title=" capture. JPG "src=" http://s3.51cto.com/wyfs02/M02/6E/D4/wKiom1WJHhnAm7gXAAF7-nuigdQ137.jpg "alt=" Wkiom1wjhhnam7gxaaf7-nuigdq137.jpg "/>

  5. Cd/ssh_ubuntu. Run Docker build-t Ssh_ubuntu. #ssh_ubuntu是镜像名称

  6. Running Docker images

    650) this.width=650; "title=" capture. JPG "src=" http://s3.51cto.com/wyfs02/M02/6E/D4/wKiom1WJHoqBBBSEAAKVgQxRIgE289.jpg "alt=" Wkiom1wjhoqbbbseaakvgqxrige289.jpg "/>

  7. Run a Container test command: Docker run-d--name ssh_ubuntu_test-p 0.0.0.0:10000:22 Ssh_ubuntu

    Command parsing

    -D is started in daemon mode

    --name Defining container Names

    -P is a port that defines ports (above this means that 10000 ports on the local host (host) are mapped to the 22 ports of the container

    650) this.width=650; "title=" capture. JPG "src=" http://s3.51cto.com/wyfs02/M00/6E/D4/wKiom1WJHzySz_p4AADelmZ_ODM797.jpg "alt=" wkiom1wjhzysz_p4aadelmz_ Odm797.jpg "/>

  8. Container ssh_ubuntu_test run successfully, SSH login container Test command: SSH [email protected] host Ip-p 10000 I'm here for 10.10.1.181.

    SSH [email protected]-P 10000

  9. Test success

  10. CentOS-built container dockerfile content for SSH support

This article is from the "Last Night Rain Wind Sudden" blog, please be sure to keep this source http://zxx287856774.blog.51cto.com/3417296/1664682

Create a Docker image that supports SSH

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.