Docker配置WebSSH的实现

 更新时间:2023年03月08日 09:40:40   作者:看得见的等候  
本文主要介绍了Docker配置WebSSH的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

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

到此这篇关于Docker配置WebSSH的实现的文章就介绍到这了,更多相关Docker配置WebSSH内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 2023年windows DockerDeskTop最新款4.18.0 全程保姆级安装图文教程

    2023年windows DockerDeskTop最新款4.18.0 全程保姆级安装图文教程

    这篇文章主要介绍了2023年windows DockerDeskTop最新款4.18.0 全程保姆级安装图文教程,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-04-04
  • 关于为Windows Service 2019 使用 Docker的问题

    关于为Windows Service 2019 使用 Docker的问题

    最近收到领导通知,甲方需要将原来的服务器迁移到新的服务器,原来的服务器上安装了很多的服务,每次重启之后总是有很多的问题需要人工大量的进行干预,今天小编通过本文给大家介绍下Windows Service 2019 使用 Docker的问题,需要的朋友参考下吧
    2022-05-05
  • docker运行nginx不生效的解决办法

    docker运行nginx不生效的解决办法

    当docker运行nginx镜像时,设置端口映射,则只有该映射端口起作用,nginx配置的其他端口无效,接下来本文将给大家介绍docker运行nginx不生效的解决办法,文中有相关的代码示例供大家参考,需要的朋友可以参考下
    2024-01-01
  • docker 打包本地镜像,并到其他机器进行恢复操作

    docker 打包本地镜像,并到其他机器进行恢复操作

    这篇文章主要介绍了docker 打包本地镜像,并到其他机器进行恢复操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-11-11
  • 用Jenkins+Docker+Maven+Git实现持续集成(超详细)

    用Jenkins+Docker+Maven+Git实现持续集成(超详细)

    本文通过较大的篇幅详细介绍了Harbor这款企业级docker管理工具的使用,并通过案例演示了如何在jenkins中配置任务集成Harbor,从而实现镜像的构建推送与分发,需要的朋友可以参考下
    2024-04-04
  • docker 限制容器对CPU的使用

    docker 限制容器对CPU的使用

    本篇文章主要介绍了docker 限制容器对CPU的使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-08-08
  • docker-compose启动minio方式

    docker-compose启动minio方式

    文章介绍了创建文件夹、配置docker-compose.yml、开启防火墙以及验证服务的步骤,适用于新版和老版的RELEASE数据格式
    2025-01-01
  • Docker tomcat的设置内存大小配置方式

    Docker tomcat的设置内存大小配置方式

    这篇文章主要介绍了Docker tomcat的设置内存大小配置方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-03-03
  • docker 镜像加速CentOS7详细介绍

    docker 镜像加速CentOS7详细介绍

    这篇文章主要介绍了docker 镜像加速CentOS7详细介绍的相关资料,需要的朋友可以参考下
    2016-12-12
  • 安装Docker配置阿里云镜像加速(图文教程)

    安装Docker配置阿里云镜像加速(图文教程)

    dcker配置阿里云镜像加速,其目的是为了在提高docker镜像下载速度,本文主要介绍了安装Docker配置阿里云镜像加速,具有一定的参考价值,感兴趣的可以了解一下
    2022-04-04

最新评论