docker 与多版本 odoo

docker安装步骤

  1. 添加docker官方gpg key:

    1
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  2. 添加docker apt源
    /etc/apt/sources.list.d/docker.list

1
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
  1. 更新源

    1
    apt-get update
  2. 安装docker

1
apt-get install docker-ce
  1. 测试安装是否成功
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    kevin@venus:~$ sudo docker run hello-world
    [sudo] password for kevin:
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    9bb5a5d4561a: Pull complete
    Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
    Status: Downloaded newer image for hello-world:latest

    Hello from Docker!
    This message shows that your installation appears to be working correctly.

    To generate this message, Docker took the following steps:
    1. The Docker client contacted the Docker daemon.
    2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
    3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
    4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

    To try something more ambitious, you can run an Ubuntu container with:
    $ docker run -it ubuntu bash

    Share images, automate workflows, and more with a free Docker ID:
    https://hub.docker.com/

    For more examples and ideas, visit:
    https://docs.docker.com/engine/userguide/

创建第一个镜像

1
docker pull ubuntu:16.04

由于国外网速访问过慢,这里我们才用国内镜像加速站点官方中国镜像

1
2
3
4
5
6
7
8
9
10
sudo docker pull registry.docker-cn.com/library/ubuntu:16.04

16.04: Pulling from library/ubuntu
b234f539f7a1: Pull complete
55172d420b43: Pull complete
5ba5bbeb6b91: Pull complete
43ae2841ad7a: Pull complete
f6c9c6de4190: Pull complete
Digest: sha256:b050c1822d37a4463c01ceda24d0fc4c679b0dd3c43e742730e2884d3c582e3a
Status: Downloaded newer image for registry.docker-cn.com/library/ubuntu:16.04

查看镜像

1
2
3
4
kevin@venus:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.docker-cn.com/library/ubuntu 16.04 5e8b97a2a082 3 weeks ago 114MB
hello-world latest e38bc07ac18e 2 months ago 1.85kB

启动一个容器:

1
sudo docker -it 5e8b97a2a082 bash

在容器内,发现无法apt-get安装vim,经查需要先apt-get update一下才可以正常使用。

制作odoo的8.0版镜像

由于docker的ubuntu版本不带systemctl工具,用包管理的方式安装在docker内安装odoo并不是一个最优方案,这里我们采用另外一种镜像方式:通过dockerfile来安装odoo。

odoo官方在dockerhub中有已经写好的dockerfile,只不过目前只剩9.0,10.0,11.0了,8.0已经作古。虽然如此,但我们还是在github上找到8.0了遗迹

Dockerfile的8.0版本

有了dockerfile剩下的事情就好办多了。

首先,8.0的版本有几个需要需改的地方:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
FROM debian:jessie # ubuntu:16.04 这里我们使用的是ubuntu的16.04版本 
MAINTAINER Odoo S.A. <info@odoo.com>

#这一段是我加得,因为需要用到python-support这个包,而这个包在16.04里不能通过apt-get的方式安装成功
RUN apt-get update
RUN apt-get -y install wget
RUN wget http://launchpadlibrarian.net/109052632/python-support_1.0.15_all.deb
RUN apt-get -y install python
RUN dpkg -i python-support_1.0.15_all.deb

