Docker compose missing yarn dependencies on build - docker-compose

Can't get node_modules folder when running yarn install in the Dockerfile
test-sof
├── docker-compose.yml
├── Dockerfile
├── package.json
└── yarn.lock
docker-compose.yml
version: '3'
services:
web:
build: .
volumes:
- .:/myapp
package.json
{
"name": "site",
"private": true,
"dependencies": {
"#rails/webpacker": "^3.2.1",
"babel-preset-react": "^6.24.1",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"reactjs": "^1.0.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"webpack-dev-server": "^2.11.1"
}
}
Dockferfile
FROM ruby:2.5
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 libpq-dev nodejs yarn
RUN mkdir /myapp
WORKDIR /myapp
ADD ./package.json /myapp/
RUN yarn install
output of the step RUN yarn install when docker-compose build:
Step 6/6 : RUN yarn install
---> Running in 3a0e7095ec81
yarn install v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.1.3: The platform "linux" is incompatible with this module.
info "fsevents#1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "#rails/webpacker > postcss-cssnext#3.1.0" has unmet peer dependency "caniuse-lite#^1.0.30000697".
warning " > webpack-dev-server#2.11.1" has unmet peer dependency "webpack#^2.2.0 || ^3.0.0".
warning "webpack-dev-server > webpack-dev-middleware#1.12.2" has unmet peer dependency "webpack#^1.0.0 || ^2.0.0 || ^3.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 21.11s.
Removing intermediate container 3a0e7095ec81
---> 5720579a0f2a
Successfully built 5720579a0f2a
Successfully tagged testsof_web:latest
Running command: docker-compose run web bash to get in the container
root#11af1818e494:/myapp# ls
Dockerfile docker-compose.yml package.json
no node_modules folder present, but later when running inside the container: yarn install output:
root#11af1818e494:/myapp# yarn install
yarn install v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.1.3: The platform "linux" is incompatible with this module.
info "fsevents#1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "#rails/webpacker > postcss-cssnext#3.1.0" has unmet peer dependency "caniuse-lite#^1.0.30000697".
warning " > webpack-dev-server#2.11.1" has unmet peer dependency "webpack#^2.2.0 || ^3.0.0".
warning "webpack-dev-server > webpack-dev-middleware#1.12.2" has unmet peer dependency "webpack#^1.0.0 || ^2.0.0 || ^3.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 13.03s.
then when listing:
root#11af1818e494:/myapp# ls
Dockerfile docker-compose.yml node_modules package.json yarn.lock
folder node_modules IT IS present. Why?

This part of Dockerfile installs yarn packages:
RUN mkdir /myapp
WORKDIR /myapp
ADD ./package.json /myapp/
RUN yarn install
Folder /myapp is created, package.json is copied to it and yarn packages are installed. Build is successful and, of course, node_modules folder is inside built image.
But after that you start built image with:
volumes:
- .:/myapp
which means that content of folder where docker-compose.yaml is is mounted to /myapp folder inside container, so it covers content of container's /myapp folder.
You don't need to mount current folder to container's folder to achieve what you want. Just delete it from your docker-compose.yaml:
version: '3'
services:
web:
build: .
Now you can:
$ docker-compose build
$ docker-compose run web bash
root#558d5b0c2ccb:/myapp# ls -la
total 268
drwxr-xr-x 3 root root 4096 Feb 23 22:25 .
drwxr-xr-x 65 root root 4096 Feb 23 22:36 ..
drwxr-xr-x 818 root root 36864 Feb 23 22:25 node_modules
-rw-rw-r-- 1 root root 333 Feb 23 22:07 package.json
-rw-r--r-- 1 root root 219075 Feb 23 22:25 yarn.lock
EDIT:
But what I want is when building the image, get these dependencies not
when spinning up the containers. Otherwise I have another container
which mounts de source code and needs this node_modules folder when
running the "docker-compose up" and I'd like to avoid some kind of
ugly sleep until the node_modules is finished. So I need present this
folder on my root host before up the containers somehow
If you want to achieve the above goal, you can use the following workaround:
1. You modify Dockerfile a little:
FROM ruby:2.5
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 libpq-dev nodejs yarn
RUN mkdir /build && mkdir /myapp
WORKDIR /build
ADD ./package.json /build/
RUN yarn install
WORKDIR /myapp
CMD cp -a /build/node_modules/ /myapp/
That's means that yarn packages will be built in /build folder inside image and copied to /myapp folder once container is started.
2. You use the original docker-compose.yaml file:
version: '3'
services:
web:
build: .
volumes:
- .:/myapp
when you start web container:
docker-compose up web
folder node_modules is copied to mounted folder i.e. to . folder on your host machine.
3. Now you can start any container and it will be contain node_modules folder inside /myapp:
docker-compose run web bash
So, you will be able to achieve your goal the following way:
$ docker-compose build && docker-compose up web
$ docker-compose run web bash
root#4b38e60adfa3:/myapp# ls -la
total 64
drwxrwxr-x 3 1000 1000 4096 Feb 24 10:59 .
drwxr-xr-x 66 root root 4096 Feb 24 11:13 ..
-rw-rw-r-- 1 1000 1000 497 Feb 24 10:55 Dockerfile
-rw-rw-r-- 1 1000 1000 73 Feb 24 09:02 docker-compose.yaml
drwxr-xr-x 818 root root 40960 Feb 24 10:57 node_modules
-rw-rw-r-- 1 root root 333 Feb 23 22:07 package.json

