I recently asked the best way to run my Lemmy bot on my Synology NAS and most people suggested Docker.
I'm currently trying to get it running on my machine in Docker before transferring it over there, but am running into trouble.
Currently, to run locally, I navigate to the folder and type npm start
. That executes tsx src/main.ts
.
The first thing main.ts
does is access argv to detect if a third argument was given, dev
, and if it was, it loads in .env.development
, otherwise it loads .env
, containing environment variables. It puts those variables into a local variable that I then pass around in the bot. I am definitely not tied to this approach if there is a better practice way of doing it.
opening lines of main.ts
import { config } from 'dotenv';
let path: string;
const env = process.argv[2];
if (env && env === 'dev') {
path = '.env.development';
} else {
path = '.env';
}
config({
override: true,
path
});
const {
ENVIROMENT_VARIABLE_1
} = process.env as Record<string, string>;
Ideally, I would like a way that I can create a Docker image and then run it with either the .env.development
variables or the .env
ones...maybe even a completely separate one I decide to create after-the-fact.
Right now, I can't even run it. When I type docker-compose up
I get npm start: not found
.
My Dockerfile
FROM node:22
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
USER node
COPY . .
CMD "npm start"
My compose.yaml
services:
node:
build: .
image: an-image-name:latest
environment:
- ENVIROMENT_VARIABLE_1 = ${ENVIROMENT_VARIABLE_1}
I assume the current problem is something to do with where stuff is being copied to and what the workdir is, but don't know precisely how to address it.
And once that's resolved, I have even less idea how to go about passing through the environment variables.
Any help would be much appreciated.