分类 ubuntu 下的文章

如何通过docker容器安装LNMP服务器环境
时间:2014-11-17 来源:服务器之家 投稿:root
安装 系统环境

硬件型号: ThinkPad T520

系统版本: ubuntu 14.04

CPU: i7

RAM: 8G
添加软件源

由于Ubuntu源中的最先版本为0.9无法满足要求,所以需要使用Docker的官方源
添加密钥:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80
--recv-keys \
36A1D7869245C8950F966E92D8576A8BA88D21E9
源地址: deb http://get.docker.io/ubuntu docker main
添加源可以通过"软件和更新->其它软件->添加"来操作
添加后执行如下命令:
$ sudo apt-get update
$ sudo apt-get install lxc-docker-1.1.1

注: 官方给出的源地址为https连接的,但是总是出现ssl验证失败的错误,最后改为非
ssl连接之后正常
测试

执行如下命令获取容器镜像,创建一个实例并打开一个实例shell
$ sudo docker run -t -i centos:latest /bin/bash

注:第一次运行由于需要下载镜像可能需要多等一会儿
运行成功后会有一个新的shell提示符
制作镜像 要求

web容器安装Nginx+PHP服务

数据库容器安装Mysql服务

web服务和数据库分离

web服务容器可以访问数据库容器
制作nginx+php镜像

启动一个容器实例:
$ sudo docker run -t -i centos:latest /bin/bash
安装nginx与PHP:
Nginx可以使用源码或rpm包进行安装,PHP可以使用源码或yum安装.具体安装和配置这里
不进行具体讲述.

注:需要把nginx与php-fpm添加到系统服务中并设置开机启动
我设置的站点根目录为/opt/web

退出shell并执行如下命令制作镜像:
$ sudo docker commit -m="web service image nginx+php" -a="username" \
sudo docker ps -lq username/web:v1

这是一个组合命令:
sudo docker commit根据已有实例制作镜像
sudo docker ps -lq返回最后一个运行的实例id
已有镜像可以使用sudo docker images 查看
至此创建了第一个镜像 username/web:v1
制作mysql镜像

启动实例:
$ sudo docker run -t -i centos:latest /bin/bash
安装Mysql.
设置Mysql服务开机启动:
$ chkconfig mysqld on
启动mysql.
修改mysql登陆权限:
mysql> grant all privileges on . to 'root'@'%'
identified by 'dbpasswd';
mysql> flush privileges;

mysql服务默认只能本地连接,制作镜像的时候需要注意.否则是无法连接到数据库的.

退出shell并执行如下命令制作mysql容器镜像:
$ sudo docker commit -m="mysql service image" -a="username" \
sudo docker ps -lq username/mysql:v1

清除不再需要的实例:
$ sudo docker rm sudo docker ps -aq
启动并关联实例

web实例依赖与mysql,所以先打开一个mysql实例:
$ sudo docker run -d --name db username/mysql:v1
/sbin/init

-d参数是让实例以dameon的形式运行. /sbin/init是创建实例后执行的操作,此处为初
始化系统服务,包括运行mysql.

启动web实例并与数据库实例进行关联:
$ sudo docker run -d --name web --link db:db -p 8080:80 -v /path/to/src:/opt/web username/web:v1 /sbin/init

--link参数设置关联的容器,可以设置多个.关联之后会自动更新web容器的host,把db
的地址指向到数据库容器的地址.
-p 参数用来进行ip映射.此处把容器的80端口映射到了本地的8080端口.web服务可是
通过localhost:8080访问.
-v 参数把数据挂载到容器指定目录.此处为把站点源码目录挂载到容器的站点目录.
在web容器中访问数据库容器的mysql服务可以使用db这个主机地址.

转载请注明原文地址:http://www.server110.com/docker/201411/11070.html

Docker Pull Command

docker pull odoo

Tag Name Size

latest 268 MB
9 268 MB
9.0 268 MB
8 264 MB
8.0 264 MB

Full Description
Supported tags and respective Dockerfile links

8.0, 8 (8.0/Dockerfile)
9.0, 9, latest (9.0/Dockerfile)

For more information about this image and its history, please see the relevant manifest file (library/odoo). This image is updated via pull requests to the docker-library/official-images GitHub repo.

For detailed information about the virtual/transfer sizes and individual layers of each of the above supported tags, please see the odoo/tag-details.md file in the docker-library/docs GitHub repo.
What is Odoo?

Odoo, formerly known as OpenERP, is a suite of open-source business apps written in Python and released under the AGPL license. This suite of applications covers all business needs, from Website/Ecommerce down to manufacturing, inventory and accounting, all seamlessly integrated. It is the first time ever a software editor managed to reach such a functional coverage. Odoo is the most installed business software in the world. Odoo is used by 2.000.000 users worldwide ranging from very small companies (1 user) to very large ones (300 000 users).