Related

running elixir on buildkite with docker-compose fails with dependencies

i have the following dockerfile for an elixir+phoenix app
FROM elixir:latest as build_base
RUN apt-get -y update
RUN apt-get -y install inotify-tools curl
ARG TARGETARCH
RUN if [ ${TARGETARCH} = arm64 ]; then \
curl -L -o /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.54.5/dart-sass-1.54.5-linux-${TARGETARCH}.tar.gz \
;else \
curl -L -o /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.54.5/dart-sass-1.54.5-linux-x64.tar.gz \
;fi
RUN tar -xvf /tmp/dart-sass.tar.gz -C /tmp
RUN mv /tmp/dart-sass/sass /usr/local/bin/sass
RUN mkdir -p /app
WORKDIR /app
COPY mix.* ./
RUN mix local.hex --force
RUN mix archive.install hex phx_new --force
RUN mix local.rebar --force
RUN mix deps.clean --all
RUN mix deps.get
RUN mix --version
RUN mix deps.compile
COPY assets assets
COPY vendor vendor
COPY lib lib
COPY config config
COPY priv priv
COPY test test
RUN mix compile
the docker-compose file looks like the following
services:
web:
build:
context: .
dockerfile: Dockerfile
target: build_base
volumes:
- ./:/app
ports:
- "80:80"
command: mix phx.server
I'm trying to run docker-compose as part of the build step in buildkite, this is an extract of the step in buildkite
- label: "run web"
key: "web"
commands:
- mix phx.server
plugins:
- docker-compose#v4.9.0:
run: web
config: docker-compose.yml
however when running web i see everything happens properly including the package installation, however when running the application i see the following error
web_1 | Unchecked dependencies for environment dev:
web_1 | * telemetry_metrics (Hex package)
web_1 | the dependency is not available, run "mix deps.get"
and the list goes on and on, this works fine on my local machine, its only when running on buildkite. does anyone have any idea on how to fix this ?

Docker-Compose up Failed Because `Service 'nginx' failed to build`

