I got this docker-compose file:
version: "3.3"
services:
api:
restart: always
build:
context: .
image: foo-platform:1.0.0.0
env_file: docker-compose-test.env
environment:
SERVICES: api,$node,foo-service
labels:
- "traefik.enable=false"
- "traefik.http.routers.api-gw.rule=PathPrefix(`/`)"
- "traefik.http.services.api-gw.loadbalancer.server.port=8090"
networks:
- internal
volumes:
- logdata:/logs/moleculer
ports:
- "5680:5680"
- "5683:5683"
- "5684:5684"
- "5685:5685"
- "5686:5686"
networks:
internal:
volumes:
logdata:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/var/log/tdcp'
I got this moleculer file config:
const brokerConfig: BrokerOptions = {
// Namespace of nodes to segment your nodes on the same network.
namespace: process.env.NAMESPACE,
// Unique node identifier. Must be unique in a namespace.
nodeID: null,
// Custom metadata store. Store here what you want. Accessing: `this.broker.metadata`
metadata: {},
// Enable/disable logging or use custom logger. More info: https://moleculer.services/docs/0.14/logging.html
// Available logger types: "Console", "File", "Pino", "Winston", "Bunyan", "debug", "Log4js", "Datadog"
logger: [
//{
// type: "Console",
// options: {
// level: "info",
// }
//},
{
type: "File",
options: {
level: "info",
folder: "/logs/moleculer",
filename: "log-{date}.log",
formatter: "{timestamp} {level} {nodeID}/{mod}: {msg}"
}
},
],
...
When I launch the moleculer runner with visual code or using node directly in the system, the "this.logger" object works perfectly, it does not use the console log and uses only the file log. But when I use this with docker, the process uses console log when my config file says that does wat console, and no file is write inside the docker execution.
This is my Dockfile.
The rest of the properties of the moleculer file works perfectly (and yes, the application uses that moleculer config file).
FROM node:lts-alpine
# Working directory
WORKDIR /app
# Install dependencies
COPY package.json package-lock.json ./
RUN npm ci --silent
# Copy source
COPY . .
# Build and cleanup
ENV NODE_ENV=production
RUN npm run build \
&& npm prune \
&& mkdir -p /logs/moleculer \
&& touch /logs/moleculer/this_is_a_volumen
# Start server
CMD ["node", "./node_modules/moleculer/bin/moleculer-runner.js"]