linux cpu占用率如何看
306
2022-10-18
Docker 安装Centos7
背景:我需要三台Centos7来部署分布式系统,但是只有一台Centos7,故想用Docker虚拟三台出来
1、下载Centos7镜像,通过docker search centos7查看镜像列表,用第一个。
[root@free-share local]# docker pull docker.io/ansible/centos7-ansibleUsing default tag: latestTrying to pull repository docker.io/ansible/centos7-ansible ... latest: Pulling from docker.io/ansible/centos7-ansible45a2e645736c: Pull complete 1c3acf573616: Pull complete edcb61e55ccc: Pull complete cbae31bad30a: Pull complete aacbdb1e2a62: Pull complete fdeea4fb835c: Pull complete Digest: sha256:39eff7d56b96530d014083cd343f7314c23acbd1ecf37eb75a71a2f6584d0b02Status: Downloaded newer image for docker.io/ansible/centos7-ansible:latest[root@free-share local]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/ansible/centos7-ansible latest 688353a31fde 5 years ago 447 MB
2、使用镜像创建容器
[root@free-share local]# docker run -itd -p 6022:22 --name=vm01 -v /bodata:/bodata -h vm01 --privileged=true 688353a31fde1a055acb4e761a61775667a3193c811b5327ef0fc2aeb77e33d1fb325474fe32[root@free-share local]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES7ec547fc37e5 688353a31fde "/bin/bash" 31 seconds ago Up 27 seconds 0.0.0.0:6022->22/tcp vm01
-i:以交互模式运行容器,通常与 -t 同时使用;
-t:为容器重新分配一个伪输入终端,通常与 -i 同时使用;
-d:后台运行容器,并返回容器ID;
-p:指定端口映射,格式为:主机(宿主)端口:容器端口
--name:为容器指定一个名称;
-h:为容器指定hostname
-v:将宿主机的目录挂载在容器中,格式为:主机(宿主)目录:容器目录,且不存在时会自行创建
3、此时使用ssh工具连ip:6022是不通的,要进入容器安装一些基础工具(sshd等网络工具)后才可以用ssh连接。
[root@free-share bodata]# docker exec -it 7ec547fc37e5 /bin/bash[root@vm01 ~]# yum install -y openssh-server[root@vm01 ~]# yum install -y net-tools[root@vm01 ~]# ssh-keygen -A ##为ssh生成必要的秘钥等[root@vm01 ~]# /usr/sbin/sshd ##启动ssh后台服务[root@vm01 ~]# echo 1|passwd --stdin root ##修改容器root用户密码为1,也可以用passwd root来修改
4、用xshell连接ip:6022,连接成功。
Connecting to 192.168.2.54:6022...Connection established.To escape to local shell, press 'Ctrl+Alt+]'.WARNING! The remote SSH server rejected X11 forwarding request.[root@vm01 ~]#
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~