在 mac os x 上安装红帽容器开发工具包-亚博电竞手机版
容器技术很棒,它将会改变我们开发好传递软件的方式。当然也有一个批评此技术的人认为它并不安全和足够安全的在产品环境运行。
随着 red hat enterprise linux 7.1 和 red hat atomic 的登陆,企业和组织机构可以不用牺牲安全性和性能,也能拥抱这一新技术趋势。
什么 red hat cdk?
cdk 是 container development kit(容器开发包)的缩写,它能让开发者在他们的桌面系统上使用 red hat atomic,不管他们所使用的是 microsoft windows®,mac os x® 或者其他 linux 的发行版。同boot2docker类似,cdk利用虚拟机来启动一个小的主机,它能运行基于 red hat enterprise linux 的容器。
前置条件
- red hat 订阅 – 要安装 red hat cdk 你就得拥有一个激活了的 red hat enterprise linux 订阅, 如果没有,可以在 这里 进行申请和查看。
- 虚拟环境 – virtualbox (mac/windows) 或者 virt-manager (linux)
- vagrant – 用来创建和管理虚拟环境。
从 red hat 消费者门户 下载下面这些东西。
- red hat 容器工具(container tools)
- 面向 virtualbox 的 red hat atomic vagrant 盒子 或者 面向libvirt 的 red hat atomic vagrant 盒子。
安装 red hat 容器开发包
注意:在这之前你需要安装好虚拟化环境以及 vagrant
解压你下载的 cdk.zip 文件到主目录. 这样会创建 ~/cdk (/users/username/cdk)
$ unzip -d $home ~/downloads/cdk-1.0-0.zip
安装使用 red hat vagrant 所需要的 vagrant 插件. 第一个插件会花几分钟时间,vagrant 可能会需要安装一些额外的gem文件。
$ cd ~/cdk/plugins $ vagrant plugin install vagrant-registration-0.0.8.gem $ vagrant plugin install vagrant-atomic-0.0.3.gem
验证插件是否已经安装好了:
$ vagrant plugin list vagrant-atomic (0.0.3) - version constraint: 0.0.3 vagrant-registration (0.0.8) - version constraint: 0.0.8
将 rhel atomic 盒子添加到 vagrant:
$ vagrant box add --name rhel-atomic-7 ~/downloads/rhel-atomic-virtualbox-7.1-0.x86_64.box
启动 atomic 主机
为 docker 文件创建一个工作目录
$ mkdir ~/containers && cd ~/containers
为容器创建一个工作目录,并初始化 vagrant
$ mkdir containers && cd containers $ vagrant init -m a `vagrantfile` has been placed in this directory. you are now ready to `vagrant up` your first virtual environment! please read the comments in the vagrantfile as well as documentation on `vagrantup.com` for more information on using vagrant.
这一步会创建一个简单的 vagrant 文件。打开它并像下面这样修改配置:
vagrant.configure(2) do |config| config.vm.box = "rhel-atomic-7" config.vm.hostname = "rhel-atomic-7-docker-host" config.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"] vb.memory = 4096 end config.vm.provision "shell", inline: <<-shell sudo systemctl stop docker > /dev/null 2>&1 sudo groupadd docker > /dev/null 2>&1 sudo usermod -a -g docker vagrant sudo systemctl enable docker && sudo systemctl start docker sudo chown root:docker /var/run/docker.sock sudo systemctl enable docker && sudo systemctl start docker shell end
我们现在已经做好了启动容器的准备。在机器的创建过程中,你将会看到是否想要注册系统的提示。回答 “y” 就会要你输入rhn (red hat network) 账户的用户名和密码.
$ vagrant up bringing machine 'default' up with 'virtualbox' provider... ==> default: importing base box 'rhel-atomic-7'... ==> default: matching mac address for nat networking... ==> default: setting the name of the vm: containers_default_1432213616739_95846 ==> default: clearing any previously set network interfaces... ==> default: preparing network interfaces based on configuration... default: adapter 1: nat ==> default: forwarding ports... default: 22 => 2222 (adapter 1) ==> default: running 'pre-boot' vm customizations... ==> default: booting vm... ==> default: waiting for machine to boot. this may take a few minutes... default: ssh address: 127.0.0.1:2222 default: ssh username: vagrant default: ssh auth method: private key default: warning: connection timeout. retrying... default: default: vagrant insecure key detected. vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: inserting generated public key within guest... default: removing insecure key from the guest if its present... default: key inserted! disconnecting and reconnecting using new ssh key... ==> default: machine booted and ready! ==> default: checking for guest additions in vm... default: no guest additions were detected on the base box for this vm! guest default: additions are required for forwarded ports, shared folders, host only default: networking, and more. if ssh fails on this machine, please install default: the guest additions and repackage the box to continue. default: default: this is not an error message; everything may continue to work properly, default: in which case you may ignore this message. ==> default: setting hostname... ==> default: registering box with vagrant-registration... default: would you like to register the system now (default: yes)? [y|n] y default: subscriber username:default: subscriber password: ==> default: rsyncing folder: /users/tqvarnst/containers/ => /home/vagrant/sync ==> default: running provisioner: shell... default: running: inline script
测试你的安装
$ vagrant ssh [vagrant@rhel-atomic-7-docker-host ~]$ docker ps container id image command created status ports names [vagrant@rhel-atomic-7-docker-host ~]$ docker run -it rhel7.1 bash unable to find image 'rhel7.1:latest' locally pulling repository registry.access.redhat.com/rhel7.1 10acc31def5d: download complete status: downloaded newer image for registry.access.redhat.com/rhel7.1:latest [root@ead3774c2b84 /]# cat /etc/redhat-release red hat enterprise linux server release 7.1 (maipo) [root@ead3774c2b84 /]#
按下 ctrl-p ctrl-q 可以离开你的容器
[vagrant@rhel-atomic-7-docker-host ~]$ docker ps container id image command created status ports names ead3774c2b84 registry.access.redhat.com/rhel7.1:7.1-4 "bash" about a minute ago up about a minute focused_rosalind
如下命令可以停掉或者删除容器
[vagrant@rhel-atomic-7-docker-host ~]$ docker stop $(docker ps -q) ead3774c2b84 [vagrant@rhel-atomic-7-docker-host ~]$ docker rm $(docker ps -aq) ead3774c2b84
总结
通过这个指南,你就可以有一个可以来使用基于 red hat enterprise linux 7.1 的容器的工作环境,不管你使用的是 mac os x®,microsoft windows® 还是其它的linux发行版。
鸣谢
特别要感谢 pete muir 在vagrant设置上给我带来的支持和帮助。