Install yarn global on Docker file - ruby-on-rails

I'm trying to get a global package recognized by yarn and the docker image.
FROM ruby:2.7.2
RUN apt-get update -qq && apt-get install -y nodejs libvips-tools yarn
# Install all gems first.
# This hits the warm cache if unchanged so bundling is faster.
COPY Gemfile* /tmp/
WORKDIR /tmp
RUN bundle install
WORKDIR /sapco
COPY . /sapco
# Get yarn and install global required packages
RUN yarn global add mjml
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
I build this with docker build -f Dockerfile.dev .
I get the following error:
=> [internal] load build definition from Dockerfile.dev 0.0s
=> => transferring dockerfile: 504B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for docker.io/library/ruby:2.7.2 1.2s
=> CACHED [1/8] FROM docker.io/library/ruby:2.7.2#sha256:abe7034da4092958d306c37aded76a751ea9d35d5c90d1ad9e92290561bd5f3f 0.0s
=> [internal] load build context 0.4s
=> => transferring context: 220.47kB 0.4s
=> [2/8] RUN apt-get update -qq && apt-get install -y nodejs libvips-tools yarn 38.2s
=> [3/8] COPY Gemfile* /tmp/ 0.1s
=> [4/8] WORKDIR /tmp 0.0s
=> [5/8] RUN bundle install 292.6s
=> [6/8] WORKDIR /sapco 0.0s
=> [7/8] COPY . /sapco 0.5s
=> ERROR [8/8] RUN yarn global add mjml 0.7s
------
> [8/8] RUN yarn global add mjml:
#12 0.567 Parsing scenario file global
#12 0.568 ERROR: [Errno 2] No such file or directory: 'global'

The issue is that yarn is the same name for another binary provided by cmdtest
I eventually traced it down to https://github.com/yarnpkg/yarn/issues/2821 and resolved my issue with this command to run in the Dockerfile.
apt remove -y cmdtest
apt remove -y yarn
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 update
apt install yarn

Related

laravel sail won't install or start. same goes with composer update

This question was migrated from Server Fault because it can be answered on Stack Overflow.
Migrated 5 days ago.
I've git cloned a project. my project from github.
the files are correct, checked them up.
On my pc I use sail and it works. however, it fails on my new station.
sail up (or build) raises this error:
[+] Running 0/1
⠿ laravel.test Warning 0.1s
[+] Building 76.5s (8/15)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:22.04 0.8s
=> [internal] load build context 0.1s
=> => transferring context: 99B 0.0s
=> [ 1/11] FROM docker.io/library/ubuntu:22.04#sha256:27cxxxxxxxxxxxxxxxxxxxxxxxf3f928 0.0s
=> CACHED [ 2/11] WORKDIR /var/www/html 0.0s
=> CACHED [ 3/11] RUN ln -snf /usr/share/zoneinfo/UTC /etc/localtime && echo UTC > /etc/timezone 0.0s
=> ERROR [ 4/11] RUN apt-get update && apt-get install -y gnupg gosu curl ca-certificates zip unzip git sup 75.5s
------
> [ 4/11] RUN apt-get update && apt-get install -y gnupg gosu curl ca-certificates
zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils && curl -sS
'https://keyserver.ubuntu.com/pks/lookup?op=get&
search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /usr/share
/keyrings/ppa_ondrej_php.gpg > /dev/null && echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" >
/etc/apt/sources.list.d/ppa_ondrej_php.list && apt-get update && apt-get install -y php8.1-cli php8.1-dev
.................
Running composer update fails due to database connection error...
any idea?

Docker cross compile build context leads to `dockerfile.v0: unsupported frontend capability moby.buildkit.frontend.contexts`

I'm trying to cross compile a rust application for my raspberry pi (the compilation there is very slow).
For that I try to execute a Dockerfile with a build context somewhere else (because there are some certificates and other things, which are needed in the Docker image).
Dockerfile (./myapp/Dockerfile)
FROM rust
RUN apt-get update && apt-get install -y pkg-config libssl-dev build-essential cmake
WORKDIR /home/myapp
COPY --from=local ./myapp/. .
COPY --from=local ./mqtt-helper/ /home/mqtt-helper/
COPY --from=local ./mqtt-broker/config/certs/ca.crt ./certs/
COPY --from=local ./mqtt-broker/config/certs/mqtt-subscriber.key ./certs/
COPY --from=local ./mqtt-broker/config/certs/mqtt-subscriber.crt ./certs/
ENV TZ=Europe/Berlin
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN cargo install --path .
EXPOSE 8080
CMD ["myapp"]
Now I'm trying to run:
docker buildx build --platform linux/arm64 --build-context local=./ ./myapp/
But this call always leads into:
[+] Building 0.0s (2/2) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
ERROR: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: unsupported frontend capability moby.buildkit.frontend.contexts
thank you

Issue with `multiarch-support` is not installable when building Docker image

