When running the step RUN yarn install in a Dockerfile during docker-compose build command, I get:
[1/4] Resolving packages... [2/4] Fetching packages... info [email protected]: The platform "linux" is incompatible with this module. info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697". warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0". warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0". [4/4] Building fresh packages...
but the node_modules folder is NOT created. On the other hand when I run
docker-compose run SERVICE_NAME yarn install
I get:
[1/4] Resolving packages... [2/4] Fetching packages... info [email protected]: The platform "linux" is incompatible with this module. info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697". warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0". warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0". [4/4] Building fresh packages...
but then the folder node_modules IT IS created in the project folder.
I just don't understand why ... I'm expecting same functionality but I'm missing something.
Here my docker-compose service
services:
ruby:
build:
context: .
dockerfile: docker/ruby/Dockerfile
networks:
- some-network
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- mysql
command: bundle exec rails s -p 3000 -b '0.0.0.0'
Dockerfile
FROM ruby:2.5
# Install dependencies:
# - build-essential: To ensure certain gems can be compiled
# - nodejs: Compile assets
# - npm: Install node modules
# - yarn: Install & manage node modules [should make npm obsolete]
# - libpq-dev
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -qq -y build-essential nodejs yarn \
libpq-dev \
mysql-client
RUN mkdir /app
COPY . /app
WORKDIR /app
# install node dependencies
RUN yarn install
RUN bundle install
At first creates an image depending on Dockerfile:
ruby:2.5
to create new image from it/app
/app
pathyarn
and bundle
(call methods inside image)And after that "mounts" your projects folder to image's /app
folder, so it becomes same as your system root folder. After that "generates" container and executes CMD
command from Docker file (if exists).
Take an account that this is not detailed explanation of image/container generation flow, but hope it can help you to solve your problem. So you can
yarn install
in your system, or create entrypoint script with installation commands: entrypoint: ./entrypoint.sh
EXAMPLE OF FILES
If you want to update your source files "on fly" (to see updates without rebuilding container), you must use second way.
Create file run.sh in your project directory:
run.sh
#!/bin/sh
echo '--- run yarn install'
yarn install
echo '--- run bundle install'
bundle install
# HERE YOU CAN RUN ANY OTHER SCRIPT BEFORE CONTAINER BUILDING
echo '--- create docker image and up it'
sudo docker-compose up -d --build
docker-compose.yml
No need to change (keep like in your question).
Dockerfile
FROM ruby:2.5
# Install dependencies:
# - build-essential: To ensure certain gems can be compiled
# - nodejs: Compile assets
# - npm: Install node modules
# - yarn: Install & manage node modules [should make npm obsolete]
# - libpq-dev
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -qq -y build-essential nodejs yarn \
libpq-dev \
mysql-client
WORKDIR /app
To build and up container just run command: sh run.sh
It will install node dependencies in your system, after that will create container, which /app
folder will be your project folder (in your system), so your code changes will take an effect immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With