docker example

来源:互联网 发布:超越时时彩软件 编辑:程序博客网 时间:2024/06/14 15:47

Dockerizing an SSH Daemon Service


1.dockerfile

# sshd## VERSION               0.0.1FROM     ubuntu:14.04MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com"RUN apt-get update && apt-get install -y openssh-serverRUN mkdir /var/run/sshdRUN echo 'root:screencast' | chpasswdRUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_configEXPOSE 22CMD ["/usr/sbin/sshd", "-D"]

Build the image using:

$ sudo docker build -t eg_sshd .

Then run it. You can then use docker port to find out what host portthe container's port 22 is mapped to:

$ sudo docker run -d -P --name test_sshd eg_sshd$ sudo docker port test_sshd 220.0.0.0:49154

And now you can ssh as root on the container's IP address (you can find it with docker inspect) or on port49154 of the Docker daemon's host IP address(ip address orifconfig can tell you that):

$ ssh root@192.168.1.2 -p 49154# The password is ``screencast``.$$

Finally, clean up after your test by stopping and removing thecontainer, and then removing the image.

$ sudo docker stop test_sshd$ sudo docker rm test_sshd$ sudo docker rmi eg_sshd

0 0