Docker与OpenStack集成实战

1、计算节点安装Docker

root@compute2: ~# apt install docker.io -y

root@compute2:~# sh -c "echo deb https://get.docker.io/ubuntu docker main >> /etc/apt/sources.list.d/docker.list"

root@compute2:~# apt-get update

root@compute2:~# apt-get install lxc-docker

root@compute2: ~# apt install docker.io -y

查看当前版本

root@compute2:/var/lib/docker# docker --version

Docker version 1.12.0, build 8eab29e

root@compute2:~# docker -v

Docker version 1.12.0, build 8eab29e

root@compute2:~# dpkg -l | grep docker

rc  docker.io                                  1.11.2-0ubuntu5~16.04                                       amd64        Linux container runtime

ii  lxc-docker                                 1.9.1                                                       amd64        Linux container runtime

ii  lxc-docker-1.9.1                           1.9.1                                                       amd64        Linux container runtime

查找镜像

root@compute2:~# docker search ubuntu

dorapro/ubuntu                    ubuntu image                                    0                    [OK]

konstruktoid/ubuntu               Ubuntu base image                               0                    [OK]

uvatbc/ubuntu                     Ubuntu images with unprivileged user            0                    [OK]

2、下载Ubuntu镜像

root@compute2: ~#  docker pull ubuntu

Using default tag: latest

latest: Pulling from library/ubuntu

2f0243478e1f: Pull complete

d8909ae88469: Pull complete

820f09abed29: Pull complete

01193a8f3d88: Pull complete

Digest: sha256:8e2324f2288c26e1393b63e680ee7844202391414dbd48497e9a4fd997cd3cbf

Status: Downloaded newer image for ubuntu:latest

root@compute2:~# docker images -a

REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE

ubuntu                     latest              bd3d4369aebc        12 days ago         126.6 MB

ubuntu-1604-sleepy_kilby   latest              94c88d9d0023        3 weeks ago         126.4 MB

ubuntu                     <none>              f8d79ba03c00        3 weeks ago         126.4 MB

cmer81/centos7-openstack   latest              3317e0f4e0fb        7 months ago        322.2 MB

3、启动并登录Docker容器

root@compute2:~# docker run -i -t ubuntu

root@c0a0294d98d2:/# cat /etc/issue

Ubuntu 16.04.1 LTS \n \l

给容器设置root密码

[root@dfbc7c3db16b /]# passwd root

Changing password for user root.

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

设置允许root密码登录

[root@dfbc7c3db16b /]# vi /etc/ssh/sshd_config

PermitRootLogin yes

PasswordAuthentication yes

SSH到容器中

root@compute2:~# ssh 172.17.0.3

root@172.17.0.3's password:

[root@dfbc7c3db16b ~]#

[root@dfbc7c3db16b ~]#

[root@dfbc7c3db16b ~]#

