First of all, lazarus packages a lot of build logic within it's projects, so to use a package, you need an LPI (lazarus project file) containing the reference to said package. This can then be read by a lazarus instance and if alle the packages are installed, lazarus will call the correct compiler commands (by looking at the build instructions for the package in the lpk and the instructions for the project in the lpi) to build it.
This building is available via the command line tool lazbuiild already shipped (and built) with lazarus. Simply call "lazbuild path/to/lpi". Lazbuild can also install lpk files, what it can't do is search the online package manager and install packages.
For this I wrote a small script a few years ago:
https://github.com/Warfley/LazarusPackageManagerThis does both give a command line interface for downloading and installing packages into lazarus using lazbuild, while also providing a neat wrapper for building lpis where lpm will read the lpi, detect if any packages from OPM are missing and if so it can download and install them.
Using the docker container it works like that (Using an example project I've built for this some time ago):
$> git clone https://gitlab.com/Warfley/lazarusgitlabci testproject
$> docker run --rm -v $(realpath testproject):/project lpm:stable lpm build --yes project/FileEncrypter.lpi Windows QTLinux GTKLinux
What this does it creates a new LPM docker container (which is pre packaged with fpc and lazarus and lpm), mounts the project into it, and then compiles the projects build targets Windows, QTLinux, and GTKLinux (see the pdf in the repository on what these build modes are and how they where created).
The project uses the DCPCrypt package which lpm (with --yes) will automatically download from OPM before compiling.
After the container finished, there will be a build folder in the project directory containing the compiled executables.
But of course this is only for existing lazarus projects, you still need lazarus for creating and managing the project and settings in the lpi project file