برای پیاده سازی Odoo توی داکر باید اول docker-compose.yml رو داشته باشیم:
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 |
version: '3.1' services: odoo: build: context: ./odoo dockerfile: Dockerfile container_name: odoo17 ports: - "8069:8069" volumes: - odoo-data:/var/lib/odoo - ./odoo/odoo17.conf:/etc/odoo17.conf - ./odoo/odoo-custom-addons:/opt/odoo17/odoo-custom-addons environment: - HOST=odoo17-db - USER=odoo17 - PASSWORD=odoo17 depends_on: - db user: "odoo17:odoo17" db: build: context: ./postgres dockerfile: Dockerfile container_name: odoo17-db environment: - POSTGRES_USER=odoo17 - POSTGRES_PASSWORD=odoo17 - POSTGRES_DB=postgres volumes: - db-data:/var/lib/postgresql/data volumes: odoo-data: db-data: |
داکرفایل postgress:
1 2 |
FROM library/postgres COPY init.sql /docker-entrypoint-initdb.d/ |
یه فایل init.sql هم استفاده شده:
1 |
CREATE USER odoo17 IDENTIFIED BY odoo17; |
فایل odoo17.conf
1 2 3 4 5 6 7 8 |
[options] admin_passwd = amir db_host = odoo17-db db_port = 5432 db_user = odoo17 db_password = odoo17 addons_path = /opt/odoo17/odoo/addons,/opt/odoo17/odoo-custom-addons logfile = /var/log/odoo/odoo.log |
از همه مهمتر Dockerfile خود Odoo:
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 |
# Use an official Python runtime as a parent image FROM python:3.11-slim # Set environment variables ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 # Install required packages and dependencies RUN apt-get update && apt-get install -y --fix-missing \ git \ build-essential \ wget \ python3-dev \ libfreetype6-dev \ libxml2-dev \ libzip-dev \ libldap2-dev \ libsasl2-dev \ node-less \ libjpeg62-turbo-dev \ zlib1g-dev \ libpq-dev \ libxslt1-dev \ libtiff5-dev \ libopenjp2-7-dev \ liblcms2-dev \ libwebp-dev \ libharfbuzz-dev \ libfribidi-dev \ libxcb1-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Create Odoo user and group RUN groupadd -r odoo17 && useradd -m -d /opt/odoo17 -g odoo17 -s /bin/bash odoo17 # Switch to Odoo user USER odoo17 # Set working directory WORKDIR /opt/odoo17 # Clone Odoo source code RUN git clone --depth 1 --branch 17.0 https://www.github.com/odoo/odoo /opt/odoo17/odoo # Create and activate a virtual environment, then install dependencies RUN python3 -m venv odoo-venv && \ /bin/bash -c "source odoo-venv/bin/activate && pip install wheel && pip install -r /opt/odoo17/odoo/requirements.txt" # Create custom addons directory RUN mkdir /opt/odoo17/odoo-custom-addons # Copy Odoo configuration file COPY odoo17.conf /etc/odoo17.conf # Expose Odoo port EXPOSE 8069 # Define the command to run the Odoo server CMD ["/opt/odoo17/odoo-venv/bin/python3", "/opt/odoo17/odoo/odoo-bin", "-c", "/etc/odoo17.conf"] |