This guide will allow you to rapidly build a ready-to-use development environment for Product Opener running in Docker.
As an alternative to setting up your environment locally, follow the Gitpod how-to guide
to instantly provision a ready-to-code development environment in the cloud.
First setup time estimate is 10-30min with the following recommended specs:
Docker is the easiest way to install the Open Food Facts server, play with it, and even modify the code.
Docker provides an isolated environment, very close to a Virtual Machine. This environment contains everything required to launch the Open Food Facts server. There is no need to install Perl, Perl modules, Nginx, or Apache separately.
Ensure a supported version of Docker Compose V2 is installed and registered as a Docker CLI plugin. Note that Product Opener commands invoke Docker Compose through the Docker CLI plugin (docker compose with a space), rather than invoking a standalone docker-compose executable directly.
Verify your installation by running:
docker compose version
If you run e.g. Debian or Ubuntu, don't forget to add your user to the docker group and ensure the docker-compose-plugin package is installed alongside Docker Engine.
On macOS, the default version of grep is BSD grep, which does not support certain GNU-specific options—most notably, the -P flag for Perl-compatible regular expressions. If you encounter errors like:
MacOS Prerequisites: Installing GNU grep for Full Regex Support
This ensures that the GNU version (often available as ggrep) is used by default instead of BSD grep.
Apply the Changes:
Restart your terminal or run:
source ~/.zshrc
Verify Installed Version:
Run the following command to ensure that GNU grep is installed and properly configured:
MacOS Prerequisites: Installing GNU grep for Full Regex Support
grep --version
You should see an output similar to the example below, indicating that GNU grep (with Homebrew packaging) is active and supports the -P option via PCRE2:
MacOS Prerequisites: Installing GNU grep for Full Regex Support
grep (GNU grep) 3.11Packaged by HomebrewCopyright (C) 2023 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.Written by Mike Haertel and others; see<https://git.savannah.gnu.org/cgit/grep.git/tree/AUTHORS>.grep -P uses PCRE2 10.44 2024-06-07
After completing these steps, running grep commands (for example, as part of make log) will use GNU grep with full support for options like -P.
When running with Windows, install Docker Desktopwhich will cover all of the above.
The Make tasks use a number of Linux commands, such as rm and nproc, so it is recommended to run Make commands from the Git Bash shell. In addition, the following need to be installed and included in the PATH:
wget for windows (In order to download the full product database). If you want to download wget with the executable, copy the wget.exe file to C:/Windows/System32 and you are done.
The process of cloning the repository will create a number of symbolic links which require specific permissions under Windows. In order to do this you can use any one of these alternatives:
Use an Administrative command prompt for all Git commands
Ensure that you have WSL installed on your Windows machine. For instructions on how to do so, you can follow Microsoft's guide to install WSL.
After successfully installing WSL, you need to set up your Linux distribution and install Docker on it:
Go to the Microsoft Store and install Ubuntu as your Linux distribution
Open Ubuntu and execute the commands/instructions specified in Installing Docker Engine on Ubuntu (**NOTE: this is NOT the same thing as Docker for Desktop)
Restart your computer to ensure all changes take effect and WSL can properly integrate with Docker
If you're on macOS and run into "missing taxonomy files" errors when running make dev, the culprit is usually Docker's file sharing being a bit slow. Switching to VirtioFS fixes this:
Open Docker Desktop and go to Settings (the gear icon)
Head to Resources → File Sharing
Select VirtioFS under "Virtual file shares"
Hit Apply & Restart
VirtioFS is way faster than the default and should sort out any timing issues. You'll need macOS 12.5 or later for this to work.
Still having trouble? Try bumping up Docker's resources—6-8 GB of memory and 4+ CPU cores usually does the trick.
You must have a GitHub account and fork the project if you want to contribute to Open Food Facts development, but it’s not required if you just want to see how it works.
Cloning Open Food Facts server with the default options downloads 2.23 GiB (as of 2024-03). See Shallow Clone if this might be a problem for you.
This is the url you have to use in the following instructions.
Very important: always work in new branches, never in "main", otherwise it will be difficult
to sync your project with the upstream repository (the openfoodfacts original repository).
From time to time (before starting a new branch), it's a good idea to sync your fork,
either using the github interface and then pulling "main" locally, or from the command line.
If you are running Docker on Windows, please use the following git clone command:
Clone
# replace my-user-id with your user id if you forked the repository, otherwise use openfoodfactsgit clone -c core.symlinks=true https://github.com/my-user-id/openfoodfacts-server.git
or (if you want to use ssh)
# replace my-user-id with your user id if you forked the repository, otherwise use openfoodfactsgit clone -c core.symlinks=true git@github.com:my-user-id/openfoodfacts-server.git
# replace my-user-id with your user id if you forked the repository, otherwise use openfoodfactsgit clone git@github.com:my-user-id/openfoodfacts-server.git
or
# replace my-user-id with your user id if you forked the repository, otherwise use openfoodfactsgit clone https://github.com/my-user-id/openfoodfacts-server.git
A full clone of the openfoodfacts-server repository can consume a significant amount of your PC's resources. It will download over 2 GiB of data and take up over 3 GiB of drive space.
To save your PC's resources, consider using a shallow clone by only cloning the main branch combined with a shallow fetch. This reduces the downloaded data to approximately 333 MiB and the repo will only use around 350 MiB of drive space.
You will still be able to contribute PRs based on the main branch. However, you will not be able to view the full Git version history of any files, and you need to use an additional branch from GitHub, e.g., gh-pages, you can do it like this:
Note: you can skip this step for the first setup since the default .env in the repo contains all the default values required to get started.
Before running the docker compose deployment, you can review and configure
Product Opener's environment (.env file).
.env is tracked by git. Editing it works, but it then shows up in
git status and risks being committed by accident. Prefer putting your
overrides in .envrc, which is git-ignored — see the note at the end of this
section.
The .env file contains ProductOpener default settings:
Field
Description
PRODUCT_OPENER_DOMAIN
Can be set to different values based on which OFF flavor is run.
PRODUCT_OPENER_PORT
can be modified to run NGINX on a different port. Useful when running multiple OFF flavors on different ports on the same host. Default port: 80.
PRODUCT_OPENER_FLAVOR
Can be modified to run different flavors of OpenFoodFacts, amongst openfoodfacts (default), openbeautyfacts, openpetfoodfacts, openproductsfacts.
PRODUCT_OPENER_FLAVOR_SHORT
can be modified to run different flavors of OpenFoodFacts, amongst off (default), obf, oppf, opf.
PRODUCERS_PLATFORM
can be set to 1 to build / run the producer platform.
ROBOTOFF_URL
can be set to connect with a Robotoff instance.
QUERY_URL
can be set to connect with a Query instance.
REDIS_URL
can be set to connect with a Redis instance for populating the search index.
GOOGLE_CLOUD_VISION_API_KEY
can be set to enable OCR using Google Cloud Vision.
CROWDIN_PROJECT_IDENTIFIER and CROWDIN_PROJECT_KEY
can be set to run translations.
GEOLITE2_PATH, GEOLITE2_ACCOUNT_ID and GEOLITE2_LICENSE_KEY
can be set to enable Geolite2.
TAG
Is set to latest by default, but you can specify any Docker Hub tag for the frontend / backendimages. Note that this is useful only if you use pre-built images from the Docker Hub (docker/prod.yml override); the default dev setup (docker/dev.yml) builds images locally
The .env file also contains some useful Docker Compose variables:
COMPOSE_PROJECT_NAME is the compose project name that sets the prefix to every container name. Do not update this unless you know what you're doing.
If you work in several git worktrees on the same machine, make agent sets this (and the network, volume, image and port names) for you: see How to run several worktrees on one machine.
COMPOSE_FILE is the ;-separated list of Docker compose files that are included in the deployment:
For a development-like environment, set it to docker-compose.yml;docker/dev.yml (default)
For a production-like environment, set it to docker-compose.yml;docker/prod.yml;docker/mongodb.yml
For more features, you can add:
docker/admin-uis.yml: add the Admin UIS container
docker/geolite2.yml: add the Geolite2 container
docker/perldb.yml: add the Perl debugger container
COMPOSE_SEPARATOR is the separator used for COMPOSE_FILE.
Note:
Instead of modifying .env (and risk committing it inadvertently),
you can also set needed variables in your shell; they will override .env values.
This applies to docker compose commands, but not to make: the Makefile
includes .env itself, and a makefile assignment always wins over an inherited
environment variable. Use .envrc for overrides that must apply to make.
Consider creating a .envrc file that you source each time you need to work on the project.
On linux and macOS, you can automatically do it if you use direnv.
Working in a git worktree, or sharing this machine with another agent?
Run make agent once, before make dev. It gives the worktree its own
container, network, volume and image names, its own domain and its own host
port, so several worktrees can run make dev side by side instead of fighting
over port 80 and over Docker DNS names such as backend. It takes no arguments:
make agent # prints the URL it settled on, e.g. http://world.w11790.openfoodfacts.localhost:8081/
Re-running it reuses the same id and port, so your URL stays stable. Use
make list-agents to see the other worktrees on the machine, and
make release-agent to undo. See
How to run several worktrees on one machine.
By default, GNU make runs one recipe at a time, sequentially. You may choose to run make dev with multiple jobs in parallel to speed up the build process, particularly operations that involve many network calls (such as building dependencies and downloading assets). Use either:
Parallel execution with make
make dev --jobs=32
or set the MAKEFLAGS environment variable before running make dev:
Parallel execution with make
export MAKEFLAGS=--jobs=32make dev
Choosing a higher job count than the number of CPU cores is safe for Product Opener because most of the time the tasks are network-bound rather than CPU-bound. A good starting point is 2-4 times your CPU core count, but monitor system performance and adjust accordingly to match your available bandwidth and system responsiveness.
Note:
If you are using Windows, you may encounter issues regarding this command. Take a look at the Troubleshooting section further in this tutorial.
Note:
If docker complains about
ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network
It can be solved by adding {"base": "172.80.0.0/16","size": 24}, {"base": "172.90.0.0/16","size": 24} to default-address-pools in /etc/docker/daemon.json and then restarting the docker daemon.
Credits to https://theorangeone.net/posts/increase-docker-ip-space/ for this solution.
The command will run 2 subcommands:
make up: Build and run containers from the local directory and bind local code files, so that you do not have to rebuild everytime.
make import_sample_data: Load sample data into mongodb container (~100 products).
Notes:
The first build can take between 10 and 30 minutes depending on your machine and internet connection (broadband connection heavily recommended, as this will download Docker base images, install Debian and Perl modules in preparation of the final container image).
Note: see the "Parallel execution with make" section above for guidance on running make dev with multiple jobs in parallel.
You might not immediately see the test products: create an account, login, and they should appear.
After editing a Perl module, restart the backend container or your change
will not take effect:
make restart_backend
Your code is bind-mounted into the container, so files are saved immediately,
but mod_perl keeps the previously loaded module in memory and only reloads it on
a restart. Frontend changes under scss/ and html/js/ do not need this.
The default PRODUCT_OPENER_DOMAIN in .env is openfoodfacts.localhost, and
current Linux, macOS and Windows resolve *.localhost to 127.0.0.1 on their own
(RFC 6761), so most browsers need no hosts file entry at all. It is also
unnecessary when the containers run under WSL2 and you browse from Windows.
Only if you actually hit name-resolution errors, add the following to your hosts
file (Linux/macOS: /etc/hosts; Windows:
C:\Windows\System32\drivers\etc\hosts):
Or let the Makefile append it for you, idempotently:
Parallel execution with make
make edit_etc_hosts
Do not edit system files unless you actually hit this error. Tools that do not
special-case *.localhost (curl, wget, some resolvers) may still need the
entry.
After registering, Keycloak will ask you to verify your email address. In the local development environment, emails are not sent to real email addresses. Instead, they're captured by a local email server.
To verify your email:
Open http://localhost:5605/ in your browser (SMTP4Dev interface)
You'll see your verification email with subject "Verify email"
Click on the email to open it
Click the verification link inside the email
Your account will be activated!
This step is required locally and is not a bug: until you click the link the
account stays inactive and cannot log in.
WARNING: Devcontainer support is currently experimental. It's recommended to run the normal docker commands before, and stop the containers: make dev down. Note that make dev, make test, and so on may currently conflict with the devcontainer.
This repository comes with a configuration for Visual Studio Code (VS Code) development containers (devcontainer). This enables some Perl support in VS Code without the need to install the correct Perl version and modules on your local machine.
Solution (if using Windows):
Click the Windows button, then type “environment properties” into the search bar and hit Enter. Click Environment Variables, then under System variables choose Path and click Edit. Click New and insert C:\Program Files (x86)\GnuWin32\bin, then save the changes. Open a new terminal and test that the command works.
(See Make Windows for more.)
Solution (if using a Linux distro):
Check that your bash PATH setting is correct. If it is, your Linux distro doesn't include make by default. For Debian (which I had that problem with --Pau Amma), use
make dev error: make: command not found
sudo apt-get install make
For other distros, consult your distro's documentation or support resources for the command to use.
make dev error: [build_lang] Error 2 - Could not load taxonomy: /mnt/podata/taxonomies/traces.result.json
<h1>Software error:</h1><pre>Could not load taxonomy: /mnt/podata/taxonomies/traces.result.json at /opt/product-opener/lib/ProductOpener/Tags.pm line 1976.Compilation failed in require at /opt/product-opener/scripts/build_lang.pl line 31, <DATA> line 2104.BEGIN failed--compilation aborted at /opt/product-opener/scripts/build_lang.pl line 31, <DATA> line 2104.</pre><p>For help, please send mail to this site's webmaster, giving this error messageand the time and date of the error.</p>[Tue Apr 5 19:36:40 2022] build_lang.pl: Could not load taxonomy: /mnt/podata/taxonomies/traces.result.json at /opt/product-opener/lib/ProductOpener/Tags.pm line 1976.[Tue Apr 5 19:36:40 2022] build_lang.pl: Compilation failed in require at /opt/product-opener/scripts/build_lang.pl line 31, <DATA> line 2104.[Tue Apr 5 19:36:40 2022] build_lang.pl: BEGIN failed--compilation aborted at /opt/product-opener/scripts/build_lang.pl line 31, <DATA> line 2104.make: *** [build_lang] Error 2
Solution:
Project needs Symlinks to be enabled.
traces.result.json is a symlink to allergens.result.json
You have to enable the 'Developer Mode' in order to use the symlinks.
To enable Developer Mode:
on windows 10: Settings > Update & Security > 'For developers' …
on windows 11: Settings > Privacy & Security > 'For developers' …
and turn on the toggle for Developer Mode.
On Windows systems, the git repository needs to be cloned with symlinks enabled.
You need to remove the directory where you cloned the project, and clone the project again, using the right options:
make dev error: [build_lang] Error 2 - Could not load taxonomy: /mnt/podata/taxonomies/traces.result.json
# replace my-user-id with your user id if you forked the repository, otherwise use openfoodfactsgit clone -c core.symlinks=true git@github.com:my-user-id/openfoodfacts-server.git
process_begin: CreateProcess(NULL, wget --no-verbose https://static.openfoodfacts.org/data/openfoodfacts-mongodbdump.gz, ...) failed.make (e=2): The system cannot find the file specified.
You need to install wget for windows. The referenced version is able to use the Windows Certificate Store, whereas the standard gnuwin32 version will give errors about not being able to verify the server certificate.
<h1>Software error:</h1><pre>MongoDB: :SelectionError: No writable server available. MongoDB server status:Topology type: Single; Member status:mongodb:27017 (type: Unknown, error: MongoDB::NetworkError: Could not connect to 'mongodb:27017': Temporary failure in name resolution )</pre><p>For help, please send mail to this site's webmaster, giving this error messageand the time and date of the error.<p>[Sat Dec 17 19:52:21 2022] update_all_products from_dir_in_mongodb.pl: MongoDB::SelectionError: No writable server available. MongoDB server status:[Sat Dec 17 19:52:21 2022] update_all_products from_dir_in_mongodb.pl: Topology type: Single; Member status:[Sat Dec 17 19:52:21 2022] update_all_products from_dir_in_mongodb.pl: mongodb:27017 (type: Unknown, error: MongoDB::NetworkError: Could not connect to 'mongodb:27017': Temporary failure in name resolution )make: *** [Makefile:154: import_sample_data] Error 22
Solution:
The cause of this issue is that you already have the mongodb database server running on your local machine at port 27017.
make dev error: [build_lang] Error 13 - can't write into /mnt/podata/data/Lang.openfoodfacts.localhost.sto
<h1>Software error:</h1><pre>can't write into /mnt/podata/data/Lang.openfoodfacts.localhost.sto: Permission denied at /opt/product-opener/lib/ProductOpener/Store.pm line 234.</pre><p>For help, please send mail to this site's webmaster, giving this error messageand the time and date of the error.</p>make: *** [Makefile:126: build_lang] Error 13
Solution:
Use the powershell/cmd to run the make dev commands in windows.
COMPOSE_FILE="docker-compose.yml;docker/dev.yml" docker compose --env-file=.env buildunknown flag: --env-fileUsage: docker [OPTIONS] COMMAND [ARG...]Run 'docker --help' for more information
Reason:
The banner Usage: docker [OPTIONS] COMMAND [ARG...] indicates that the root Docker CLI handled the flag rather than Docker Compose. This occurs when Docker CLI cannot dispatch compose to the Compose CLI plugin, such as when:
The Docker Compose CLI plugin (docker-compose-plugin) is not installed.
The Docker Compose CLI plugin is installed, but is not discoverable in standard Docker CLI plugin directories.
A standalone docker-compose executable is present in PATH, but the Docker Compose CLI plugin (accessible through docker compose) is not installed or registered with the Docker CLI.
Note for Linux distributions (e.g. Arch Linux, Debian, Ubuntu): Docker Engine and Docker Compose are often packaged separately (such as docker and docker-compose on Arch Linux, or docker-ce and docker-compose-plugin on Debian/Ubuntu). Installing Docker Engine alone does not automatically install Docker Compose.
Compatibility Note: Once the Docker Compose CLI plugin is installed and discoverable, ensure your installed Compose version supports the global --env-file option by verifying docker compose --help.
Diagnostic steps & Solution:
Check your installed Docker Compose plugin:
docker compose version
If this command produces either of the following errors:
docker: unknown command: docker composedocker: 'compose' is not a docker command.
the Docker Compose CLI plugin may either be missing or not registered in your Docker plugins directory.
Verify that --env-file is supported by your Docker Compose installation:
docker compose --help
Look for --env-file under the listed options.
On Arch Linux, verify that both packages are installed:
pacman -Q docker docker-compose
If docker-compose is missing, install it with:
sudo pacman -S docker-compose
For other Linux distributions, macOS, or Windows, install or upgrade Docker Compose following the official documentation: