【利用K8S技術棧打造我的私有云系列文章目錄】docker
注: 本文首發於 My 公衆號 CodeSheep ,可 長按 或 掃描 下面的 當心心 來訂閱 ↓ ↓ ↓
任何一家雲主機廠商提供給用戶的主機功能其實講白了就是一個操做系統基礎鏡像的運行實例。所以本篇博文將講解如何在本地構建一個帶ssh組件的centos底包鏡像並上傳到docker hub上供下載使用。編程
註冊網址:https://hub.docker.com/
vim
命令行中輸入:docker login
c#
docker pull centos
centos
docker run -it centos:latest /bin/bash
bash
yum -y install openssh-server yum -y install openssh-clients
啓動sshd服務命令: /usr/sbin/sshd -D
報以下錯誤:服務器
Could not load host key: /etc/ssh/ssh_host_rsa_key Could not load host key: /etc/ssh/ssh_host_ecdsa_key Could not load host key: /etc/ssh/ssh_host_ed25519_key
咱們來解決以上錯誤:框架
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
此時再次來啓動sshd服務應該無錯誤了ssh
執行命令:vim /etc/ssh/sshd_config
將配置文件中本來UsePAM yes
換成UsePAM no
微服務
執行命令:passwd root
輸入兩次密碼便可
docker commit bf5b84f8e2d8 docker.io/hansonwang/centos7.4_ssh
(1)注意此處的bf5b84f8e2d8即爲剛纔運行的容器的id,可用docker ps -a查看
(2)注意此處的commit格式,必須爲docker.io/<你的dockerhub用戶名>/centos7.4_ssh
docker push docker.io/hansonwang/centos7.4_ssh:latest
一樣須要注意此處的push格式,必須爲docker.io/<你的dockerhub用戶名/完整的鏡像名
以下圖所示:
同時咱們去docker hub上也能看到咱們剛push的鏡像:
爲了驗證鏡像確實被推到遠端,咱們將本地剛打包好的鏡像刪除,而後從遠端pull下來運行看看
docker pull hansonwang/centos7.4_ssh
能夠成功pull下來:
咱們來測試一下該鏡像裏是否包含有ssh組件:運行其並用ssh鏈接到容器中:
運行容器:docker run -d -p 2222:22 docker.io/hansonwang/centos7.4_ssh:latest /usr/sbin/sshd -D
ssh接入:ssh root@localhost -p 2222
此時會讓你輸入密碼,而後成功登入容器之中:
做者更多的SpringBt實踐文章在此:
若是有興趣,也能夠抽點時間看看做者一些關於容器化、微服務化方面的文章: