docker新建centos鏡像並配置遠程訪問


1.# docker search centos 查找官方鏡像

 

 

2.# docker pull centos 下載鏡像(默認版本是latest)

3.# docker run -idt centos /bin/bash 啟動鏡像

4.# docker ps | grep centos 查看鏡像id

 

5.# docker exec -it  0400b38b215a /bin/bash 進入容器

6.安裝centos基礎環境

  1)# yum -y install net-tools.x86_64 安裝網絡環境,完成后使用ifconfig查看ip等信息

  2)# yum -y install openssh-server 安裝sshd,若出現:

    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 ""

  3)# vim /etc/ssh/sshd_config 編輯sshd_config配置文件 ,設置UsePAM為no

  4)# passwd 修改root默認密碼;若提示沒有這個命令,通過# yum -y install passwd安裝

  5)# exit 命令退出到host主機

7.# 打包新鏡像:docker commit -m "提交信息" 鏡像id 新鏡像名稱

8.# 啟動新鏡像:docker run -itd -p 50001:22 新鏡像名稱 /user/sbin/sshd -D

9:遠程連接:ssh root@localhost -p 50001

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM