目錄
- 1、基于DockerHub Centos鏡像
- 2、 Centos鏡像存在的一個自身問題:啟動后的容器內部無法使用systemctl命令
- 3、在基礎鏡像中安裝基礎服務
- 4、在基礎鏡像中配置WebSSH
- 5、后臺啟動并指定webssh服務的日志目錄
- 6、加入開機自啟
- 7、制作最終鏡像并在遷移后使用
- 8、頁面訪問
1、基于DockerHub Centos鏡像
docker pull centos:centos7
2、 Centos鏡像存在的一個自身問題:啟動后的容器內部無法使用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、在基礎鏡像中安裝基礎服務
(1)安裝sshd、httpd、firewalld服務
yum install -y openssh openssh-server openssh-client yum install httpd yum install firewalld firewall-config
(2) 啟動服務后并加入開機自啟
## 啟動 systemctl start sshd systemctl start httpd systemctl start firewalld ## 開機自啟 systemctl enable sshd systemctl enable httpd systemctl enable firewalld
(3)針對于httpd服務
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服務
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)設置默認初始密碼:passwd root
4、在基礎鏡像中配置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服務的日志目錄
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