Nevermind, I misremembered, been a while since I last set up docker networks
Are you looking for:
let
projectPath = builtins.toPath "/home/redhawk/code/Bongo-Bot";
in
{
virtualisation.oci-containers.containers = {
bongo-bot = {
image = "ghcr.io/redhawk18/bongo-bot:latest";
dependsOn = [ "lavalink" ];
environmentFiles = [ "${projectPath}/.env" ];
volumes = [ "${projectPath}/bongo.sqlite:/app/bongo.sqlite" ];
};
lavalink = {
image = "ghcr.io/lavalink-devs/lavalink:3-alpine";
ports = [ "2333:2333" ];
volumes = [
"${projectPath}/application.yml:/opt/Lavalink/application.yml"
];
extraOptions = [
"--hostname" "lavalink"
];
};
};
}
The simplest way for two containers like this is to link them: Legacy container links | Docker Docs
I suspect in theory connecting to localhost
instead could work too, assuming all communication happens over port 2333
, but I’m less sure of that.
A more idiomatic solution is to create a docker network for these two containers, at which point lavalink
will already be known as lavalink
on that network, as that’s the container name, and you wouldn’t need to specify anything else.
This is somewhat tedious to configure on NixOS though, because of annoying limitations of how docker does networking.
To do so, you will need to create a oneshot systemd service that lingers and runs e.g. docker network create discord-bot
, and then add a --network=discord-bot
to the extraOptions
of your containers. You’ll also need to add a dependency (something like this + after, to the systemd service of the containers, not the containers) to depend on the creation of that network.
I think you can also directly write a JSON file somewhere, which someone showed off last time I complained about this mess, but that’s clearly not endorsed by docker.
Technically you can also just create the network once from the command line, but that’s imperative and will mean your config can’t easily move from this system. There’s a reason I stopped using docker.
Podman pods are much nicer, but also not properly supported by the NixOS module, probably because nobody wants to break the docker/podman compatibility and because of the relative lack of maintenance of this module in general. Systemd sandboxing is just better. You can always use podman pods (or docker-compose, which does similar things with a warning not to use it in production) without the NixOS module system, of course…
Or I could give you my three-year-old pod module, but now we’re shaving yaks to shave yaks.