www.odoo.com

How to use this image

This image requires a running PostgreSQL server.
Start a PostgreSQL server

$ docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --name db postgres

Start an Odoo instance

$ docker run -p 127.0.0.1:8069:8069 --name odoo --link db:db -t odoo

The alias of the container running Postgres must be db for Odoo to be able to connect to the Postgres server.
Stop and restart an Odoo instance

$ docker stop odoo
$ docker start -a odoo

Stop and restart a PostgreSQL server

When a PostgreSQL server is restarted, the Odoo instances linked to that server must be restarted as well because the server address has changed and the link is thus broken.

Restarting a PostgreSQL server does not affect the created databases.
Run Odoo with a custom configuration

The default configuration file for the server (located at /etc/odoo/openerp-server.conf) can be overriden at startup using volumes. Suppose you have a custom configuration at /path/to/config/openerp-server.conf, then

$ docker run -v /path/to/config:/etc/odoo -p 127.0.0.1:8069:8069 --name odoo --link db:db -t odoo

Please use this configuration template to write your custom configuration as we already set some arguments for running Odoo inside a Docker container.

You can also directly specify Odoo arguments inline. Those arguments must be given after the keyword -- in the command-line, as follows

$ docker run -p 127.0.0.1:8069:8069 --name odoo --link db:db -t odoo -- --db-filter=odoo_db_.*

Mount custom addons

You can mount your own Odoo addons within the Odoo container, at /mnt/extra-addons

$ docker run -v /path/to/addons:/mnt/extra-addons -p 127.0.0.1:8069:8069 --name odoo --link db:db -t odoo

Run multiple Odoo instances

$ docker run -p 127.0.0.1:8070:8069 --name odoo2 --link db:db -t odoo
$ docker run -p 127.0.0.1:8071:8069 --name odoo3 --link db:db -t odoo

Please note that for plain use of mails and reports functionalities, when the host and container ports differ (e.g. 8070 and 8069), one has to set, in Odoo, Settings->Parameters->System Parameters (requires technical features), web.base.url to the container port (e.g. 127.0.0.1:8069).
How to upgrade this image

Suppose you created a database from an Odoo instance named old-odoo, and you want to access this database from a new Odoo instance named new-odoo, e.g. because you've just downloaded a newer Odoo image.

By default, Odoo 8.0 uses a filestore (located at /var/lib/odoo/filestore/) for attachments. You should restore this filestore in your new Odoo instance by running

$ docker run --volumes-from old-odoo -p 127.0.0.1:8070:8069 --name new-odoo --link db:db -t odoo

You can also simply prevent Odoo from using the filestore by setting the system parameter ir_attachment.location to db-storage in Settings->Parameters->System Parameters (requires technical features).
License

View license information for the software contained in this image.
Supported Docker versions

This image is officially supported on Docker version 1.9.1.

Support for older versions (down to 1.6) is provided on a best-effort basis.

Please see the Docker installation documentation for details on how to upgrade your Docker daemon.
User Feedback Documentation

Documentation for this image is stored in the odoo/ directory of the docker-library/docs GitHub repo. Be sure to familiarize yourself with the repository's README.md file before attempting a pull request.
Issues

If you have any problems with or questions about this image, please contact us through a GitHub issue.

You can also reach many of the official image maintainers via the #docker-library IRC channel on Freenode.
Contributing

You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.

Before you start to code, we recommend discussing your plans through a GitHub issue, especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing.

思路是修改ubuntu系统存储挂载,如下:
Docker的镜像以及一些数据都是在/var/lib/docker目录下,它占用的是Linux的系统分区,也就是下面的/dev/vda1,当有多个镜像时,/dev/vda1的空间可能不足,我们可以把docker的数据挂载到数据盘,例如:/dev/vdb目录下。
[root@10-10-63-106 docker]# df -lhT
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 xfs 20G 3.8G 16G 20% /
devtmpfs devtmpfs 916M 0 916M 0% /dev
tmpfs tmpfs 921M 0 921M 0% /dev/shm
tmpfs tmpfs 921M 43M 878M 5% /run
tmpfs tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/vdb xfs 100G 11G 90G 11% /data

     其中主要的步骤如下:

(1) 首先,备份fstab文件
sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
(2) 停止docker, 用rsync同步/var/lib/docker到新位置.

    如果rsync没有安装,则使用yum -y intall rsync 进行安装,停止docker ,service docker stop,在数据分区中建立要挂载的目录,mkdir /data/docker 使用rsync工具同步,rsync -aXS /var/lib/docker/.  /data/docker/,这可能需要花费的较长的时间,取决于/var/lib/docker的大小,

