基於CentOS的SSHD服務的Docker鏡像

原文地址html

1.Dockerfile文件

FROM       registry.aliyuncs.com/acs-sample/centos:6
MAINTAINER xuqh "xqh_163@163.com"

RUN yum install -y openssh-server

RUN        ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN        ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key

RUN echo 'root:TopDocker' |chpasswd

RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config

EXPOSE 22
EXPOSE 80

CMD    ["/usr/sbin/sshd", "-D"]

2.建立鏡像而後查看

docker build -t aliyun/centos-sshd:6 .docker

[root@iZ23g3sxtunZ dockerfile]# docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
aliyun/centos-sshd                        6                   a8eea9913432        17 minutes ago      277.5 MB
registry.aliyuncs.com/acs-sample/centos   6                   63b04d6634cc        4 weeks ago         190.6 MB

3.啓動容器而後查看

docker run -d -p 10022:22 -p 10080:80 --name centos aliyun/centos-sshd:6centos

[root@iZ23g3sxtunZ dockerfile]# docker ps
CONTAINER ID        IMAGE                  COMMAND               CREATED             STATUS              PORTS                                          NAMES
e188fc592756        aliyun/centos-sshd:6   "/usr/sbin/sshd -D"   19 minutes ago      Up 19 minutes       0.0.0.0:10022->22/tcp, 0.0.0.0:10080->80/tcp   centos

注:能夠用netstat -lntp查看端口信息ssh

4.宿主機上登錄測試

ssh root@192.168.x.x -p 10022tcp

5.若是ssh提示IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY

rm -rf ~/.ssh/known_hosts測試

6.阿里雲容器Hub服務

Hubui

相關文章
相關標籤/搜索