R
Railwayā€¢11mo ago
igli

DockerFile fails to install packages with yarn install and doesn't generate node_modules

This is my DockerFile
# Build stage
FROM node:18 as builder
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install
COPY . .
RUN yarn build

# Runtime stage
FROM node:18
WORKDIR /app
COPY --from=builder /app .
RUN apt-get update && apt-get install -y libicu-dev
EXPOSE 3000
CMD ["node", "dist/src/server.js"]
# Build stage
FROM node:18 as builder
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install
COPY . .
RUN yarn build

# Runtime stage
FROM node:18
WORKDIR /app
COPY --from=builder /app .
RUN apt-get update && apt-get install -y libicu-dev
EXPOSE 3000
CMD ["node", "dist/src/server.js"]
Also how can I run the DockerFile with no cache?
No description
19 Replies
Percy
Percyā€¢11mo ago
Project ID: 80aa096c-5a05-4e03-9772-a48238f8ffa9
igli
igliā€¢11mo ago
80aa096c-5a05-4e03-9772-a48238f8ffa9 I need to install ICU library that's the only reason why I'm using DockerFile
Brody
Brodyā€¢11mo ago
you have a multi stage dockerfile but you aren't copying the node_modules from the first stage into the second stage, I'd recommend for simplicity, do a single stage dockerfile, or at least get a single stage dockerfile working before you worry worry about optimizations like that
igli
igliā€¢11mo ago
Hey Bordy thanks for replying. This was my initial DockerFile
# Use an official Node.js runtime as a parent image
FROM node:18

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /usr/src/app
COPY package.json .
COPY yarn.lock .

# Install any needed packages specified in package.json
RUN yarn install

# Copy applicaiton code
COPY . .

RUN yarn build

# Install ICU library (example for a Debian-based image)
RUN apt-get update && apt-get install -y libicu-dev

# Make port available to the world outside this container
EXPOSE 3000

# Run the app when the container launches
CMD ["node", "dist/src/server.js"]
# Use an official Node.js runtime as a parent image
FROM node:18

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /usr/src/app
COPY package.json .
COPY yarn.lock .

# Install any needed packages specified in package.json
RUN yarn install

# Copy applicaiton code
COPY . .

RUN yarn build

# Install ICU library (example for a Debian-based image)
RUN apt-get update && apt-get install -y libicu-dev

# Make port available to the world outside this container
EXPOSE 3000

# Run the app when the container launches
CMD ["node", "dist/src/server.js"]
Brody
Brodyā€¢11mo ago
yes this one looks much better, what where the difficulties you faced with this?
igli
igliā€¢11mo ago
the same error as the screenshot yarn build would fail
#11 [7/8] RUN yarn build



#11 1.582 Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)

#11 1.582

#11 1.582 $ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...



#11 ERROR: process "/bin/sh -c yarn build" did not complete successfully: exit code: 1

-----

> [7/8] RUN yarn build:

1.582 Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)

1.582

1.582 $ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...

-----



Dockerfile:17

-------------------

15 | COPY . .

16 |

17 | >>> RUN yarn build

18 |

19 | # Install ICU library (example for a Debian-based image)

-------------------

ERROR: failed to solve: process "/bin/sh -c yarn build" did not complete successfully: exit code: 1


#11 [7/8] RUN yarn build



#11 1.582 Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)

#11 1.582

#11 1.582 $ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...



#11 ERROR: process "/bin/sh -c yarn build" did not complete successfully: exit code: 1

-----

> [7/8] RUN yarn build:

1.582 Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)

1.582

1.582 $ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...

-----



Dockerfile:17

-------------------

15 | COPY . .

16 |

17 | >>> RUN yarn build

18 |

19 | # Install ICU library (example for a Debian-based image)

-------------------

ERROR: failed to solve: process "/bin/sh -c yarn build" did not complete successfully: exit code: 1


Brody
Brodyā€¢11mo ago
can you send a screenshot of your github repo?
igli
igliā€¢11mo ago
No description
Brody
Brodyā€¢11mo ago
can you build with your dockerfile locally?
igli
igliā€¢11mo ago
yes I had this project deployed to railway before without the DockerFile and everything worked perfectly, I'm only using the DockerFile because I need to install the ICU library if there's a way to install the ICU library without using the DockerFile please let me know
igli
igliā€¢11mo ago
I created a nixpacks.toml >
aptPkgs = ['libicu-dev']
aptPkgs = ['libicu-dev']
Would this do it?
Brody
Brodyā€¢11mo ago
[phases.setup]
aptPkgs = ['...', 'libicu-dev']
[phases.setup]
aptPkgs = ['...', 'libicu-dev']
igli
igliā€¢11mo ago
thank you, I'll try that and I'll let you know I really appreciate the help @Brody
Brody
Brodyā€¢11mo ago
of course šŸ™‚
igli
igliā€¢11mo ago
Hey @Brody the solution worked but it didn't work for my case. I need to install a binary util called "cputil" and it can't be install with apt-get. I'm trying to do with a DockerFile again which looks like this
# Example using Node.js 18
FROM node:18

