获取centos7镜像
首先先搞一个centos7的镜像
先搜索找到下载一个centos [root@scyun-node-1 docker]# docker search centos7 NAME DESCRIPTION STARS OFFICIAL AUTOMATED ansible/centos7-ansible Ansible on Centos7 134 [OK] rpmbuild/centos7 CentOS 7 RPM package building environment 16 flyceek/centos7-jdk centos7-jdk 5 [OK] paigeeworld/centos7 Centos7 with apache, iperf3, nmap, ssh 5
下载centos7镜像 [root@scyun-node-1 docker]# docker pull ansible/centos7-ansible 或者导入一个centos7镜像 [root@scyun-node-1 docker]# docker load<centos7-ansible.tar
启动centos7镜像
[root@scyun-node-1 docker]# docker run -itd -p 60022:22 --name=centos7-1 --privileged centos7-ansible:latest 6726ac4ac654e26cc4dba3306242e425cd235fef4397d2c27e0a80d767e2f4d8 ##查看centos容器IP [root@scyun-node-1 docker]# docker inspect centos7-1|grep -aiE "ipaddr" |tail -1
ssh远程连接22端口试下
连接不上可能22端口没开 [root@scyun-node-1 docker]# ssh -l root 172.17.0.3 ssh: connect to host 172.17.0.3 port 22: Connection refused
进入centos容器内部看下ssh服务有没有启动
[root@scyun-node-1 docker]# docker exec -it 6726ac4ac654 /bin/bash [root@6726ac4ac654 ansible]# cd [root@6726ac4ac654 ~]# ls anaconda-ks.cfg 安装一个net-tools工具 [root@6726ac4ac654 ~]# yum install net-tools -y [root@6726ac4ac654 ~]# netstat -nltp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name ssh服务有没安装,安装ssh服务端 [root@6726ac4ac654 ~]# yum install openssh-server -y [root@6726ac4ac654 ~]# ssh-keygen -A ssh-keygen: generating new host keys: RSA1 RSA DSA ECDSA ED25519 [root@6726ac4ac654 ~]# ls /etc/ssh/ moduli ssh_host_dsa_key ssh_host_ecdsa_key ssh_host_ed25519_key ssh_host_key ssh_host_rsa_key sshd_config ssh_config ssh_host_dsa_key.pub ssh_host_ecdsa_key.pub ssh_host_ed25519_key.pub ssh_host_key.pub ssh_host_rsa_key.pub ##启动ssh服务 [root@6726ac4ac654 ~]# /usr/sbin/sshd [root@6726ac4ac654 ~]# netstat -nltp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 116/sshd tcp6 0 0 :::22 :::* LISTEN 116/sshd [root@6726ac4ac654 ~]# ps -ef |grep ssh root 116 0 0 14:31 ? 00:00:00 /usr/sbin/sshd root 121 14 0 14:35 pts/1 00:00:00 grep --color=auto ssh ##修改root密码 [root@6726ac4ac654 ~]# echo 1 |passwd --stdin root Changing password for user root. passwd: all authentication tokens updated successfully.
远程连接即可成功
Connecting to 192.168.93.101:60022... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. WARNING! The remote SSH server rejected X11 forwarding request. Last login: Sun May 9 14:51:08 2021 from gateway [root@6726ac4ac654 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.3 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet) RX packets 217 bytes 23276 (22.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 143 bytes 20900 (20.4 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
使用现在基础制作一个centos7镜像,下次直接启动镜像后直接可以连接上。https://www.wscyun.com/2021/05/1437.html
继续阅读
评论