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

2、 Centos鏡像存在的一個(gè)自身問(wèn)題:?jiǎn)?dòng)后的容器內(nèi)部無(wú)法使用systemctl命令
Failed to get D-Bus connection: Operation not permitted
## docker run -dit eeb6ee3f44bd /bin/bash ## 切勿忘記宿主機(jī)防火墻開(kāi)放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) 啟動(dòng)服務(wù)后并加入開(kāi)機(jī)自啟
## 啟動(dòng) systemctl start sshd systemctl start httpd systemctl start firewalld ## 開(kāi)機(jī)自啟 systemctl enable sshd systemctl enable httpd systemctl enable firewalld
(3)針對(duì)于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)針對(duì)于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)開(kāi)放端口
firewall-cmd --permanent --add-port=8888/tcp firewall-cmd --reload firewall-cmd --list-all
(6)設(shè)置默認(rèn)初始密碼:passwd root
4、在基礎(chǔ)鏡像中配置WebSSH
(1)安裝python3
yum install python3-pip
(2)安裝WebSSH
##### pip3 install webssh ##### pip3 報(bào)錯(cuò):Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-xxx/xxx/ ##### https://www.modb.pro/db/81767
針對(duì)以上報(bào)錯(cuò)的解決方案:
### 升級(jí)setuptools pip3 install --upgrade setuptools -i https://mirrors.aliyun.com/pypi/simple/ ### 升級(jí)pip工具:https://www.cnblogs.com/rychh/p/16206842.html pip3 --default-timeout=1000 install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/
額外針對(duì)于以下告警的處理可選擇性處理:
### 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
進(jìn)行安裝:
pip3 --default-timeout=1000 install webssh -i https://mirrors.aliyun.com/pypi/simple/
5、后臺(tái)啟動(dòng)并指定webssh服務(wù)的日志目錄
wssh --log-file-prefix=/data/webssh/wssh.log --timeout=500 --fbidhttp=false &
6、加入開(kāi)機(jī)自啟
vi /etc/rc.local wssh --log-file-prefix=/data/webssh/wssh.log --timeout=500 --fbidhttp=false & chmod 777 /etc/rc.local
7、制作最終鏡像并在遷移后使用
1、打包正在運(yùn)行的容器為 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、頁(yè)面訪問(wèn)
訪問(wèn)方式(1)如圖:

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