(3) 修改fstab
在该文件中把下面一行添加到fstab里,将新位置挂载到 /var/lib/docker
/data/docker /var/lib/docker none bind 0 0
文件的内如如下:
[root@10-10-63-106 docker]# cat /etc/fstab

/etc/fstab

Created by anaconda on Thu Jul 31 07:50:13 2014

Accessible filesystems, by reference, are maintained under '/dev/disk'

See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

/dev/vda1 / xfs errors=remount-ro 0 1
/swapfile none swap defaults 0 0
/dev/vdb /data xfs defaults,noatime 0 0
/data/docker /var/lib/docker none bind 0 0
(4) 重新挂载
mount –a
(5) 使用下面的命令检查一下
df /var/lib/docker/
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vdb 104806400 47204 104759196 1% /var/lib/docker
(6)进入Container查看我们的空间
bash-4.1# df -lhT
Filesystem Type Size Used Avail Use% Mounted on
rootfs rootfs 9.8G 1.4G 7.9G 15% /
tmpfs tmpfs 921M 0 921M 0% /dev
shm tmpfs 64M 0 64M 0% /dev/shm
/dev/vdb xfs 100G 2.1G 98G 3% /etc/resolv.conf
/dev/vdb xfs 100G 2.1G 98G 3% /etc/hostname
/dev/vdb xfs 100G 2.1G 98G 3% /etc/hosts
tmpfs tmpfs 921M 0 921M 0% /run/secrets
tmpfs tmpfs 921M 0 921M 0% /proc/kcore
没有更改/var/lib/docker路径之前的情况:
bash-4.1# df -lhT
Filesystem Type Size Used Avail Use% Mounted on
rootfs rootfs 9.8G 1.4G 7.9G 15% /
tmpfs tmpfs 921M 0 921M 0% /dev
shm tmpfs 64M 0 64M 0% /dev/shm
/dev/vda1 xfs 20G 13G 6.9G 66% /etc/resolv.conf
/dev/vda1 xfs 20G 13G 6.9G 66% /etc/hostname
/dev/vda1 xfs 20G 13G 6.9G 66% /etc/hosts
tmpfs tmpfs 921M 0 921M 0% /run/secrets
tmpfs tmpfs 921M 0 921M 0% /proc/kcore
宿主机中的分区大小信息:
[root@10-10-63-106 ~]# df -lhT
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 xfs 20G 13G 6.9G 65% /
devtmpfs devtmpfs 916M 0 916M 0% /dev
tmpfs tmpfs 921M 0 921M 0% /dev/shm
tmpfs tmpfs 921M 89M 832M 10% /run
tmpfs tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/vdb xfs 100G 33M 100G 1% /data

一、需要docker的gui界面进行管理如下:
1、位置:https://github.com/crosbymichael/dockerui
执行命令:
$ docker run -d -p 9000:9000 --privileged -v /var/run/docker.sock:/var/run/docker.sock dockerui/dockerui

2、浏览器打开网址:http://:9000例如本机:http://localhost:9000即可ui界面管理docker。
3、docker运行参数有以下几种:

二、postgresql数据库的运行参数:
1、在odoo的官方docker里的参数:
$ docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --name db postgres
$ docker run -p 127.0.0.1:8069:8069 --name odoo --link db:db -t odoo
将postgres以odoo用户名以odoo为密码以db为docker名字名称来运行一个images postgres。
随后将odoo以8069端口以link命令将db连网连接互相通讯交换数据互连起来。

Docker build for Postgresql 9.3

This repository provides Dockerfile for Postgresql 9.3 with SSH access, initally created to be used by but not limited to shaker/odoo docker image.

Started from: http://docs.docker.io/examples/postgresql_service/
Status

Ubuntu: 14.04
Postgresql: 9.3

Built images are uploaded to index.docker.io
Usage:

Install Docker: http://docs.docker.io/
Execute
docker run -d --name postgresql shaker/postgresql
to run with SSH on port 2222
docker run -d --name postgresql -p 2222:22 shaker/postgresql
If you like to expose postgresql port too:
docker run -d --name postgresql -p 2222:22 -p 5432:5432 shaker/postgresql
Stop and start again
    docker stop postgresql
    docker start postgresql
ssh root password is postgresql - you should change it if you exposed ssh port.
directories that can be mounted by docker (to allow backup of config, logs and databases):
    configuration: /etc/postgresql
    logs: /var/log/postgresql
    db data: /var/lib/postgresql

The official Odoo docker images have been published on docker.com

https://registry.hub.docker.com/_/odoo/

The docker file is maintained in this repository

https://github.com/odoo/docker

They depends on postgresql images, usage is pretty simple:

$ docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --name db postgres
$ docker run -p 127.0.0.1:8069:8069 --name odoo --link db:db -t odoo

We will update the install/deploy documentation to mention them.

https://www.odoo.com/documentation/8.0/setup/install.html