启动虚拟机:vagrant up
连接虚拟机:vagrant ssh
关闭虚拟机:vagrant halt
连接虚拟机后关闭:shutdown -h now
查看容器日志:docker logs 容器id|容器名字
查看容器(已启动的):docker ps
查看容器(已启动、未启动但不包括已删除的):docker ps -a
重启容器:docket restart 容器id|容器名字
停止容器:docket stop 容器id|容器名字
启动容器:docket start 容器id|容器名字
设置容器跟随虚拟机启动而启动:
docker update 容器名字|容器id --restart=always
一、安装虚拟机:VirtualBox + vagrant
1、下载安装VirtualBox:
https://www.virtualbox.org/,注意:要开启cpu虚拟化(查看是否已开启:任务管理器->性能->CPU->右下角显示虚拟化是否已开启)
VirtualBox-7.1.6-167084-Win.exe
2、下载安装vagrant:
Vagrant官方镜像仓库(这里有许多镜像可直接使用如centos/7,后续会用到):https://app.vagrantup.com/boxes/search
Vagrant下载(百度搜vagrant官网也行):https://developer.hashicorp.com/vagrant/install?product_intent=vagrant#windows
vagrant_2.4.3_windows_amd64.msi
验证是否安装成功:cmd窗口输入命令 vagrant 后有命令提示即安装成功
3、初始化一个centos7系统(在指定文件夹下打开cmd窗口):
在非C盘的目录下打开,如D:\software\mirros
运行 Vagrant init centos/7
4、启动虚拟机:
vagrant up
(需要在Vagrantfile文件所在文件夹打开cmd执行此命令,我的在目录D:\software\mirros),系统root密码是vagrant
5、连接虚拟机:
vagrant ssh
6、设置虚拟机的固定ip地址
修改Vagrantfile文件的config.vm.network “private_network”, ip: "192.168.33.10"即可
ip修改规则:
(1)cmd窗口输入ipconfig找到“以太网适配器 以太网 2”有的叫以太网 ****也有的叫VirtualBox Host-Only Network
(2)如该ip为192.168.56.1那么上面的配置就应该配置为192.168.56.*如config.vm.network “private_network”, ip: “192.168.56.10”
(3)重启虚拟机:vagrant reload
重启后查看虚拟机ip(ifconfig/ip addr)之后和主机相互ping下看看是否通
二、Centos 修改yum华为源
1、备份原配置文件:
cd /etc/yum.repos.d
sudo mv CentOS-Base.repo CentOS-Base.repo.backup
2、创建CentOS-Base.repo文件并插入一下内容
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#[base]
name=CentOS-$releasever - Base - repo