老天 发布的文章

Docker Dockerfile使用详解
时间:2014-11-19 来源:服务器之家 投稿:root
如何使用

Dockerfile用来创建一个自定义的image,包含了用户指定的软件依赖等。当前目录下包含Dockerfile,使用命令build来创建新的image,并命名为edwardsbean/centos6-jdk1.7:
docker build -t edwardsbean/centos6-jdk1. .
Dockerfile关键字

如何编写一个Dockerfile,格式如下:

CommentINSTRUCTION arguments

FROM

基于哪个镜像
RUN

安装软件用
MAINTAINER

镜像创建者
CMD

container启动时执行的命令,但是一个Dockerfile中只能有一条CMD命令,多条则只执行最后一条CMD.

CMD主要用于container时启动指定的服务,当docker run command的命令匹配到CMD command时,会替换CMD执行的命令。如:
Dockerfile:
CMD echo hello world

运行一下试试:
edwardsbean@ed-pc:~/software/docker-image/centos-add-test$ docker run centos-cmd
hello world

一旦命令匹配:
edwardsbean@ed-pc:~/software/docker-image/centos-add-test$ docker run centos-cmd echo hello edwardsbean
hello edwardsbean
ENTRYPOINT

container启动时执行的命令,但是一个Dockerfile中只能有一条ENTRYPOINT命令,如果多条,则只执行最后一条

ENTRYPOINT没有CMD的可替换特性
USER

使用哪个用户跑container
如:
ENTRYPOINT ["memcached"]
USER daemon
EXPOSE

container内部服务开启的端口。主机上要用还得在启动container时,做host-container的端口映射:
docker run -d -p 127.0.0.1:33301: centos6-ssh

container ssh服务的22端口被映射到主机的33301端口
ENV

用来设置环境变量,比如:
ENV LANG en_US.UTF-
ENV LC_ALL en_US.UTF-
ADD

将文件拷贝到container的文件系统对应的路径
所有拷贝到container中的文件和文件夹权限为0755,uid和gid为0
如果文件是可识别的压缩格式,则docker会帮忙解压缩

如果要ADD本地文件,则本地文件必须在 docker build ,指定的目录下

如果要ADD远程文件,则远程文件必须在 docker build ,指定的目录下。比如:
docker build github.com/creack/docker-firefox

docker-firefox目录下必须有Dockerfile和要ADD的文件

注意:使用docker build - <
somefile方式进行build,是不能直接将本地文件ADD到container中。只能ADD url file.

ADD只有在build镜像的时候运行一次,后面运行container的时候不会再重新加载了。
VOLUME

可以将本地文件夹或者其他container的文件夹挂载到container中。
WORKDIR

切换目录用,可以多次切换(相当于cd命令),对RUN,CMD,ENTRYPOINT生效
ONBUILD

ONBUILD 指定的命令在构建镜像时并不执行,而是在它的子镜像中执行

转载请注明原文地址:http://www.server110.com/docker/201411/11101.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连网连接互相通讯交换数据互连起来。

参考:http://www.zoobab.com/docker-openwrt-image
docker仅64bit因此下载openwrt的x64回来:
$ wget http://downloads.openwrt.org/attitude_adjustment/12.09-rc2/x86/generic/openwrt-x86-generic-rootfs.tar.gz
然后通过zcat将下载得到的rootfs.tar.gz导入docker中:
$ zcat openwrt-x86-generic-rootfs.tar.gz | docker import - openwrt-x86
用docker images查看一下docker import 得到的openwrt-x86的images镜像:
看到后,用docker run来运行一个简单的openwrt-x86的容器:
$ docker run -i openwrt-x86 cat /etc/banner
此时挂载到 /sbin/init:
$ docker run -i openwrt-x86 /sbin/init

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