[root@dfbc7c3db16b ~]# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 172.17.0.3  netmask 255.255.0.0  broadcast 0.0.0.0

        inet6 fe80::42:acff:fe11:3  prefixlen 64  scopeid 0x20<link>

        ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)

        RX packets 434  bytes 52434 (51.2 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 419  bytes 42782 (41.7 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 1  (Local Loopback)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 0  bytes 0 (0.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@dfbc7c3db16b ~]#

退出Docker容器

root@76da79f898c3:/# exit

exit

4、在另一个docker主机查看目前运行的docker进程的ID

root@compute2:~# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES

a8ffa3d75d46        ubuntu              "/bin/bash"         51 seconds ago      Exited (127) 42 seconds ago                       sleepy_kilby

aee77e7dec7b        ubuntu              "/bin/bash"         2 minutes ago       Exited (0) 53 seconds ago                         compassionate_hodgkin

c0a0294d98d2        ubuntu              "/bin/bash"         47 minutes ago      Exited (127) 38 minutes ago                       ecstatic_ritchie

5、将镜像保存为

root@compute2:~# docker commit a8ffa3d75d46 ubuntu-1604-sleepy_kilby

sha256:94c88d9d002364ed5b405357f6910fbc6fdddda917a07f99933a65e66e74fe99

6、将此镜像打包成一个文件

root@compute2:~# docker save ubuntu-1604-sleepy_kilby > /root/ubuntu-1604.tar

7、从终端直接启动容器

root@compute2:~# docker run -i -t -p 50001:22 ubuntu-1604-sleepy_kilby /bin/bash

nova-docker方案实践

安装novadocker

python-pip 有一个BUG,如果已安装python-pip,先删除,

root@compute2:~# apt-get remove python-pip

root@compute2:~#apt-get autoremove

root@compute2:~# easy_install -U pip

root@compute2:~# pip install -e git+https://github.com/stackforge/nova-docker#egg=novadocker

root@compute2:~# cd src/novadocker/

root@compute2:~/src/novadocker# python setup.py install

配置NOVA

root@compute2:~# vim /etc/nova/nova.conf

[DEFAULT]

compute_driver = novadocker.virt.docker.DockerDriver

创建/etc/nova/rootwrap.d/dockers.filters

# nova-rootwrap command filters for setting up network in the docker driver

# This file should be owned by (and only-writeable by) the root user

[Filters]

# nova/virt/docker/driver.py: 'ln', '-sf', '/var/run/netns/.*'

ln: CommandFilter, /bin/ln, root

配置Glance

root@controller:/etc/glance# vim glance-api.conf

[DEFAULT]

container_formats = ami,ari,aki,bare,ovf,docker

下载Docker镜像

查找适用于OpenStack的镜像

root@compute2:~# docker search openstack

NAME                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED

krystism/openstack-keystone          An easy way to try openstack keystone service   7                    [OK]

continuse/openstack-controller       OpenStack Controller Service for CoreOS         5                    [OK]

centurylink/openstack-cli-wetty      This image provides a Wetty terminal with ...   4                    [OK]

cmer81/centos7-openstack             Centos7 image for openstack-cloudinit           2                    [OK]

continuse/openstack-nova-docker      OpenStack Nova-Docker Service for CoreOS        2                    [OK]

cosmicq/openstack-nova               (project not complete) The Nova (compute) ...   1                    [OK]

cosmicq/openstack-rabbitmq           (project not complete) RabbitMQ (AMQP) ser...   1                    [OK]

ennweb/openstack-controller          OpenStack Controller                            1                    [OK]

cosmicq/openstack-keystone           (project not complete) The Keystone (authe...   1                    [OK]

cosmicq/openstack-mariadb            (project not complete) MariaDB and PHPMyAd...   1                    [OK]

continuse/openstack-network          OpenStack Network (Neutron) Service for Co...   1                    [OK]

continuse/openstack-compute          OpenStack Compute Service for CoreOS            1                    [OK]

krystism/openstack-glance            An easy way to try openstack glance service     1                    [OK]

factual/docker-openstack-database    OpenStack Database (MariaDB)                    1                    [OK]

pataquets/openstack-dashboard                                                        0                    [OK]

colstrom/openstack-cli               OpenStack CLI                                   0                    [OK]

continuse/openstack-cinder           OpenStack Block Storage Service for CoreOS      0                    [OK]

alvaroaleman/openstack-horizon       A simple Docker image for the Openstack Ho...   0                    [OK]

pataquets/openstack-keystone                                                         0                    [OK]

pierrezemb/exherbo-openstack         Exherbo image generator for OpenStack           0                    [OK]

factual/docker-openstack-messaging   OpenStack Messaging service (RabbitMQ)          0                    [OK]

ennweb/openstack-compute             OpenStack Compute on Docker                     0                    [OK]

anguslees/openstack-tox                                                              0                    [OK]

gbraad/openstack-client              Container with the OpenStack client and 's...   0                    [OK]

jmcvea/openstack-client              OpenStack command line tools                    0                    [OK]

root@compute2:~#

root@compute2:~# docker pull cmer81/centos7-openstack

Using default tag: latest

latest: Pulling from cmer81/centos7-openstack

a3ed95caeb02: Pull complete

3286cdf780ef: Pull complete

889e0983d8b8: Pull complete

48ed448d00d6: Pull complete

0ebb5fe0f8ad: Pull complete

c93dc6f68ef1: Pull complete

cf8e344e8663: Pull complete

9827381c9ae3: Pull complete

8f1f6b35ea96: Pull complete

Digest: sha256:84b374fe2a8bf40a8716d79e5ea179b2fb28352e8a18fa49ddda2ab295bebe6e

Status: Downloaded newer image for cmer81/centos7-openstack:latest

root@compute2:~# docker save cmer81/centos7-openstack | glance --os-image-api-version 1 image-create --is-public=True --container-format=docker --disk-format=raw --name cmer81/centos7-openstack

+------------------+--------------------------------------+

| Property         | Value                                |

+------------------+--------------------------------------+

| checksum         | 114c19e55638a317b837ae73f6c8314c     |

| container_format | docker                               |

| created_at       | 2016-08-17T03:03:22.000000           |

| deleted          | False                                |

| deleted_at       | None                                 |

| disk_format      | raw                                  |

| id               | 521f5a87-22cc-4851-a812-dee1b17b5e46 |

| is_public        | True                                 |

| min_disk         | 0                                    |

| min_ram          | 0                                    |

| name             | cmer81/centos7-openstack             |

| owner            | f9027cccf7da4f2399c7fdf32e8776f0     |

| protected        | False                                |

| size             | 334179328                            |

| status           | active                               |

| updated_at       | 2016-08-17T03:03:28.000000           |

| virtual_size     | None                                 |

+------------------+--------------------------------------+

查找ubuntu镜像

root@compute2:~# docker search ubuntu

NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED

ubuntu                            Ubuntu is a Debian-based Linux operating s...   4468      [OK]       

ubuntu-upstart                    Upstart is an event-based replacement for ...   65        [OK]       

rastasheep/ubuntu-sshd            Dockerized SSH service, built on top of of...   31                   [OK]

torusware/speedus-ubuntu          Always updated official Ubuntu docker imag...   27                   [OK]

ubuntu-debootstrap                debootstrap --variant=minbase --components...   25        [OK]       

nickistre/ubuntu-lamp             LAMP server on Ubuntu                           8                    [OK]

nuagebec/ubuntu                   Simple always updated Ubuntu docker images...   7                    [OK]

nickistre/ubuntu-lamp-wordpress   LAMP on Ubuntu with wp-cli installed            6                    [OK]

nimmis/ubuntu                     This is a docker images different LTS vers...   5                    [OK]

jordi/ubuntu                      Ubuntu Base Image                               1                    [OK]

admiringworm/ubuntu               Base ubuntu images based on the official u...   1                    [OK]

seetheprogress/ubuntu             Ubuntu image provided by seetheprogress us...   1                    [OK]

darksheer/ubuntu                  Base Ubuntu Image -- Updated hourly             1                    [OK]

life360/ubuntu                    Ubuntu is a Debian-based Linux operating s...   0                    [OK]

datenbetrieb/ubuntu               custom flavor of the official ubuntu base ...   0                    [OK]

konstruktoid/ubuntu               Ubuntu base image                               0                    [OK]

lynxtp/ubuntu                     https://github.com/lynxtp/docker-ubuntu         0                    [OK]

esycat/ubuntu                     Ubuntu LTS                                      0                    [OK]

widerplan/ubuntu                  Our basic Ubuntu images.                        0                    [OK]

croscon/ubuntu                    Crosconized Ubuntu                              0                    [OK]

teamrock/ubuntu                   TeamRock's Ubuntu image configured with AW...   0                    [OK]

smartentry/ubuntu                 ubuntu with smartentry                          0                    [OK]

ustclug/ubuntu                    ubuntu image for docker with USTC mirror        0                    [OK]

dorapro/ubuntu                    ubuntu image                                    0                    [OK]

webhippie/ubuntu                  Docker images for ubuntu                        0                    [OK]

下载镜像

root@compute2:~# docker pull ubuntu

Using default tag: latest

latest: Pulling from library/ubuntu

Digest: sha256:8e2324f2288c26e1393b63e680ee7844202391414dbd48497e9a4fd997cd3cbf

Status: Image is up to date for ubuntu:latest

把镜像上传到Glance中

root@compute2:~# docker save ubuntu | glance image-create --container-format=docker --disk-format=raw --name ubuntu-docer

+------------------+--------------------------------------+

| Property         | Value                                |

+------------------+--------------------------------------+

| checksum         | 364a6b81f4a3f5fb5c4a0e1d62395322     |

| container_format | docker                               |

| created_at       | 2016-08-17T02:46:58Z                 |

| disk_format      | raw                                  |

| id               | e2616723-b55d-48a6-9548-606f0da7dddb |

| min_disk         | 0                                    |

| min_ram          | 0                                    |

| name             | ubuntu-docer                         |

| owner            | f9027cccf7da4f2399c7fdf32e8776f0     |

| protected        | False                                |

| size             | 132096512                            |

| status           | active                               |

| tags             | []                                   |

| updated_at       | 2016-08-17T02:46:59Z                 |

| virtual_size     | None                                 |

| visibility       | private                              |

+------------------+--------------------------------------+

root@compute2:~# nova image-list

+--------------------------------------+-----------------------------------------+--------+--------+

| ID                                   | Name                                    | Status | Server |

+--------------------------------------+-----------------------------------------+--------+--------+

| 96872d33-73a1-4e1d-bc9e-5b4206a258af | CentOS-7-x86_64-GenericCloud            | ACTIVE |        |

| c8d224af-b3ed-42be-a29b-ea7295abf932 | Ubuntu16.04-server-clouding-powerpc64el | ACTIVE |        |

| e9b86672-f9d2-48f3-b57f-0320fc4a048f | Ubuntu16.04-xenial-server-cloud-amd64   | ACTIVE |        |

| 521f5a87-22cc-4851-a812-dee1b17b5e46 | cmer81/centos7-openstack                | ACTIVE |        |

| e2616723-b55d-48a6-9548-606f0da7dddb | ubuntu-docer                            | ACTIVE |        |

| ba5c1506-4389-42b5-acfb-849855b019b5 | ubuntu-server-clouding-amd64            | ACTIVE |        |

| b2170c9b-41da-4b55-a4ec-88b8b3fc528e | ubuntu1604-server-cloud-ppc64el         | ACTIVE |        |

| c94a41f5-10b2-43f8-ae5d-1c91886f6f94 | windows2012server-clouding              | ACTIVE |        |

+--------------------------------------+-----------------------------------------+--------+--------+

root@compute2:~# nova boot centos7-openstack --image 521f5a87-22cc-4851-a812-dee1b17b5e46 --nic net-id=a969f82e-b4cc-48cf-a04a-64923dc73b4a --flavor 22 --security-groups default --key key

+--------------------------------------+-----------------------------------------------------------------+

| Property                             | Value                                                           |

+--------------------------------------+-----------------------------------------------------------------+

| OS-DCF:diskConfig                    | MANUAL                                                          |

| OS-EXT-AZ:availability_zone          |                                                                 |

| OS-EXT-SRV-ATTR:host                 | -                                                               |

| OS-EXT-SRV-ATTR:hostname             | centos7-openstack                                               |

| OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                                               |

| OS-EXT-SRV-ATTR:instance_name        | instance-0000070f                                               |

| OS-EXT-SRV-ATTR:kernel_id            |                                                                 |

| OS-EXT-SRV-ATTR:launch_index         | 0                                                               |

| OS-EXT-SRV-ATTR:ramdisk_id           |                                                                 |

| OS-EXT-SRV-ATTR:reservation_id       | r-3euaomoc                                                      |

| OS-EXT-SRV-ATTR:root_device_name     | -                                                               |

| OS-EXT-SRV-ATTR:user_data            | -                                                               |

| OS-EXT-STS:power_state               | 0                                                               |

| OS-EXT-STS:task_state                | scheduling                                                      |

| OS-EXT-STS:vm_state                  | building                                                        |

| OS-SRV-USG:launched_at               | -                                                               |

| OS-SRV-USG:terminated_at             | -                                                               |

| accessIPv4                           |                                                                 |

| accessIPv6                           |                                                                 |

| adminPass                            | KjbkCzV8VVn2                                                    |

| config_drive                         |                                                                 |

| created                              | 2016-08-17T03:23:21Z                                            |

| description                          | -                                                               |

| flavor                               | zoom.medium (22)                                                |

| hostId                               |                                                                 |

| host_status                          |                                                                 |

| id                                   | 41dad309-eb1a-4445-b1eb-81b87cd34d97                            |

| image                                | cmer81/centos7-openstack (521f5a87-22cc-4851-a812-dee1b17b5e46) |

| key_name                             | key                                                             |

| locked                               | False                                                           |

| metadata                             | {}                                                              |

| name                                 | centos7-openstack                                               |

| os-extended-volumes:volumes_attached | []                                                              |

| progress                             | 0                                                               |

| security_groups                      | default                                                         |

| status                               | BUILD                                                           |

| tenant_id                            | f9027cccf7da4f2399c7fdf32e8776f0                                |

| updated                              | 2016-08-17T03:23:21Z                                            |

| user_id                              | 957ba591d7824e0ab6e54d5c40e6be85                                |

+--------------------------------------+-----------------------------------------------------------------+

root@compute2:~# nova list

+--------------------------------------+-------------------+--------+------------+-------------+-----------------------------------+

| ID                                   | Name              | Status | Task State | Power State | Networks                          |

+--------------------------------------+-------------------+--------+------------+-------------+-----------------------------------+

| 41dad309-eb1a-4445-b1eb-81b87cd34d97 | centos7-openstack | ACTIVE | -          | Running     | private=10.1.1.80, 10.1.1.78      |

| 4f6c62b0-3917-4a4c-a017-bc57ff1a7e4d | ubuntu            | ACTIVE | -          | Running     | private=10.1.1.46

 


本文转自    OpenStack2015 博客,原文链接:    http://blog.51cto.com/andyliu/1852267    如需转载请自行联系原作者


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值