redrose2100/openeuler-ssh的镜像仓库见 redrose2100/openeuler-ssh ,它为在openEuler镜像额基础上安装好sshd服务的镜像,并且设置了用户名root的密码为osImagePassword123,通过拉取此镜像即可直接启动可以ssh的容器。镜像的tag值与openEuler的镜像的tag值保持一致
(1)创建一个网络,如下创建一个名为staticnet的网络,网段为172.18.0.0/16
docker network create --subnet=172.18.0.0/16 staticnet
(2)查看网络如下
[root@centos7-1 ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
0eb4f2b7af54 bridge bridge local
be204ec4735f host host local
1df66d2f7b49 none null local
d6f5c693f28d staticnet bridge local
[root@centos7-1 ~]#
(3)启动容器,指定网络同时设置容器的ip地址
docker run -d --name=vm1 --privileged --net staticnet --ip 172.18.0.100 redrose2100/openeuler-ssh:22.03-lts /usr/sbin/sshd -D
(4)查看容器,如下,创建成功
[root@centos7-1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
60fbd371e02c redrose2100/openeuler-ssh:22.03-lts "/usr/sbin/sshd -D" 5 seconds ago Up 4 seconds vm1
[root@centos7-1 ~]#
(5)如下,通过ssh命令即可登录到容器,而且容器的ip地址配置也已经生效了
[root@centos7-1 ~]# ssh -o "StrictHostKeyChecking=no" root@172.18.0.100
root@172.18.0.100's password:
Last failed login: Tue Dec 13 09:21:32 UTC 2022 from 172.18.0.1 on ssh:notty
There was 1 failed login attempt since the last successful login.
Welcome to 3.10.0-1160.el7.x86_64
System information as of time: Tue Dec 13 09:21:56 AM UTC 2022
System load: 0.03
Processes: 8
Memory used: 19.6%
Swap used: .2%
Usage On: 31%
Users online: 0
[root@60fbd371e02c ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.100 netmask 255.255.0.0 broadcast 172.18.255.255
ether 02:42:ac:12:00:64 txqueuelen 0 (Ethernet)
RX packets 62 bytes 9502 (9.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 41 bytes 8108 (7.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@60fbd371e02c ~]#