|
| 1 | +# Odoo Installation (Docker) |
| 2 | + |
| 3 | +> [!NOTE] |
| 4 | +> Last update: 2025-12-29 |
| 5 | +
|
| 6 | +```.sh |
| 7 | +# Settings |
| 8 | +domain="website.com" |
| 9 | +domain_root_path="/home/$domain" |
| 10 | +subdomain="erp" |
| 11 | +system_user="website" |
| 12 | +odoo_version="18.0" |
| 13 | +database_name="website_odoo" |
| 14 | +database_host="db" |
| 15 | +database_port=5432 |
| 16 | +database_username="website_odoo_user" |
| 17 | +database_password=$(openssl rand -base64 32 | tr -dc 'A-Za-z0-9') |
| 18 | +odoo_master_password=$(openssl rand -base64 32 | tr -dc 'A-Za-z0-9') |
| 19 | +odoo_http_port=8069 |
| 20 | +odoo_longpolling_port=8072 |
| 21 | +odoo_workers=2 |
| 22 | +``` |
| 23 | + |
| 24 | +## [Odoo](https://www.odoo.com) |
| 25 | + |
| 26 | +```.sh |
| 27 | +# Create directories |
| 28 | +sudo mkdir -p $domain_root_path/domains/$subdomain.$domain/odoo |
| 29 | +sudo chown -R $system_user:$system_user $domain_root_path/domains/$subdomain.$domain/odoo |
| 30 | +``` |
| 31 | + |
| 32 | +```.sh |
| 33 | +# Add the system user to the docker group |
| 34 | +sudo usermod -aG docker $system_user |
| 35 | + |
| 36 | +# Verify the user is in the docker group |
| 37 | +groups $system_user |
| 38 | +``` |
| 39 | + |
| 40 | +```.sh |
| 41 | +# Create docker-compose.yml |
| 42 | +cat <<EOF > "$domain_root_path/domains/$subdomain.$domain/odoo/docker-compose.yml" |
| 43 | +name: odoo |
| 44 | +
|
| 45 | +services: |
| 46 | + odoo: |
| 47 | + container_name: "odoo_server_${system_user}" |
| 48 | + image: odoo:\${ODOO_VERSION} |
| 49 | + depends_on: |
| 50 | + db: |
| 51 | + condition: service_healthy |
| 52 | + ports: |
| 53 | + - "127.0.0.1:\${ODOO_HTTP_PORT}:8069" |
| 54 | + - "127.0.0.1:\${ODOO_LONGPOLLING_PORT}:8072" |
| 55 | + volumes: |
| 56 | + - \${ODOO_DATA_LOCATION}:/var/lib/odoo |
| 57 | + - \${ODOO_CONFIG_LOCATION}:/etc/odoo |
| 58 | + - \${ODOO_ADDONS_LOCATION}:/mnt/extra-addons |
| 59 | + - /etc/localtime:/etc/localtime:ro |
| 60 | + environment: |
| 61 | + - HOST=\${DB_HOST} |
| 62 | + - PORT=\${DB_PORT} |
| 63 | + - USER=\${DB_USERNAME} |
| 64 | + - PASSWORD=\${DB_PASSWORD} |
| 65 | + env_file: |
| 66 | + - .env |
| 67 | + restart: always |
| 68 | +
|
| 69 | + db: |
| 70 | + container_name: "odoo_postgres_${system_user}" |
| 71 | + image: postgres:16 |
| 72 | + environment: |
| 73 | + POSTGRES_DB: postgres |
| 74 | + POSTGRES_USER: \${DB_USERNAME} |
| 75 | + POSTGRES_PASSWORD: \${DB_PASSWORD} |
| 76 | + PGDATA: /var/lib/postgresql/data/pgdata |
| 77 | + volumes: |
| 78 | + - \${DB_DATA_LOCATION}:/var/lib/postgresql/data/pgdata |
| 79 | + shm_size: 128mb |
| 80 | + restart: always |
| 81 | + healthcheck: |
| 82 | + test: ["CMD-SHELL", "pg_isready -U \${DB_USERNAME}"] |
| 83 | + interval: 10s |
| 84 | + timeout: 5s |
| 85 | + retries: 5 |
| 86 | +
|
| 87 | +EOF |
| 88 | +``` |
| 89 | + |
| 90 | +```.sh |
| 91 | +# Create .env file |
| 92 | +cat <<EOF > "$domain_root_path/domains/$subdomain.$domain/odoo/.env" |
| 93 | +# Odoo version |
| 94 | +ODOO_VERSION=$odoo_version |
| 95 | +
|
| 96 | +# Odoo ports |
| 97 | +ODOO_HTTP_PORT=$odoo_http_port |
| 98 | +ODOO_LONGPOLLING_PORT=$odoo_longpolling_port |
| 99 | +
|
| 100 | +# Odoo data locations |
| 101 | +ODOO_DATA_LOCATION=$domain_root_path/domains/$subdomain.$domain/odoo/data |
| 102 | +ODOO_CONFIG_LOCATION=$domain_root_path/domains/$subdomain.$domain/odoo/config |
| 103 | +ODOO_ADDONS_LOCATION=$domain_root_path/domains/$subdomain.$domain/odoo/addons |
| 104 | +
|
| 105 | +# PostgreSQL data location |
| 106 | +DB_DATA_LOCATION=$domain_root_path/domains/$subdomain.$domain/odoo/postgres |
| 107 | +
|
| 108 | +# Database credentials |
| 109 | +DB_HOST=$database_host |
| 110 | +DB_PORT=$database_port |
| 111 | +DB_USERNAME=$database_username |
| 112 | +DB_PASSWORD=$database_password |
| 113 | +
|
| 114 | +EOF |
| 115 | + |
| 116 | +# Secure .env file |
| 117 | +chmod 600 "$domain_root_path/domains/$subdomain.$domain/odoo/.env" |
| 118 | +``` |
| 119 | + |
| 120 | +```.sh |
| 121 | +# Create directory |
| 122 | +sudo mkdir -p $domain_root_path/domains/$subdomain.$domain/odoo/config |
| 123 | + |
| 124 | +# Create odoo.conf |
| 125 | +cat <<EOF > "$domain_root_path/domains/$subdomain.$domain/odoo/config/odoo.conf" |
| 126 | +[options] |
| 127 | +addons_path = /usr/lib/python3/dist-packages/odoo/addons,/mnt/extra-addons |
| 128 | +data_dir = /var/lib/odoo |
| 129 | +admin_passwd = $odoo_master_password |
| 130 | +db_host = $database_host |
| 131 | +db_port = $database_port |
| 132 | +db_name = $database_name |
| 133 | +db_user = $database_username |
| 134 | +db_password = $database_password |
| 135 | +proxy_mode = True |
| 136 | +workers = $odoo_workers |
| 137 | +gevent_port = 8072 |
| 138 | +limit_memory_hard = 2684354560 |
| 139 | +limit_memory_soft = 2147483648 |
| 140 | +limit_request = 8192 |
| 141 | +limit_time_cpu = 600 |
| 142 | +limit_time_real = 1200 |
| 143 | +max_cron_threads = 1 |
| 144 | +without_demo = all |
| 145 | +
|
| 146 | +EOF |
| 147 | +``` |
| 148 | + |
| 149 | +```.sh |
| 150 | +# Get Odoo container UID/GID |
| 151 | +odoo_uid=$(docker run --rm odoo:$odoo_version id -u) |
| 152 | +odoo_gid=$(docker run --rm odoo:$odoo_version id -g) |
| 153 | +echo "Odoo UID: $odoo_uid, GID: $odoo_gid" |
| 154 | + |
| 155 | +# Change ownership |
| 156 | +sudo chown -R $odoo_uid:$odoo_gid "$domain_root_path/domains/$subdomain.$domain/odoo/data" |
| 157 | + |
| 158 | +# Get PostgreSQL container UID |
| 159 | +postgres_uid=$(docker run --rm postgres:16 id -u) |
| 160 | +postgres_gid=$(docker run --rm postgres:16 id -g) |
| 161 | +echo "Postgres UID: $postgres_uid, GID: $postgres_gid" |
| 162 | + |
| 163 | +# Change ownership |
| 164 | +sudo chown -R $postgres_uid:$postgres_gid "$domain_root_path/domains/$subdomain.$domain/odoo/postgres" |
| 165 | +``` |
| 166 | + |
| 167 | +```.sh |
| 168 | +# Initialize Odoo database with core modules |
| 169 | +cd $domain_root_path/domains/$subdomain.$domain/odoo |
| 170 | + |
| 171 | +docker compose run --rm odoo odoo \ |
| 172 | + --config /etc/odoo/odoo.conf \ |
| 173 | + --init base,web,account,contacts,delivery,product,sale_management,stock,stock_account \ |
| 174 | + --stop-after-init |
| 175 | +``` |
| 176 | + |
| 177 | +```.sh |
| 178 | +# Start containers |
| 179 | +cd $domain_root_path/domains/$subdomain.$domain/odoo |
| 180 | +docker compose up -d |
| 181 | +``` |
| 182 | + |
| 183 | +```.sh |
| 184 | +# Confirm docker is running |
| 185 | +docker ps |
| 186 | +``` |
| 187 | + |
| 188 | +```.sh |
| 189 | +# View logs |
| 190 | +# docker logs odoo_server_${system_user} |
| 191 | +# docker logs odoo_postgres_${system_user} |
| 192 | +``` |
| 193 | + |
| 194 | +### Nginx directives |
| 195 | + |
| 196 | +```.txt |
| 197 | +server { |
| 198 | + client_max_body_size 512M; |
| 199 | + proxy_buffering off; |
| 200 | +
|
| 201 | + location / { |
| 202 | + proxy_pass http://127.0.0.1:8069; |
| 203 | + proxy_set_header Host $host; |
| 204 | + proxy_set_header X-Real-IP $remote_addr; |
| 205 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 206 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 207 | + proxy_read_timeout 720s; |
| 208 | + proxy_connect_timeout 720s; |
| 209 | + proxy_send_timeout 720s; |
| 210 | + } |
| 211 | +
|
| 212 | + location /longpolling { |
| 213 | + proxy_pass http://127.0.0.1:8072; |
| 214 | + proxy_set_header Host $host; |
| 215 | + proxy_set_header X-Real-IP $remote_addr; |
| 216 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 217 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 218 | + } |
| 219 | +
|
| 220 | + location /websocket { |
| 221 | + proxy_pass http://127.0.0.1:8072; |
| 222 | + proxy_set_header Host $host; |
| 223 | + proxy_set_header X-Real-IP $remote_addr; |
| 224 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 225 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 226 | + proxy_set_header Upgrade $http_upgrade; |
| 227 | + proxy_set_header Connection "upgrade"; |
| 228 | + } |
| 229 | +} |
| 230 | +``` |
| 231 | + |
| 232 | +```.sh |
| 233 | +# Restart Nginx |
| 234 | +sudo systemctl reload nginx |
| 235 | +``` |
| 236 | + |
| 237 | +### Useful Commands |
| 238 | + |
| 239 | +```.sh |
| 240 | +# Stop containers |
| 241 | +# cd $domain_root_path/domains/$subdomain.$domain/odoo |
| 242 | +# docker compose down |
| 243 | + |
| 244 | +# Update Odoo to latest patch |
| 245 | +# docker compose pull |
| 246 | +# docker compose up -d |
| 247 | + |
| 248 | +# Access Odoo shell |
| 249 | +# docker exec -it odoo_server_${system_user} odoo shell -d $database_name |
| 250 | + |
| 251 | +# Backup database |
| 252 | +# docker exec odoo_postgres_${system_user} pg_dump -U $database_username $database_name > backup.sql |
| 253 | +``` |
| 254 | + |
| 255 | +## Uninstall |
| 256 | + |
| 257 | +```.sh |
| 258 | +# cd $domain_root_path/domains/$subdomain.$domain/odoo |
| 259 | + |
| 260 | +# Stop and remove containers + volumes |
| 261 | +# docker compose down -v |
| 262 | + |
| 263 | +# Remove all data |
| 264 | +# sudo rm -rf $domain_root_path/domains/$subdomain.$domain/odoo |
| 265 | + |
| 266 | +# Confirm docker is not running |
| 267 | +docker ps |
| 268 | +``` |
0 commit comments