设为首页 收藏本站
查看: 1111|回复: 0

[经验分享] 搭建VirtualBox + Vagrant + CoreOS + Docker环境

[复制链接]

尚未签到

发表于 2016-1-10 13:50:08 | 显示全部楼层 |阅读模式
构成图
引用
Container | Container | ...
-----------------------
           Docker
-----------------------
           CoreOS
-----------------------
         Virtual Box
-----------------------
  Local Machine(Windows)

***CoreOS已经内置了docker,CoreOS也推出新的容器引擎Rocket(rkt)。
准备
・VirtualBox 4.3.20 https://www.virtualbox.org/wiki/Downloads
・Vagrant 1.7.2 http://www.vagrantup.com/downloads.html
・Git 1.8.3 http://git-scm.com/downloads
・Putty 0.64 http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
(1)下载配置文件coreos-vagrant
F:\>git clone https://github.com/coreos/coreos-vagrant.git

(2)修改配置文件
・config.rb.sample -> config.rb
・user-data.sample -> user-data
・config.rb
  $num_instances=1         #如果安装单个coreos就写1,如果是集群就写大于1的数字
  $update_channel='stable' #这个是版本,可以改为stable或者beta
・Vagrantfile
  # config.vm.box_version = ">= 308.0.1" 注释掉这行
(3)安装coreos
F:\>cd coreos-vagrant
F:\coreos-vagrant>vagrant up
Bringing machine 'core-01' up with 'virtualbox' provider...
==> core-01: Box 'coreos-stable' could not be found. Attempting to find and install...
core-01: Box Provider: virtualbox
core-01: Box Version: >= 0
==> core-01: Loading metadata for box 'http://stable.release.core-os.net/amd64-
usr/current/coreos_production_vagrant.json'
core-01: URL: http://stable.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json
==> core-01: Adding box 'coreos-stable' (v633.1.0) for provider: virtualbox
core-01: Downloading: http://stable.release.core-os.net/amd64-usr/633.1.0/coreos_production_vagrant.box
==> core-01: Box download is resuming from prior download progress
core-01: Progress: 20% (Rate: 62195/s, Estimated time remaining: 0:20:11)
.......第一次需要下载box文件
==> core-01: Importing base box 'coreos-stable'...
.......第二次就不用下载了
==> core-01: Setting the name of the VM: coreos-vagrant_core-01_1430979570265_83365
==> core-01: Clearing any previously set network interfaces...
==> core-01: Preparing network interfaces based on configuration...
core-01: Adapter 1: nat
core-01: Adapter 2: hostonly
==> core-01: Forwarding ports...
core-01: 22 => 2222 (adapter 1)
==> core-01: Running 'pre-boot' VM customizations...
==> core-01: Booting VM...
==> core-01: Waiting for machine to boot. This may take a few minutes...
core-01: SSH address: 127.0.0.1:2222
core-01: SSH username: core
core-01: SSH auth method: private key
core-01: Warning: Connection timeout. Retrying...
==> core-01: Machine booted and ready!
==> core-01: Setting hostname...
==> core-01: Configuring and enabling network interfaces...
==> core-01: Running provisioner: file...
==> core-01: Running provisioner: shell...
core-01: Running: inline script

(4)vagrant连接CoreOS
F:\coreos-vagrant>vagrant ssh
CoreOS stable (633.1.0)
core@core-01 ~ $ cat /etc/os-release
NAME=CoreOS
ID=coreos
VERSION=633.1.0
VERSION_ID=633.1.0
BUILD_ID=
PRETTY_NAME="CoreOS 633.1.0"
ANSI_COLOR="1;32"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://github.com/coreos/bugs/issues"
core@core-01 ~ $ docker -v
Docker version 1.5.0, build a8a31ef-dirty
core@core-01 ~ $ exit
logout
'cygwin': unknown terminal type.
Connection to 127.0.0.1 closed.
查看运行状态
F:\coreos-vagrant>vagrant global-status
id       name    provider   state   directory
------------------------------------------------------------------------
52bbbd1  core-01 virtualbox running F:/coreos-vagrant
关闭容器
F:\coreos-vagrant>vagrant halt
==> core-01: Attempting graceful shutdown of VM...

(5)Putty连接CoreOS
Private key: C:\Documents and Settings\RenSanNing\.vagrant.d\insecure_private_key
・打开PuTTYgen,通过菜单Conversions > Import key来读入上边的insecure_private_key
・保存密钥为.ppk文件Save private key
・打开PuTTY
【Session】
Host Name: core@127.0.0.1
Port: 2222
【Connection / SSH / Auth】
Private key file for authentication:选择上边的.ppk文件
DSC0000.png
****XP下Vagrant不能添加box:参考这里
****启动卡在“Booting VM...”:修改config.rb文件“$vm_gui = true”以GUI形式启动。
(6)CentOS 6中安装Docker
# rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum update -y
# yum -y install docker-io
# service docker start
# chkconfig docker on

(7)Docker基础
■镜像Image
公共registry:https://registry.hub.docker.com/
查找镜像
# docker search centos | more
查看镜像详细信息
# docker inspect centos:latest
下载镜像
# docker pull centos:latest
# docker pull busybox
# docker pull docker.cn/docker/java
镜像列表
# docker images
删除镜像
# docker rmi centos:latest
■容器Container
从镜像上创建一个容器Container
# docker run centos /bin/echo ok
# docker run -i -t centos /bin/bash
容器列表
# docker ps -a
与运行中的容器交互
# docker start 330ec265ad9d
# docker attach 330ec265ad9d
# docker stop 330ec265ad9d
查看容器日志
# docker logs 330ec265ad9d
删除容器
# docker rm 330ec265ad9d
■Container - Image
安装Apache
# docker run -i -t -h centos centos:centos6 /bin/bash
bash-4.1# yum -y install httpd
bash-4.1# exit
提交变更
# docker ps -a
# docker commit abb0ba529ee9 cent6_apache
# docker ps -a
运行Apache
# docker run -p 8080:80 -d cent6_apache /usr/sbin/apachectl -DFOREGROUND
■创建镜像Dockerfile
语法: INSTRUCTTION argument
指令约定为全部大写
必须以FROM命令开始: FROM <image name>
# vi Dockerfile
  FROM centos
  MAINTAINER rensanning <rensanning@gmail.com>
  RUN echo "now building..."
  CMD ["echo", "now running..."]
# docker build -t rensanning/test .
# docker images
# docker run rensanning/test
# vi Dockerfile
  FROM centos
  MAINTAINER rensanning <rensanning@gmail.com>
  RUN yum install -y httpd
  ADD ./index.html /var/www/html/
  EXPOSE 80
  CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
# vi index.html
  <html>hello from Docker!</html>
# docker build -t rensanning/httpd .
# docker images
# docker run -p 8080:80 -d rensanning/httpd
■发布到Registry
# docker login
# docker push rensanning/httpd
DSC0001.png
DSC0002.png
更多可以参考:Docker Cheat Sheet

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-162570-1-1.html 上篇帖子: virtualbox add box error 下篇帖子: Build Your Own Dev Server with VirtualBox
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表