使用 pycharm调试docker环境运行的Odoo

安装Docker
windows系统,参考 docker官方文档
mac系统,参考 docker官方文档
构建自定义ODOO镜像
标准ODOO镜像可能不包含特别的Python模块,或者linux工具,此时需要 自定义 Odoo镜像
 
写dockerfile
编写dockerfile,例如加入需要的python库
? 10.1 git:(master) ? cat Dockerfile
FROM odoo:10.0
MAINTAINER Odoo S.A. <info@odoo.com>
 
USER root
 
COPY ./pip.conf /root/.pip/pip.conf
 
RUN set -x;
pip install pypinyin pypdf
 
# Set default user when running the container
USER odoo
 
ENTRYPOINT ["/entrypoint.sh"]
CMD ["odoo"]
 
说明: 上面的自定义镜像,是在Odoo10 基础上,安装了 pypinyin 模块,为了使用本地pip镜像,例如 pip.conf 内容
? 10.1 git:(master) ? cat pip.conf
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
 
构建镜像
基于dockerfile构建镜像
? 10.1 git:(master) ? docker build . -t odoo:10.1
Sending build context to Docker daemon 3.072kB
Step 1/8 : FROM odoo:10.0
---> 50bfb7575fe2
Step 2/8 : MAINTAINER Odoo S.A. <info@odoo.com>
---> Using cache
---> 353b1366ee28
Step 3/8 : USER root
---> Using cache
---> 27ec1ca1072c
Step 4/8 : COPY ./pip.conf /root/.pip/pip.conf
---> Using cache
---> ebdd6547d4e1
Step 5/8 : RUN set -x; pip install pypinyin pypdf
---> Using cache
---> 72edd5d9d792
Step 6/8 : USER odoo
---> Using cache
---> 0cc904972ec2
Step 7/8 : ENTRYPOINT ["/entrypoint.sh"]
---> Using cache
---> e4738346b7a3
Step 8/8 : CMD ["odoo"]
---> Using cache
---> 793edee6ab30
Successfully built 793edee6ab30
Successfully tagged odoo:10.1
 
这样,就会建立odoo:10.1 镜像
比如 docker images查看镜像
? 10.1 git:(master) ? docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
odoo 10.1 793edee6ab30 3 days ago 894MB <<<<<
<none> <none> 2ebbc09b340c 4 days ago 888MB
<none> <none> 5e1be85e3ee9 4 days ago 894MB
<none> <none> cd0e2acac50b 4 days ago 536MB
<none> <none> 317e442f4416 4 days ago 561MB
<none> <none> 7d6ae7c50fb6 4 days ago 549MB
<none> <none> 73c08dfaaf64 4 days ago 546MB
pycharm_helpers PY-183.6156.16 0430ed2d37ee 6 days ago 37.1MB
odoo 13.0 b77d7d215af3 7 days ago 1.14GB
<none> <none> 7b449bc0b8bd 7 days ago 535MB
odoo 11.0 ac8c1f2da96a 11 days ago 1.07GB
odoo 12.0 a914ad271b31 11 days ago 1.15GB
<none> <none> 687217ff7424 2 weeks ago 84.1MB
postgres 12 f88dfa384cc4 2 weeks ago 348MB
odoo 10.0 50bfb7575fe2 2 weeks ago 888MB
debian stretch-slim c2f145c34384 2 weeks ago 55.3MB
debian buster-slim 105ec214185d 2 weeks ago 69.2MB
debian latest 8e9f8546050d 2 weeks ago 114MB
busybox latest 19485c79a9bb 2 months ago 1.22MB
shadowsocks/shadowsocks-libev latest 4ae4e89442e8 2 months ago 17.4MB
dpage/pgadmin4 latest 15aebd95450f 3 months ago 237MB
postgres 10 897b33033d64 3 months ago 230MB
postgres 11 53912975086f 3 months ago 312MB
mplatform/mquery latest 0e11d82ddb1d 2 years ago 7.11MB
使用docker compose编排 Odoo
odoo是基于多个服务,用docker compose 对这些服务进行编排,会比较方便 。
 
编写 docker-compose.yml
编写 docker-compose.yml 文件,内容如下
? odoo10c cat docker-compose.yml
version: '3.3'
 
services:
# Web Application Service Definition
# --------
#
# All of the information needed to start up an odoo web
# application container.
web:
image: odoo:10.1
depends_on:
- db
- pgadmin
 
# Port Mapping
# --------
#
# Here we are mapping a port on the host machine (on the left)
# to a port inside of the container (on the right.) The default
# port on Odoo is 8069, so Odoo is running on that port inside
# of the container. But we are going to access it locally on
# our machine from localhost:9000.
ports:
- 9000:8069
 
# Data Volumes
# --------
#
# This defines files that we are mapping from the host machine
# into the container.
#
# Right now, we are using it to map a configuration file into
# the container and any extra odoo modules.
volumes:
- ./config:/etc/odoo


推荐阅读