Centos上Docker 使用dockerfile構建容器實現ssh

來源:互聯網
上載者:User

標籤:

這幾日在學習docker、遇到的問題數一年都數不完,網上大多數都是ubuntu的,百度或者Google的時候心好累。寫寫文檔來協助使用centos的docker愛好者們。 

docker基本操作這裡就不介紹了        編寫時間為:2015年12月25日17:41:41

如果你是準備開始學習,或者準備想用ssh實現串連容器這個功能時,請先自己折騰一下。不然達不到學習的目的哦

 

ssh -p 32772 [email protected]Read from socket failed: Connection reset by peer

看到這個報錯我估計大多數同學都很煩燥,恭喜你,找到了這篇文章

 

這裡我們直接上dockerfile 

#syw/centos:ssh##by:VFROM centos:centos6.6              MAINTAINER syw "[email protected]"       RUN yum -y install openssh-server;yum clean allRUN mkdir /var/run/sshdRUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_keyRUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_keyRUN /bin/echo ‘root:123456‘|chpasswdRUN /bin/sed -i ‘s/.*session.*required.*pam_loginuid.so.*/session optional pam_loginuid.so/g‘ /etc/pam.d/sshdRUN /bin/echo -e "LANG=\"en_US.UTF-8\"" > /etc/default/localEXPOSE 22CMD /usr/sbin/sshd -D

 使用build打包成image

docker build -t syw/centos6:ssh .

 這裡有時候會因為網路原因,或者一些其他原因導致打包的鏡像名稱為<none> ,如果出現這個錯誤就說明 打包的這個鏡像是錯誤的。(也可以注意build過程中的strin)

如果成功會提示打包成功的哦

Successfully built 3ea906c5b3a9

這裡我們建立一個容器來實驗一下

docker run -d -P --name endtest syw/centos6:ssh

 在查看容器狀態,如果沒有退出說明實驗成功docker ps

如果容器裡面沒有持續啟動並執行進程,容器就會退出。 這裡我們看到容器暴露的22連接埠對應宿主機的32769

所以我們來ssh驗證一下

退出不關閉容器的命令為 ctrl+p+q  這裡也順便記錄一下KVM 的為 ctrl+[

 

                                              有疑問可留言!

Centos上Docker 使用dockerfile構建容器實現ssh

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.