实在搞不定可以用https://labs.play-with-docker.com/
来玩玩就好了。
今天我打算练习docker,但还不影响MacOS的纯净性
计划使用虚拟机的方式进行练习,
结构如下,Mac -> vagrant -> VirtualBox Cent 7 -> Docker
这样做的目的是实验环境随时可一键删除,不影响使用的系统,
隔离了用户系统的影响,
不管是windows 还是 Mac 得到的演示结果是一致的
首先下载必要的软件
VirtualBox
https://www.virtualbox.org/wiki/Downloads
Vagrant
https://www.vagrantup.com/downloads.html
找到自己操作系统的版本
下载安装就不在这里详述了
打开终端工具执行命令 验证vagrant是否安装成功
AlbertMP:~ Albert$ vagrant
Usage: vagrant [options] <command> [<args>]
-v, --version Print the version and exit.
-h, --help Print this help.
Common commands:
box manages boxes: installation, removal, etc.
cloud manages everything related to Vagrant Cloud
destroy stops and deletes all traces of the vagrant machine
global-status outputs status Vagrant environments for this user
halt stops the vagrant machine
help shows the help for a subcommand
init initializes a new Vagrant environment by creating a Vagrantfile
login
package packages a running vagrant environment into a box
plugin manages plugins: install, uninstall, update, etc.
port displays information about guest port mappings
powershell connects to machine via powershell remoting
provision provisions the vagrant machine
push deploys code in this environment to a configured destination
rdp connects to machine via RDP
reload restarts vagrant machine, loads new Vagrantfile configuration
resume resume a suspended vagrant machine
snapshot manages snapshots: saving, restoring, etc.
ssh connects to machine via SSH
ssh-config outputs OpenSSH valid configuration to connect to the machine
status outputs status of the vagrant machine
suspend suspends the machine
up starts and provisions the vagrant environment
upload upload to machine via communicator
validate validates the Vagrantfile
version prints current and latest Vagrant version
winrm executes commands on a machine via WinRM
winrm-config outputs WinRM configuration to connect to the machine
For help on any individual command run `vagrant COMMAND -h`
Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.
下面开始用vagrant安装centOS7
# 创建一个目
mkdir -p ~/coding/docker/centos7
# 移动到当前目录
cd ~/coding/docker/centos7
# 查看当前目录
pwd
# 初始化一个centos/7
vagrant init centos/7
# 查看Vagrant 配置
more Vagrantfile
# 启动
vagrant up
# 登陆刚刚创建好了的 centos
vagrant ssh
安装docker
https://docs.docker.com/install/linux/docker-ce/centos/#prerequisites
1 hostname
2 ip addr
3 exit
4 ll
5 sudo yum update
6 exit
7 sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
8 sudo yum install -y yum-utils device-mapper-persistent-data lvm2
9 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
10 sudo yum install docker-ce docker-ce-cli containerd.io
15 sudo systemctl start docker
16 sudo docker run hello-world
17 history
至此Docker就安装完成了
把vagrant 用户添加到docker组里, 这样运行docker命令就不需要sudo了
13 sudo groupadd docker
15 sudo gpasswd -a vagrant docker
需要退出ssh 重新登录才能生效
网友评论