Docker配置WebSSH的實現(xiàn)
1、基于DockerHub Centos鏡像
docker pull centos:centos7

2、 Centos鏡像存在的一個自身問題:啟動后的容器內(nèi)部無法使用systemctl命令
Failed to get D-Bus connection: Operation not permitted
## docker run -dit eeb6ee3f44bd /bin/bash ## 切勿忘記宿主機防火墻開放8889 2200端口 docker run -dit -p 8889:8888 -p 2200:22 --restart=always --privileged --name t2 centos:centos7 init
3、在基礎(chǔ)鏡像中安裝基礎(chǔ)服務(wù)
(1)安裝sshd、httpd、firewalld服務(wù)
yum install -y openssh openssh-server openssh-client yum install httpd yum install firewalld firewall-config
(2) 啟動服務(wù)后并加入開機自啟
## 啟動 systemctl start sshd systemctl start httpd systemctl start firewalld ## 開機自啟 systemctl enable sshd systemctl enable httpd systemctl enable firewalld
(3)針對于httpd服務(wù)
localhost.localdomain httpd[1953]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
vi /etc/httpd/conf/httpd.conf 加入一句:ServerName localhost:80 systemctl restart httpd
(4)針對于firewalld服務(wù)
WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now
vi /etc/firewalld/firewalld.conf AllowZoneDrifting=yes ====》》AllowZoneDrifting=no systemctl restart firewalld
(5)開放端口
firewall-cmd --permanent --add-port=8888/tcp firewall-cmd --reload firewall-cmd --list-all
(6)設(shè)置默認初始密碼:passwd root
4、在基礎(chǔ)鏡像中配置WebSSH
(1)安裝python3
yum install python3-pip
(2)安裝WebSSH
##### pip3 install webssh ##### pip3 報錯:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-xxx/xxx/ ##### https://www.modb.pro/db/81767
針對以上報錯的解決方案:
### 升級setuptools pip3 install --upgrade setuptools -i https://mirrors.aliyun.com/pypi/simple/ ### 升級pip工具:https://www.cnblogs.com/rychh/p/16206842.html pip3 --default-timeout=1000 install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/
額外針對于以下告警的處理可選擇性處理:
### WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
### https://blog.csdn.net/m0_58782029/article/details/129049587
進行安裝:
pip3 --default-timeout=1000 install webssh -i https://mirrors.aliyun.com/pypi/simple/
5、后臺啟動并指定webssh服務(wù)的日志目錄
wssh --log-file-prefix=/data/webssh/wssh.log --timeout=500 --fbidhttp=false &
6、加入開機自啟
vi /etc/rc.local wssh --log-file-prefix=/data/webssh/wssh.log --timeout=500 --fbidhttp=false & chmod 777 /etc/rc.local
7、制作最終鏡像并在遷移后使用
1、打包正在運行的容器為 image docker commit eeb6ee3f44bd webssh:dev 2、保存image到文件 docker save -o webssh_dev.tar webssh:dev 3、使用已保存的image文件 docker load --input webssh_dev.tar
8、頁面訪問
訪問方式(1)如圖:

訪問方式(2)
## password需要進行base64加密 http://ip:8889?hostname=ip&username=root&password=cm9vdA==&port=2200
備注:
## 查看容器啟動日志
[vagrant@localhost images]$ sudo docker inspect --format '{{.LogPath}}' 21431ff039e7
/data/docker/containers/21431ff039e768753702d64cb01b1a75bb250c2c587b0f3396dd30b548a62850/21431ff039e768753702d64cb01b1a75bb250c2c587b0f3396dd30b548a62850-json.log到此這篇關(guān)于Docker配置WebSSH的實現(xiàn)的文章就介紹到這了,更多相關(guān)Docker配置WebSSH內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
2023年windows?DockerDeskTop最新款4.18.0?全程保姆級安裝圖文教程
這篇文章主要介紹了2023年windows?DockerDeskTop最新款4.18.0?全程保姆級安裝圖文教程,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04
關(guān)于為Windows?Service?2019?使用?Docker的問題
最近收到領(lǐng)導(dǎo)通知,甲方需要將原來的服務(wù)器遷移到新的服務(wù)器,原來的服務(wù)器上安裝了很多的服務(wù),每次重啟之后總是有很多的問題需要人工大量的進行干預(yù),今天小編通過本文給大家介紹下Windows?Service?2019?使用?Docker的問題,需要的朋友參考下吧2022-05-05
docker 打包本地鏡像,并到其他機器進行恢復(fù)操作
這篇文章主要介紹了docker 打包本地鏡像,并到其他機器進行恢復(fù)操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
用Jenkins+Docker+Maven+Git實現(xiàn)持續(xù)集成(超詳細)
本文通過較大的篇幅詳細介紹了Harbor這款企業(yè)級docker管理工具的使用,并通過案例演示了如何在jenkins中配置任務(wù)集成Harbor,從而實現(xiàn)鏡像的構(gòu)建推送與分發(fā),需要的朋友可以參考下2024-04-04
Docker tomcat的設(shè)置內(nèi)存大小配置方式
這篇文章主要介紹了Docker tomcat的設(shè)置內(nèi)存大小配置方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03