I'm new to docker, and have been trying to troubleshoot this error for a while. I've read similar posts and nothing seems to work.
Full error:
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to copy: httpReadSeeker: failed open: could not fetch content descriptor sha256:eff196a3849ad6541fd3afe676113896be214753740e567575bb562986bd2cd4 (application/vnd.docker.distribution.manifest.v1+json) from remote: not found
ERROR: Service 'nginx' failed to build : Build failed
I have three Dockerfiles, one for my react frontend, one for my django backend, and one for nginx.
Frontend dockerfile:
COPY ./react_app/package.json .
RUN apk add --no-cache --virtual .gyp \
python \
make \
g++ \
&& npm install \
&& apk del .gyp
COPY ./react_app .
ARG API_SERVER
ENV REACT_APP_API_SERVER=${API_SERVER}
RUN REACT_APP_API_SERVER=${API_SERVER} \
npm run build
WORKDIR /usr/src/app
RUN npm install -g serve
COPY --from=builder /usr/src/app/build ./build
Django Python backend Dockerfile
WORKDIR /usr/src/app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
FROM python:3.7.9-slim-stretch
RUN apt-get update && apt-get install -y --no-install-recommends netcat && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*
WORKDIR /usr/src/app
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
COPY ./django_app .
RUN chmod +x /usr/src/app/entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
and the nginx dockerfile
FROM nginx:1.19.0-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
WORKDIR /usr/src/app
Backend Dockerfile
###########
# BUILDER #
###########
# pull official base image
FROM python:3.7.9-slim-stretch as builder
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
#########
# FINAL #
#########
# pull official base image
FROM python:3.7.9-slim-stretch
# installing netcat (nc) since we are using that to listen to postgres server in entrypoint.sh
RUN apt-get update && apt-get install -y --no-install-recommends netcat && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# install dependencies
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*
# set work directory
WORKDIR /usr/src/app
# copy entrypoint.sh
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
# copy our django project
COPY ./django_app .
# run entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
Nginx Dockerfile
FROM nginx:1.19.0-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
WORKDIR /usr/src/app
I don't know where to go from here. I've tried following 5 or 6 similar stack overflows and many more github issues, to no avail. Thanks, please let me know.

CentOS - error while using yum

