1

As the title says, I'm having trouble using argon2 when I'm running Docker on my Windows 10 machine.

Dockerfile:

FROM node:16.13.1

WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .

CMD npm start

.dockerignore:

.git
docker-compose.yml
.env.example
.gitlab-ci.yml
Makefile
.vscode
tmp
_Production

# Log files
npm-debug.log*

# Dependency directories
node_modules
/node_modules
npm-debug.log

# Coverage files
coverage
.nyc_output

# Documentation files
/docs
README.md

Example.ts:

import { Request, Response } from "express";
import { getRepository } from "typeorm";
import { User } from "../entity/user.entity";
import * as argon2 from "argon2";

export const Register = async (req: Request, res: Response) => {
  const { body } = req as any;

  if (body.password !== body.password_confirm) {
    return res.status(400).send({
      message: "Passwords do not match",
    });
  }

  const user = await getRepository(User).save({
    email: body.email,
    password: await argon2.hash(body.password),
  });

  return res.status(201).send(user);
};

docker-compose.yaml

version: '20.10.13'
services:
  backend:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/app
    depends_on:
      - db

  db:
    image: mysql:8
    restart: always
    environment:
      MYSQL_DATABASE: ambassador
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - .dbdata:/var/lib/mysql
    ports:
      - "33066:3306"

As you can see I already exclude node_modules in the .dockerignore. Help is appreciated.

Starfish
  • 3,344
  • 1
  • 19
  • 47
  • How are you launching the container? If you have Compose `volumes:` or a `docker run -v` option that replaces everything in the image with content mounted from the host, does deleting this option help? – David Maze Mar 24 '22 at 17:10
  • Can you share your folder structure? If node_modules is in the subfolder then try to include `**/node_modules/` in the .dockerignore – David Mar 24 '22 at 17:21
  • Does this answer your question? ["invalid ELF header" when using the nodejs "ref" module on AWS Lambda](https://stackoverflow.com/questions/29994411/invalid-elf-header-when-using-the-nodejs-ref-module-on-aws-lambda) – SiKing Mar 24 '22 at 17:47
  • @David The `node_modules` and `.dockerignore` are at the same level. It might have to do with the comment @SiKing provided, but I'm not sure how to do/approach this. @David Maze I'm running `docker compose up`. I've updated the OP with my `docker-compose.yaml` – Starfish Mar 24 '22 at 18:20

0 Answers0