当前位置: 首页 > news >正文

ubuntu22.04的docker容器中安装ssh服务

ubuntu22.04的docker容器中安装ssh服务,以便外部可以连接到容器中操作。

root@node15:~# cat /etc/issue
Ubuntu 22.04.5 LTS \n \l

root@node15:~# docker ps|grep qwen
7d3c36c37d36   vllm/vllm-openai:v0.7.3                                "python3 -m vllm.ent…"   45 hours ago   Up 45 hours             0.0.0.0:8102->8000/tcp, :::8102->8000/tcp                                                                                                                                qwen2.5-vl-72b
root@node15:~# docker exec -it qwen2.5-vl-72b /bin/bash
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN
bash: netstat: command not found
root@7d3c36c37d36:/vllm-workspace# apt install net-tools
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 78 not upgraded.
Need to get 204 kB of archives.
After this operation, 819 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 net-tools amd64 1.60+git20181103.0eebece-1ubuntu5 [204 kB]
Fetched 204 kB in 1s (144 kB/s)     
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package net-tools.
(Reading database ... 29384 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20181103.0eebece-1ubuntu5_amd64.deb ...
Unpacking net-tools (1.60+git20181103.0eebece-1ubuntu5) ...
Setting up net-tools (1.60+git20181103.0eebece-1ubuntu5) ...
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN
tcp        0      0 127.0.0.11:44857        0.0.0.0:*               LISTEN      -                   
tcp        0      0 192.168.48.2:58107      0.0.0.0:*               LISTEN      310/python3         
tcp        0      0 192.168.48.2:59035      0.0.0.0:*               LISTEN      311/python3         
tcp        0      0 192.168.48.2:60607      0.0.0.0:*               LISTEN      309/python3         
tcp        0      0 192.168.48.2:53561      0.0.0.0:*               LISTEN      310/python3         
tcp        0      0 192.168.48.2:55133      0.0.0.0:*               LISTEN      309/python3         
tcp        0      0 192.168.48.2:54617      0.0.0.0:*               LISTEN      311/python3         
tcp        0      0 192.168.48.2:57269      0.0.0.0:*               LISTEN      311/python3         
tcp        0      0 192.168.48.2:56415      0.0.0.0:*               LISTEN      310/python3         
tcp        0      0 192.168.48.2:56765      0.0.0.0:*               LISTEN      311/python3         
tcp        0      0 192.168.48.2:49247      0.0.0.0:*               LISTEN      68/python3          
tcp        0      0 192.168.48.2:52421      0.0.0.0:*               LISTEN      68/python3          
tcp        0      0 192.168.48.2:45507      0.0.0.0:*               LISTEN      311/python3         
tcp        0      0 127.0.0.1:44069         0.0.0.0:*               LISTEN      68/python3          
tcp        0      0 192.168.48.2:46687      0.0.0.0:*               LISTEN      68/python3          
tcp        0      0 192.168.48.2:46935      0.0.0.0:*               LISTEN      68/python3          
tcp        0      0 192.168.48.2:46121      0.0.0.0:*               LISTEN      310/python3         
tcp        0      0 192.168.48.2:46513      0.0.0.0:*               LISTEN      309/python3         
tcp        0      0 192.168.48.2:48837      0.0.0.0:*               LISTEN      309/python3         
tcp        0      0 192.168.48.2:41667      0.0.0.0:*               LISTEN      310/python3         
tcp        0      0 192.168.48.2:41097      0.0.0.0:*               LISTEN      309/python3         
tcp        0      0 192.168.48.2:42797      0.0.0.0:*               LISTEN      310/python3         
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      1/python3           
tcp        0      0 192.168.48.2:37179      0.0.0.0:*               LISTEN      311/python3         
tcp        0      0 192.168.48.2:38189      0.0.0.0:*               LISTEN      68/python3          
tcp        0      0 192.168.48.2:40845      0.0.0.0:*               LISTEN      68/python3          
tcp        0      0 192.168.48.2:40249      0.0.0.0:*               LISTEN      68/python3          
tcp        0      0 192.168.48.2:34167      0.0.0.0:*               LISTEN      309/python3         
tcp        0      0 192.168.48.2:35607      0.0.0.0:*               LISTEN      310/python3         
tcp        0      0 192.168.48.2:36851      0.0.0.0:*               LISTEN      309/python3         
tcp        0      0 192.168.48.2:36699      0.0.0.0:*               LISTEN      311/python3         
tcp6       0      0 :::56307                :::*                    LISTEN      68/python3          
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN|grep 22
root@7d3c36c37d36:/vllm-workspace# apt install ssh      
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libwrap0 ncurses-term openssh-server openssh-sftp-server ssh-import-id
Suggested packages:
  molly-guard monkeysphere ssh-askpass ufw
The following NEW packages will be installed:
  libwrap0 ncurses-term openssh-server openssh-sftp-server ssh ssh-import-id


4;2m
c
# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

#HostbasedAuthentication no
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
KbdInteractiveAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
4;m"/etc/ssh/sshd_config" 122L, 3239B written                                                                                                                                        
4;m
0 upgraded, 6 newly installed, 0 to remove and 78 not upgraded.
Need to get 804 kB of archives.
After this operation, 6291 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 openssh-sftp-server amd64 1:8.9p1-3ubuntu0.11 [38.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 libwrap0 amd64 7.6.q-31build2 [47.9 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 openssh-server amd64 1:8.9p1-3ubuntu0.11 [435 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 ssh all 1:8.9p1-3ubuntu0.11 [4852 B]
Get:5 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 ncurses-term all 6.3-2ubuntu0.1 [267 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/main amd64 ssh-import-id all 5.11-0ubuntu1 [10.1 kB]
Fetched 804 kB in 6s (146 kB/s)       
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package openssh-sftp-server.
(Reading database ... 29433 files and directories currently installed.)
Preparing to unpack .../0-openssh-sftp-server_1%3a8.9p1-3ubuntu0.11_amd64.deb ...
Unpacking openssh-sftp-server (1:8.9p1-3ubuntu0.11) ...
Selecting previously unselected package libwrap0:amd64.
Preparing to unpack .../1-libwrap0_7.6.q-31build2_amd64.deb ...
Unpacking libwrap0:amd64 (7.6.q-31build2) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../2-openssh-server_1%3a8.9p1-3ubuntu0.11_amd64.deb ...
Unpacking openssh-server (1:8.9p1-3ubuntu0.11) ...
Selecting previously unselected package ssh.
Preparing to unpack .../3-ssh_1%3a8.9p1-3ubuntu0.11_all.deb ...
Unpacking ssh (1:8.9p1-3ubuntu0.11) ...
Selecting previously unselected package ncurses-term.
Preparing to unpack .../4-ncurses-term_6.3-2ubuntu0.1_all.deb ...
Unpacking ncurses-term (6.3-2ubuntu0.1) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../5-ssh-import-id_5.11-0ubuntu1_all.deb ...
Unpacking ssh-import-id (5.11-0ubuntu1) ...
Setting up openssh-sftp-server (1:8.9p1-3ubuntu0.11) ...
Setting up ssh-import-id (5.11-0ubuntu1) ...
Setting up libwrap0:amd64 (7.6.q-31build2) ...
Setting up ncurses-term (6.3-2ubuntu0.1) ...
Setting up openssh-server (1:8.9p1-3ubuntu0.11) ...

Creating config file /etc/ssh/sshd_config with new version
Creating SSH2 RSA key; this may take some time ...
3072 SHA256:5KlUbR+mj4rQYm1FD30BYwYRAqzWgwXONXGW610/Hj0 root@7d3c36c37d36 (RSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:kGZUG3xhPLQPF1ujDnW+MJdXx45kqoDTC9Vf26BvCD0 root@7d3c36c37d36 (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:OIcPYhmTREwAXKbdibbwDIZlxzLsHryXVgvu1o0lvT4 root@7d3c36c37d36 (ED25519)
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/systemd/system/ssh.service.
Setting up ssh (1:8.9p1-3ubuntu0.11) ...
Processing triggers for libc-bin (2.35-0ubuntu3.4) ...
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN|grep 22
root@7d3c36c37d36:/vllm-workspace# systemctl restart sshd
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN|grep 22
root@7d3c36c37d36:/vllm-workspace# vi /etc/ssh/
moduli                    ssh_config.d/             ssh_host_ecdsa_key.pub    ssh_host_ed25519_key.pub  ssh_host_rsa_key.pub      sshd_config               
ssh_config                ssh_host_ecdsa_key        ssh_host_ed25519_key      ssh_host_rsa_key          ssh_import_id             sshd_config.d/            
root@7d3c36c37d36:/vllm-workspace# vi /etc/ssh/
moduli                    ssh_config.d/             ssh_host_ecdsa_key.pub    ssh_host_ed25519_key.pub  ssh_host_rsa_key.pub      sshd_config               
ssh_config                ssh_host_ecdsa_key        ssh_host_ed25519_key      ssh_host_rsa_key          ssh_import_id             sshd_config.d/          

允许root登录 
root@7d3c36c37d36:/vllm-workspace# vi /etc/ssh/sshd_config


root@7d3c36c37d36:/vllm-workspace# passwd root
New password: 
Retype new password: 
passwd: password updated successfully

启动ssh服务:

exit
root@node15:/disk2/qwen-2.5-vl-72b# docker exec -it qwen2.5-vl-72b /bin/bash
root@7d3c36c37d36:/vllm-workspace# service ssh stop  
 * Stopping OpenBSD Secure Shell server sshd                                                                                                                                                              [ OK ] 
root@7d3c36c37d36:/vllm-workspace# service ssh start
 * Starting OpenBSD Secure Shell server sshd                                                                                                                                                              [ OK ] 
root@7d3c36c37d36:/vllm-workspace# service ssh status
 * sshd is running
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN|grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1290/sshd: /usr/sbi 
tcp6       0      0 :::22                   :::*                    LISTEN      1290/sshd: /usr/sbi 
root@7d3c36c37d36:/vllm-workspace# service ssh stop
 * Stopping OpenBSD Secure Shell server sshd                                                                                                                                                              [ OK ] 
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN|grep 22
root@7d3c36c37d36:/vllm-workspace# /usr/sbin/sshd -D &
[1] 1322
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN|grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1322/sshd: /usr/sbi 
tcp6       0      0 :::22                   :::*                    LISTEN      1322/sshd: /usr/sbi 
root@7d3c36c37d36:/vllm-workspace# service ssh stop
 * Stopping OpenBSD Secure Shell server sshd                                                                                                                                                              [ OK ] 
[1]+  Done                    /usr/sbin/sshd -D
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN|grep 22
root@7d3c36c37d36:/vllm-workspace# /usr/sbin/sshd -D &
[1] 1345
root@7d3c36c37d36:/vllm-workspace# 


root@7d3c36c37d36:/vllm-workspace# /etc/init.d/ssh start
 * Starting OpenBSD Secure Shell server sshd                                                                                                                                                              [ OK ] 
root@7d3c36c37d36:/vllm-workspace# netstat -tunlp|grep LISTEN|grep 22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1189/sshd: /usr/sbi 
tcp6       0      0 :::22                   :::*                    LISTEN      1189/sshd: /usr/sbi 
root@7d3c36c37d36:/vllm-workspace# 

保存容器:

root@node15:~# docker ps|grep llm
7d3c36c37d36   vllm/vllm-openai:v0.7.3                                "python3 -m vllm.ent…"   45 hours ago   Up 45 hours             0.0.0.0:8102->8000/tcp, :::8102->8000/tcp                                                                                                                                qwen2.5-vl-72b

root@node15:~# docker commit 7d3c36c37d36 vllm/vllm-openai:v0.7.3
sha256:68e6945f7f6bbbb14451a181461d45f6625044e3b776b42d9efaafcf57dd40bf
root@node15:~# docker images|grep llm
vllm/vllm-openai                                                                v0.7.3                         68e6945f7f6b   10 seconds ago   16.5GB
vllm/vllm-openai                                                                <none>                         a0b3e59739e9   3 days ago       16.4GB
vllm/vllm-openai                                                                v0.6.5                         56aa649484bf   2 months ago     10.1GB
 

重启docker,增加端口映射:

root@node15:~# cd /disk2/qwen-2.5-vl-72b
root@node15:/disk2/qwen-2.5-vl-72b# more docker-compose.yml 
services:
  # vllm
  vllm-openai:
    image: vllm/vllm-openai:v0.7.3
    container_name: qwen2.5-vl-72b
    restart: unless-stopped
    runtime: nvidia
    ports:
      - 8102:8000
      - 8122:22
    volumes:
      - /disk2/:/models
    command: >
      --model /models/qwen-2.5-vl-72b
      --tokenizer_mode="auto"
      --dtype=bfloat16
      --tensor_parallel_size=4
      --gpu-memory-utilization=0.9
      --max-model-len=16384
      --served-model-name=Qwen2.5-VL-72B-Instruct
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              capabilities: [gpu]
              device_ids: [ "0","1","2","3" ]
    ipc: host
networks:
        vllm:

启停容器

root@node15:/disk2/qwen-2.5-vl-72b#

docker compose -f docker-compose.yml down

docker compose -f docker-compose.yml up -d

相关文章:

  • 机器学习数学基础:32.斯皮尔曼等级相关
  • 机器学习数学基础:36.φ相关系数分析
  • iOS指纹归因详解
  • C++ Primer 额外的string操作
  • MySQL入门:高频操作命令大全
  • Java 实现快速排序算法:一条快速通道,分而治之
  • 超详细介绍map(multimap)的使用
  • JVM生产环境问题定位与解决实战(二):JConsole、VisualVM到MAT的高级应用
  • 【原创】Windows11安装WSL“无法解析服务器的名称或地址”问题解决方法
  • rust 前端npm依赖工具rsup升级日志
  • 独立开发者之Google Analytics使用教程
  • 文字语音相互转换
  • 玩机日记 11 解决fnOS识别不了虚拟核显的问题
  • 01-03基于vs2022的c语言笔记——软件安装,写程序前的准备,初识c语言
  • pyecharts介绍
  • 从基础到模块化:深度解析RAG技术演进如何重塑AI知识边界
  • 系统升级过程中如何实现数据的平滑迁移
  • MySQL 主从同步延迟:原因剖析与解决之道
  • 图片爬取案例
  • Spring Boot 项目启动命令大全:参数详解与高阶用法
  • 美国务卿会见叙利亚外长,沙特等国表示将支持叙利亚重建
  • 中国军网:带你揭开3所新调整组建军队院校的神秘面纱
  • 铁路端午假期运输火车票今日开售,12306提升应对超大规模并发访问需求能力
  • 上海高院与上海妇联签协议,建立反家暴常态化联动协作机制
  • 黑龙江省政府副秘书长许振宇,拟任正厅级领导
  • 杞支雅男评《1517》|放眼世界,立足德国