I get this error when I try to use yum,
http://iredmail.org/yum/rpms/6/repodata/repomd.xml: [Errno 14] problem making ssl connection
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: iRedMail. Please verify its path and try again
I tried the below but the error persists.
yum clean all
rm /var/lib/rpm/__db*
rpm --rebuilddb
yum update
Please let me know how to fix this, appreciate your help.
Create repo.disabled inside /etc/yum.repos.d
[root#centos ~]# mkdir /etc/yum.repos.d/repo.disabled
[root#centos ~]# ls /etc/yum.repos.d/
centos.repo centos.repo centos-updates.repo centos-updates-testing.repo
repo.disabled
Then move all these 3 repo files into repo.disabled folder :
[root#centos ~]# mv /etc/yum.repos.d/centos.repo/etc/yum.repos.d/repo.disabled
[root#centos ~]# mv /etc/yum.repos.d/centos-updates.repo/etc/yum.repos.d/repo.disabled
[root#centos ~]# mv /etc/yum.repos.d/centos-updates-testing.repo/etc/yum.repos.d/repo.disabled
List out the updated files and folders inside /etc/yum.repos.d :
[root#centos ~]# ls -l /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 92 Aug 18 00:09 centos.repo
drwxr-xr-x. 2 root root 4096 Aug 18 11:27 repo.disabled
NOTE : Only file centos.repo and the folder repo.disabled should exist.
Now you gotta run yum clean all to clear the cache and everything should work just fine.
[root#centos ~]# yum clean all

Install Docker using a Dockerfile

I have a Dockerfile that looks like this:
# Pull base image
FROM openjdk:8
ENV SCALA_VERSION 2.12.2
ENV SBT_VERSION 0.13.15
# Scala expects this file
RUN touch /usr/lib/jvm/java-8-openjdk-amd64/release
# Install Scala
## Piping curl directly in tar
RUN \
curl -fsL http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz | tar xfz - -C /root/ && \
echo >> /root/.bashrc && \
echo 'export PATH=~/scala-$SCALA_VERSION/bin:$PATH' >> /root/.bashrc
# Install sbt
RUN \
curl -L -o sbt-$SBT_VERSION.deb http://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && \
rm sbt-$SBT_VERSION.deb && \
apt-get update && \
apt-get install sbt && \
sbt sbtVersion
# Install Docker
RUN \
# if we have older versions, let's get rid of them first
apt-get install docker
# Define working directory
WORKDIR /root
What I want to do is, I would like to install Docker into this image and be able to run docker commands form within. How do I start the installed docker instance?
You can install the docker client binary only and share dockerd with the container and host.
Here is an example Dockerfile:
FROM openjdk:8
# Install your dependencies
# ...
# Install curl
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install docker client
ENV DOCKER_CHANNEL stable
ENV DOCKER_VERSION 17.03.1-ce
ENV DOCKER_API_VERSION 1.27
RUN curl -fsSL "https://download.docker.com/linux/static/${DOCKER_CHANNEL}/x86_64/docker-${DOCKER_VERSION}.tgz" \
| tar -xzC /usr/local/bin --strip=1 docker/docker
Build the image:
$ docker build -t docker-client .
Run a docker container with mounting /var/run/docker.sock, and then you can use docker command in the container:
$ docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock docker-client /bin/bash
root#c696b78206a8:/# docker version
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Mon Mar 27 16:58:30 2017
OS/Arch: linux/amd64
Server:
Version: 17.05.0-ce
API version: 1.29 (minimum version 1.12)
Go version: go1.7.5
Git commit: 89658be
Built: Thu May 4 21:43:09 2017
OS/Arch: linux/amd64
Experimental: false
Note that mounting the docker.sock means that the container is permitted access to the docker host. Please be aware that there are potential security risks.
I would recommend you that use the official "dind" image (docker in docker): https://hub.docker.com/_/docker/ . However you will need to rewrite your Dockerfile.
FROM docker:dind-stable
# Install your stuff
And, take into account this:
Although running Docker inside Docker is generally not recommended, there are some legitimate use cases, such as development of Docker itself.

issues in buiding Slate with Docker

I have tried to build slate using Docker, but modified changes are not affected when i compile the source. in my source path I have below files.
Dockerfile
FROM debian:latest
MAINTAINER Fed
VOLUME /usr/src/app/source
EXPOSE 4567
RUN apt-get update && \
apt-get install -y ruby git ruby-dev make gcc zlib1g-dev nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN gem install bundler
RUN git clone https://github.com/tripit/slate.git /slate
WORKDIR "/slate"
RUN bundle install
CMD ["bundle", "exec", "middleman", "server", "--force-polling"]
docker-compose.yml
slate:
build: .
ports:
- 4567:4567
volumes:
- ./source:/slate/source
- ./build:/slate/build
Makefile
.PHONY: build
build:
docker-compose build
up:
docker-compose up
compile:
docker-compose run slate bundle exec middleman build --clean
When I tried make compile output shows
docker-compose run slate bundle exec middleman build --clean
create build/stylesheets/screen.css
create build/stylesheets/print.css
create build/images/navbar.png
create build/images/logo.png
create build/fonts/slate.svg
create build/fonts/slate.woff
create build/fonts/slate.woff2
create build/fonts/slate.ttf
create build/fonts/slate.eot
create build/javascripts/all.js
create build/javascripts/all_nosearch.js
create build/index.html
Project built successfully
and when I execute make build
docker-compose build
Building slate
Step 1 : FROM debian:latest
---> 1b088884749b
Step 2 : MAINTAINER Fed
---> Using cache
---> f36ba5d1e018
Step 3 : VOLUME /usr/src/app/source
---> Using cache
---> d97292401c69
Step 4 : EXPOSE 4567
---> Using cache
---> 5ae0ecc71451
Step 5 : RUN apt-get update && apt-get install -y ruby git ruby-dev make gcc zlib1g-dev nodejs && apt-get clean && rm -rf /var/lib/apt/lists/*
---> Using cache
---> c83e099e40ee
Step 6 : RUN gem install bundler
---> Using cache
---> 4cc13ce89152
Step 7 : RUN git clone https://github.com/tripit/slate.git /slate
---> Using cache
---> 1ec325b7dc6b
Step 8 : WORKDIR "/slate"
---> Using cache
---> 8cc73cafc405
Step 9 : RUN bundle install
---> Using cache
---> 150ed469b196
Step 10 : CMD bundle exec middleman server --force-polling
---> Using cache
---> 9c2142617887
Successfully built 9c2142617887
and when I execute make up
docker-compose up
Starting docs_slate_1
Attaching to docs_slate_1
slate_1 | == The Middleman is loading
slate_1 | == View your site at "http://localhost:4567", "http://127.0.0.1:4567"
slate_1 | == Inspect your site configuration at "http://localhost:4567/__middleman", "http://127.0.0.1:4567/__middleman"
but when I go to browser(http://192.168.99.100:4567/- boot2docker ip) and check then it will shows original slate installation not my modified changes i have done to index.html.md file in source folder. The build folder in my path also have not been updated.
anyone can identify What i have done wrong here? I'm new to Docker.
Thanks.
Try this: docker-compose up --build