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.