Docker uses Dockerfile to create a container mirror that supports SSH services from boot _docker

Source: Internet
Author: User
Tags ssh docker run

The example of this article for you to share the Dockerfile to create support for SSH service from the launch of the container mirror, for your reference, the specific content as follows

1. First create a Dockerfile file with the following contents

# Select an existing OS mirror as

the author of the base from CENTOS:CENTOS6 # mirror
maintainer fanbin Kong "kongxx@hotmail.com"

# Install the Openssh-server and sudo packages and set the sshd usepam parameters to no
RUN yum install-y openssh-server sudo
RUN sed-i ' S/usepam yes/ Usepam no/g '/etc/ssh/sshd_config 

# Add Test user admin, Password Admin, and add this user to sudoers
run Useradd admin
run Echo Admin:admin "| CHPASSWD
RUN echo "admin  all= all    " >>/etc/sudoers

# The following two sentences are special, they must be on the CENTOS6, Otherwise the created container sshd cannot log on to
run ssh-keygen-t dsa-f/etc/ssh/ssh_host_dsa_key
run ssh-keygen-t rsa-f Host_rsa_key

# starts sshd service and exposes 22 port
RUN mkdir/var/run/sshd
expose
CMD ["/usr/sbin/sshd", "D"]

The Dockerfile file has its own syntax and commands, and you can refer to Docker's official documentation.

2. With the Dockerfile file, you can create image files based on Dockerfile, and in the directory where Dockerfile is located, run the following command

sudo docker build-t centos6-ssh.

When the command succeeds, an image named Centos6-ssh is created and can be viewed using the sudo docker images.

3. At this point, you can create your own container based on the image file created above, and the following command creates a container named "MyTest".

sudo docker run-d-P--name=mytest centos6-ssh

4. With the container, you can test our SSH service.

4.1 Run "sudo docker inspect mytest", view the current boot container IP address, and then run the following command to test

SSH admin@< Container ip>

4.2 Alternatively, you can access through the Docker port map, use the sudo docker port mytest 22 to view the port of the host machine for the current container's 22 ports, and then access the following command

SSH admin@< host machine ip>-p < host machine port >

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.