# Install system dependencies
RUN apt-get update && apt-get install -y \
libicu-dev \
libssl-dev \

# Copy cputil binary into the image
COPY /tools/cputil-linux-x64/cputil /usr/local/bin/cputil

# Make sure cputil is executable
RUN chmod +x /usr/local/bin/cputil

# Set the working directory
WORKDIR /app

# Copy the current directory contents into the container at /usr/src/app
COPY package.json .
COPY yarn.lock .

# Install any needed packages specified in package.json
RUN yarn run install

# Copy applicaiton code
COPY . .

RUN yarn run build

# Make port available to the world outside this container
EXPOSE 3000

# Run the app when the container launches
CMD ["node", "dist/src/server.js"]
# Example using Node.js 18
FROM node:18

# Install system dependencies
RUN apt-get update && apt-get install -y \
libicu-dev \
libssl-dev \

# Copy cputil binary into the image
COPY /tools/cputil-linux-x64/cputil /usr/local/bin/cputil

# Make sure cputil is executable
RUN chmod +x /usr/local/bin/cputil

# Set the working directory
WORKDIR /app

# Copy the current directory contents into the container at /usr/src/app
COPY package.json .
COPY yarn.lock .

# Install any needed packages specified in package.json
RUN yarn run install

# Copy applicaiton code
COPY . .

RUN yarn run build

# Make port available to the world outside this container
EXPOSE 3000

# Run the app when the container launches
CMD ["node", "dist/src/server.js"]
Now when i push to my github, railway starts building but it's not recognizing my DockerFile
[Region: us-west1]

==============

Using Nixpacks

==============


context: 8b1bbaf98b522d31c54bfc4d4cad323e



ā•”ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā• Nixpacks v1.20.0 ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•—

ā•‘ setup ā”‚ nodejs_18, yarn-1_x, openssl ā•‘

ā•‘ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•‘

ā•‘ install ā”‚ npm install -g corepack && corepack enable ā•‘

ā•‘ ā”‚ yarn install --check-cache ā•‘

ā•‘ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•‘

ā•‘ build ā”‚ yarn run build ā•‘

ā•‘ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•‘

ā•‘ start ā”‚ yarn run start ā•‘

ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
[Region: us-west1]

==============

Using Nixpacks

==============


context: 8b1bbaf98b522d31c54bfc4d4cad323e



ā•”ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā• Nixpacks v1.20.0 ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•—

ā•‘ setup ā”‚ nodejs_18, yarn-1_x, openssl ā•‘

ā•‘ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•‘

ā•‘ install ā”‚ npm install -g corepack && corepack enable ā•‘

ā•‘ ā”‚ yarn install --check-cache ā•‘

ā•‘ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•‘

ā•‘ build ā”‚ yarn run build ā•‘

ā•‘ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā•‘

ā•‘ start ā”‚ yarn run start ā•‘

ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
Brody
Brodyā€¢11mo ago
make sure the it's named Dockerfile and in the root of your repo
igli
igliā€¢11mo ago
Hey @Brody I'm running into the same problem as earlier where yarn build command doesn't work "#15 1.262 Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation) #15 1.262 #15 1.262 $ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ... #15 ERROR: process "/bin/sh -c yarn run build" did not complete successfully: exit code: 1 -----" Hey @Brody how does this look to you. I need this cputil to be executable in my server. But when i try to use it in production in my node js server it says that the command doesn't exist
[phases.setup]
aptPkgs = ['...', 'wget', 'libicu-dev', "libssl-dev"]
cmds = [
"wget https://star-m.jp/products/s_print/CloudPRNTSDK/cputil/cputil-linux-x64_v112.tar.gz -O /tmp/cputil.tar.gz",
"tar -xzf /tmp/cputil.tar.gz -C /opt",
"rm /tmp/cputil.tar.gz",
"chmod +x /opt/cputil-linux-x64/cputil",
"export PATH=/opt/cputil-linux-x64:$PATH",
"echo $PATH",
"ls /opt/cputil-linux-x64"
]

[environment]
PATH = "/opt/cputil-linux-x64:$PATH"

[phases.build]
cmds = [
"cputil help"
]
[phases.setup]
aptPkgs = ['...', 'wget', 'libicu-dev', "libssl-dev"]
cmds = [
"wget https://star-m.jp/products/s_print/CloudPRNTSDK/cputil/cputil-linux-x64_v112.tar.gz -O /tmp/cputil.tar.gz",
"tar -xzf /tmp/cputil.tar.gz -C /opt",
"rm /tmp/cputil.tar.gz",
"chmod +x /opt/cputil-linux-x64/cputil",
"export PATH=/opt/cputil-linux-x64:$PATH",
"echo $PATH",
"ls /opt/cputil-linux-x64"
]

[environment]
PATH = "/opt/cputil-linux-x64:$PATH"

[phases.build]
cmds = [
"cputil help"
]
@Brody if you have any ideas, can you please help me. I've been stuck on this for 3 days now
Brody
Brodyā€¢11mo ago
i honestly have no clue, it looks fine to me
Want results from more Discord servers?
Add your server