# Install some deps, lessc and less-plugin-clean-css, and wkhtmltopdf
RUN set -x; \
apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
node-less \
node-clean-css \
python-pyinotify \
python-renderpm \
python-support \
&& curl -o wkhtmltox.deb -SL http://nightly.odoo.com/extra/wkhtmltox-0.12.1.2_linux-jessie-amd64.deb \
&& echo '40e8b906de658a2221b15e4e8cd82565a47d7ee8 wkhtmltox.deb' | sha1sum -c - \
&& dpkg --force-depends -i wkhtmltox.deb \
&& apt-get -y install -f --no-install-recommends \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false npm \
&& rm -rf /var/lib/apt/lists/* wkhtmltox.deb

# Install Odoo
ENV ODOO_VERSION 8.0
ENV ODOO_RELEASE 20151215
RUN set -x; \
curl -o odoo.deb -SL http://nightly.odoo.com/${ODOO_VERSION}/nightly/deb/odoo_${ODOO_VERSION}.${ODOO_RELEASE}_all.deb \
&& echo '8d3454047891074cc0805d30f11dd393831d69d8 odoo.deb' | sha1sum -c - \
&& dpkg --force-depends -i odoo.deb \
&& apt-get update \
&& apt-get -y install -f --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* odoo.deb

# Copy entrypoint script and Odoo configuration file
COPY ./entrypoint.sh /
COPY ./openerp-server.conf /etc/odoo/
RUN chown odoo /etc/odoo/openerp-server.conf
#这一段也是我加的
RUN chmod +x /entrypoint.sh


# Mount /var/lib/odoo to allow restoring filestore and /mnt/extra-addons for users addons
RUN mkdir -p /mnt/extra-addons \
&& chown -R odoo /mnt/extra-addons
VOLUME ["/var/lib/odoo", "/mnt/extra-addons"]

# Expose Odoo services
EXPOSE 8069 8071

# Set the default config file
ENV OPENERP_SERVER /etc/odoo/openerp-server.conf

# Set default user when running the container
USER odoo

ENTRYPOINT ["/entrypoint.sh"]
CMD ["openerp-server"]

总结一下:

  1. 需要安装wget和python-support这个库,python-support在16.04上只能手动安装
  2. 需要给entrypoint.sh这个文件的运行权限,否则在启动容器的时候会报权限错误

完后装备工作后,就可以开始构建docker镜像了,注意,这里要将entrypoint.sh和openerp-server.conf和Dockerfile放到同一个目录下。

构建:

1
docker build . -t odoo:v8

大概需要十几分钟到二三十分钟左右的样子,看你的网络,镜像构建完成。

1
2
REPOSITORY    TAG        IMAGE ID            CREATED             SIZE
odoo v8 cc0330013b8b About an hour ago 742MB

接下来需要设置数据库,这里我们使用host本身的数据库,也可以采用官方的建议,构建一个PG的镜像,这里按下不表。简单说一下配置docker访问PG需要注意的几个问题。

  1. 把host本地的pg设置为所有人可以访问。
  2. 在pg中创建odoo用户并给予访问和创建的权限。

启动容器:

1
docker run -d -e PGUSER=odoo -e PGPASSWORD=odoo -e PGHOST=192.168.221.130 -p 8069:8069 cc0330013b8b

参数解释:
PGUSER 是访问数据用的用户
PGPASSWORD 是访问数据库和密码
PGHOST 是host的ip地址,不要用localhost
-p 是把容器的端口映射给host

好了,接下来用浏览器访问一下host的8069端口,看一下能不能打开吧。

查看docker的日志的命令是

1
docker logs cc0330013b8b

制作odoo 9.0 镜像

步骤同8.0类似,完整的Dockerfile如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

FROM ubuntu:16.04
MAINTAINER Odoo S.A. <info@odoo.com>

# Install some deps, lessc and less-plugin-clean-css, and wkhtmltopdf
RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN apt-get update \
&& apt-get -y install wget \
&& wget http://launchpadlibrarian.net/109052632/python-support_1.0.15_all.deb \
&& apt-get -y install python \
&& dpkg -i python-support_1.0.15_all.deb \
&& apt-get -y install python-pip \
&& pip install -U setuptools
RUN set -x; \
apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
node-less \
python-gevent \
python-pip \
python-renderpm \
python-support \
python-watchdog \
&& curl -o wkhtmltox.deb -SL http://nightly.odoo.com/extra/wkhtmltox-0.12.1.2_linux-jessie-amd64.deb \
&& echo '40e8b906de658a2221b15e4e8cd82565a47d7ee8 wkhtmltox.deb' | sha1sum -c - \
&& dpkg --force-depends -i wkhtmltox.deb \
&& apt-get -y install -f --no-install-recommends \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false npm \
&& rm -rf /var/lib/apt/lists/* wkhtmltox.deb \
&& pip install psycogreen==1.0

# Install Odoo
ENV ODOO_VERSION 10.0
ENV ODOO_RELEASE 20180704
RUN set -x; \
curl -o odoo.deb -SL http://nightly.odoo.com/${ODOO_VERSION}/nightly/deb/odoo_${ODOO_VERSION}.${ODOO_RELEASE}_all.deb \
&& dpkg --force-depends -i odoo.deb \
&& apt-get update \
&& apt-get -y install -f --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* odoo.deb

# Copy entrypoint script and Odoo configuration file
COPY ./entrypoint.sh /
COPY ./odoo.conf /etc/odoo/
RUN chown odoo /etc/odoo/odoo.conf \
&& chmod +x /entrypoint.sh

# Mount /var/lib/odoo to allow restoring filestore and /mnt/extra-addons for users addons
RUN mkdir -p /mnt/extra-addons \
&& chown -R odoo /mnt/extra-addons
VOLUME ["/var/lib/odoo", "/mnt/extra-addons"]

# Expose Odoo services
EXPOSE 8069 8071

# Set the default config file
ENV ODOO_RC /etc/odoo/odoo.conf

# Set default user when running the container
USER odoo

ENTRYPOINT ["/entrypoint.sh"]
CMD ["odoo"]

诡异的事情又出来一个,构建完镜像启动容器的时候发现报了这么一个莫名其妙的错误:

1
2
kevin@venus:~/docker_odoo10$ docker logs e43
standard_init_linux.go:190: exec user process caused "no such file or directory"

后来查到是entrypoint.sh的脚本格式是dos,需要改成unix并重新build

1
2
3
vim entrypoint.sh
:set ff
:set ff=unix:wq

推送自己的镜像到dockerhub

登录自己的dockerhub账号:

1
2
3
4
5
6
docker login

Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username:
Password:
Login Succeeded

首先用tag 命令规范化自己的镜像命名

1
docker tag odoo:v11 kevinkong/odoo:v11

然后使用docker push 命令将镜像推送到dockerhub

1
docker push kevinkong/odoo:v11
你的支持我的动力