My Dockerfile
FROM continuumio/miniconda3
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends g++ unixodbc-dev
# Copy environment.yml (if found) to a temp location so we update the environment.
COPY environment.yml /tmp/conda-tmp/
RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \
&& rm -rf /tmp/conda-tmp
RUN apt install -y gnupg curl
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
# optional: for bcp and sqlcmd
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN . ~/.bashrc
# optional: for unixODBC development headers
RUN apt-get install -y unixodbc-dev
WORKDIR /workspace
COPY . .
ENTRYPOINT ["/bin/bash"]
When I am trying to build the docker image using docker build -t my-simulator . I am getting the followings:
=> [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 1.09kB 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 34B 0.0s => [internal] load metadata for docker.io/continuumio/miniconda3:latest 1.1s => [auth] continuumio/miniconda3:pull token for registry-1.docker.io 0.0s => [internal] load build context 0.0s => => transferring context: 11.16kB 0.0s => [ 1/15] FROM docker.io/continuumio/miniconda3#sha256:977263e8d1e476972fddab1c75fe050dd3cd17626390e874448bd92721fd659b 0.0s => CACHED [ 2/15] RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-recommends g++ unixodbc-dev 0.0s => CACHED [ 3/15] COPY environment.yml /tmp/conda-tmp/ 0.0s => CACHED [ 4/15] RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi && rm -rf /tmp/conda- 0.0s => CACHED [ 5/15] RUN apt install -y gnupg curl 0.0s => CACHED [ 6/15] RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 0.0s => CACHED [ 7/15] RUN curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list 0.0s => CACHED [ 8/15] RUN apt-get update 0.0s => ERROR [ 9/15] RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17 0.8s ------
> [ 9/15] RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17:
#14 0.313 Reading package lists...
#14 0.651 Building dependency tree...
#14 0.736 Reading state information...
#14 0.771 Some packages could not be installed. This may mean that you have
#14 0.771 requested an impossible situation or if you are using the unstable
#14 0.771 distribution that some required packages have not yet been created
#14 0.771 or been moved out of Incoming.
#14 0.771 The following information may help to resolve the situation:
#14 0.771
#14 0.771 The following packages have unmet dependencies:
#14 0.810 libodbc1 : PreDepends: multiarch-support but it is not installable
#14 0.810 odbcinst1debian2 : PreDepends: multiarch-support but it is not installable
#14 0.817 E: Unable to correct problems, you have held broken packages.
------
executor failed running [/bin/sh -c ACCEPT_EULA=Y apt-get install -y msodbcsql17]: exit code: 100
It seems the issue is multiarch-suppot being not installable. I have tried these solutions (#1 and #2) without success.

dotnet not found in alpine docker

I have the following dockerfile:
FROM jenkins/jenkins:lts-alpine
USER root
RUN apk update
RUN apk add bash icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib wget
RUN apk add libgdiplus --repository https://dl-3.alpinelinux.org/alpine/edge/testing/
USER jenkins
RUN wget https://dot.net/v1/dotnet-install.sh -O $HOME/dotnet-install.sh
RUN chmod +x $HOME/dotnet-install.sh
RUN $HOME/dotnet-install.sh -c 5.0
RUN dotnet --info
EXPOSE 2376 23676
But when I run docker-compose, it gives me:
Building jenkins
failed to get console mode for stdout: Invalid identifier.
[+] Building 64.6s (10/11)
[+] Building 64.7s (11/11) FINISHED
=> [internal] load build definition from jenkins.dockerfile 0.0s
=> => transferring dockerfile: 486B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/jenkins/jenkins:lts-alpine 1.6s
=> [1/8] FROM docker.io/jenkins/jenkins:lts-alpine#sha256:b2f3dd63864733 0.0s
=> CACHED [2/8] RUN apk update 0.0s
=> CACHED [3/8] RUN apk add bash icu-libs krb5-libs libgcc libintl libss 0.0s
=> [4/8] RUN apk add libgdiplus --repository https://dl-3.alpinelinux.or 7.8s
=> [5/8] RUN wget https://dot.net/v1/dotnet-install.sh -O $HOME/dotnet-i 2.2s
=> [6/8] RUN chmod +x $HOME/dotnet-install.sh 0.3s
=> [7/8] RUN $HOME/dotnet-install.sh -c 5.0 52.2s
=> ERROR [8/8] RUN dotnet --info 0.5s
------
> [8/8] RUN dotnet --info:
#11 0.447 /bin/sh: dotnet: not found
------
ERROR: Service 'jenkins' failed to build
I followed every step in Microsoft documentation but I keep failing. What am I doing wrong here?
Using the jenkins/jnlp-slave:alpine image
FROM jenkins/jnlp-slave:alpine
USER root
RUN apk add bash icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib wget
RUN apk add libgdiplus --repository https://dl-3.alpinelinux.org/alpine/edge/testing/
RUN mkdir -p /usr/share/dotnet \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
RUN wget https://dot.net/v1/dotnet-install.sh
RUN chmod +x dotnet-install.sh
RUN ./dotnet-install.sh -c 3.1 --install-dir /usr/share/dotnet
RUN ./dotnet-install.sh -c 5.0 --install-dir /usr/share/dotnet
RUN ./dotnet-install.sh -c 6.0 --install-dir /usr/share/dotnet
To install .Net Core 5.0 SDK in a jenkins container with volumes configure I had to do the following:
FROM jenkins/jenkins:lts-alpine AS builder
# Switch to root user to install .NET SDK
USER root
# Pre-requisits
RUN apk add bash icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib wget
RUN apk update
FROM builder
# Download do script
RUN wget https://dot.net/v1/dotnet-install.sh -O $HOME/dotnet-install.sh
RUN chmod +x $HOME/dotnet-install.sh
RUN $HOME/dotnet-install.sh -c 5.0
EXPOSE 2376 2376

Docker build fails with 'secret pip not found: not found' error

I am trying to build a docker image but getting
secret pip not found: not found
Any ideas on this?
Dockerfile:
FROM <jfrog dockerfile package>
SHELL ["/bin/bash", "-c"]
RUN apt-get update \
&& apt-get -y install chromium chromium-driver
COPY requirments.txt
RUN pip install -r requirments.txt
USER nobody
CMD robot ./smoketests-nonprod.robot \
&& robot ./smoketests-prod.robot
The log is as follows:
$ docker build -t robottests .
[+] Building 1.6s (18/25)
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 39B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 35B 0.0s
=> resolve image config for my-company-docker-virtual.jfrog.io/docker/dockerfile:1.2 0.0s
=> CACHED docker-image://my-company-docker-virtual.jfrog.io/docker/dockerfile:1.2 0.0s
=> [internal] load metadata for my-company-docker-virtual.jfrog.io/node:14-buster-slim 0.0s
=> [internal] load metadata for my-company-docker-virtual.jfrog.io/python:3-slim 0.0s
=> [base 1/7] FROM my-company-docker-virtual.jfrog.io/python:3-slim 0.0s
=> [client 1/6] FROM my-company-docker-virtual.jfrog.io/node:14-buster-slim 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 5.25kB 0.0s
=> CACHED [base 2/7] RUN echo 'APT { Default-Release "stable"; };' >/etc/apt/apt.conf && echo deb http://deb.debian.org/debian testing main >>/etc/apt/sources.list 0.0s
=> CACHED [base 3/7] RUN --mount=type=cache,target=/var/cache/apt --mount=type=secret,id=sources.list,target=/etc/apt/sources.list,required=true apt update && apt -y install libcap2-bin/testing 0.0s
=> CACHED [base 4/7] RUN ["/sbin/setcap", "cap_net_bind_service,cap_setpcap+p", "/sbin/capsh"] 0.0s
=> CACHED [base 5/7] WORKDIR /project 0.0s
=> CACHED [base 6/7] COPY pyproject.toml setup.* . 0.0s
=> CACHED [client 2/6] WORKDIR /client 0.0s
=> CACHED [client 3/6] COPY package*.json . 0.0s
=> ERROR [base 7/7] RUN --mount=type=cache,target=/root/.cache --mount=type=secret,id=pip,target=/etc/pip.conf,required=true mkdir -p src && pip install -U pip wheel && pip install . && pip unin 0.1s
=> CANCELED [client 4/6] RUN --mount=type=secret,id=npmrc,target=/usr/local/etc/npmrc,required=true --mount=type=bind,source=.npmrc,target=/root/.npmrc --mount=type=cache,target=/root/.npm npm c 0.2s
------
> [base 7/7] RUN --mount=type=cache,target=/root/.cache --mount=type=secret,id=pip,target=/etc/pip.conf,required=true mkdir -p src && pip install -U pip wheel && pip install . && pip uninstall -y $(./setup.py --name):
------
secret pip not found: not found
Any help would be appreciated
This is using the relatively new --secret option which allows you to mount secrets at build time
The general way you utilize it is you have a secret file outside and assign it an id
in your case, you'd have a pip.conf file somewhere and specify it in your build command:
docker build --secret id=pip,src=pip.conf -t robottests .
this will make the pip.conf available during the build, but not part of your image (presumably because it contains authentication secrets for accessing your internal pypi)
Maybe I'm wrong, but for me you do not show the Dockerfile corresponding to the logs. Or there are some missing parts which could have been helpful.
I'd expect to view something like that in your Dockerfile which is in error :
RUN ["/sbin/setcap", "cap_net_bind_service,cap_setpcap+p", "/sbin/capsh"]
WORKDIR /project
COPY pyproject.toml setup.* .
WORKDIR /client
RUN --mount=type=cache,target=/root/.cache --mount=type=secret,id=pip,target=/etc/pip.conf,required=true mkdir -p src && pip install -U pip wheel && pip install . && pip unin...
Because in this last line, there is the part that fails :
--mount=type=secret,id=pip,target=/etc/pip.conf,required=true
And with the link provided by Anthony Sottile, or this link I think you can be able to find out what is wrong in your command.

Resources