Installed packages in docker image not found in path? - docker

My Dockerfile for custom image with Gradle and Node installed:
FROM ubuntu:jammy
LABEL key=DevOps
SHELL ["/bin/bash", "--login", "-i", "-c"]
RUN apt update && apt upgrade -y && apt install curl -y
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
RUN source /root/.bashrc && nvm install 12.14.1
RUN nvm install 12.20.0
RUN apt install zip unzip
RUN curl -s "https://get.sdkman.io" | bash
RUN source "$HOME/.sdkman/bin/sdkman-init.sh"
RUN sdk install java 8.0.302-open
RUN sdk install gradle 3.4.1
SHELL ["/bin/bash", "--login", "-c"]
CMD [ "bin/bash" ]
After I run it, it says that npm is not found in $PATH, I tried Java, Gradle as well but they weren't found in the path as well.
I don't know why since I installed them as you can tell from the Dockerfile.
How can I preinstall these dependencies so that I can address them during the build process of my app?

Related

Dockerfile to create an image to be used as an container agent in jenkins

I am trying to use a node agent container in Jenkins to run npm instructions on it. So that, I am creating a Dockerfile to get a valid image with ssh and nodejs. The executor runs fine, but when I use npm it says that it doesn't know the command.
The same problem happens when (after building the dockerfile) I do docker exec -it af5451297d85 bash and after that, inside the container, I try to do npm --v (for example).
# This Dockerfile is used to build an image containing an node jenkins agent
FROM node:9.0
MAINTAINER Estefania Castro <estefania.castro#luceit.es>
# Upgrade and Install packages
RUN apt-get update && apt-get -y upgrade && apt-get install -y git openssh-server
# Install NGINX to test.
RUN apt-get install nginx -y
# Prepare container for ssh
RUN mkdir /var/run/sshd && adduser --quiet jenkins && echo "jenkins:jenkins" | chpasswd
RUN npm install
ENV CI=true
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
I would like to run npm instructions like npm install, npm publish, ... to manage my project in a jenkinsfile. Could anyone help?
Thanks
I have already solved the problem (after two weeks haha).
FROM jenkins/ssh-slave
# Install selected extensions and other stuff
RUN apt-get update && apt-get -y --no-install-recommends install && apt-get clean
RUN apt-get install -y curl
# Install nodejs
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs && apt-get install -y nginx

Why docker layer is not cached?

I have Dockerfile which have next command:
RUN source $PERLBREW_ROOT/etc/bashrc && perlbrew install $PERL_VERSION
Here layers start to rebuild:
Step 12/27 : RUN echo -e "\nif [ -f /opt/perlbrew/etc/bashrc ]; then\n\tsource /opt/perlbrew/etc/bashrc\nfi\n" >> /root/.bash_profile
---> Using cache
---> b18437df38fb
Step 13/27 : RUN source $PERLBREW_ROOT/etc/bashrc && perlbrew install $PERL_VERSION
---> Running in 3b76e5d4ae0a
Fetching perl 5.24.1 as /opt/perlbrew/dists/perl-5.24.1.tar.bz2
Download http://www.cpan.org/authors/id/S/SH/SHAY/perl-5.24.1.tar.bz2 to /opt/perlbrew/dists/perl-5.24.1.tar.bz2
Installing /opt/perlbrew/build/perl-5.24.1/perl-5.24.1 into /opt/perlbrew/perls/perl-5.24.1
Why cached layer is not used for this command?
UPD
The docker file:
FROM centos:latest
ARG PERLBREW_ROOT=/opt/perlbrew
ARG PERL_VERSION=5.24.1
ARG MONKEYMAN_DIR=/opt/monkeyman
RUN yum -y install yum-plugin-ovl
RUN yum -y upgrade
RUN yum -y install perl
RUN yum-builddep -y perl
RUN yum install -y bzip2 zip which
RUN yum groupinstall -y 'Development Tools'
RUN curl -L https://install.perlbrew.pl | bash
RUN echo -e "\nif [ -f /opt/perlbrew/etc/bashrc ]; then\n\tsource /opt/perlbrew/etc/bashrc
\nfi\n" >> /root/.bash_profile
RUN source $PERLBREW_ROOT/etc/bashrc && perlbrew install $PERL_VERSION
RUN source $PERLBREW_ROOT/etc/bashrc && perlbrew switch $PERL_VERSION
RUN source $PERLBREW_ROOT/etc/bashrc && perlbrew install-cpanm
RUN source $PERLBREW_ROOT/etc/bashrc && cpanm Carton
no arguments provided when build
UPD
$ docker --version
Docker version 1.13.1, build 07f3374/1.13.1

Install kotlin in ubuntu image getting error

I am getting an error while installing kotlin in ubuntu image.
FROM ubuntu:16.04
RUN apt-get update
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -qq -y install curl
RUN apt-get install -y unzip
RUN apt-get install -y zip
RUN curl -s https://get.sdkman.io | bash
RUN chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh"
RUN source "$HOME/.sdkman/bin/sdkman-init.sh"
RUN sdk install kotlin
Getting error
Step 10/35 : RUN sdk install kotlin
---> Running in 9282af532681
/bin/sh: sdk: command not found
ERROR: Service 'myproject' failed to build: The command '/bin/sh -c sdk install kotlin' returned a non-zero code: 127
FROM ubuntu:16.04
RUN apt-get update
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -qq -y install curl
RUN apt-get install -y unzip
RUN apt-get install -y zip
RUN curl -s https://get.sdkman.io | bash
RUN chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh"
RUN source "$HOME/.sdkman/bin/sdkman-init.sh" && sdk install kotlin
Each RUN have their own "session". So RUN sdk install kotlin will not know about previous source command.
Multiple RUN is not optimal: each RUN will create a layer.
Looks like you want to create docker image with Kotlin JVM. Then you need standard openjdk:8-jdk (Or what version you want) and then just put there your jar file.

not able to start uwsgi as a service in docker

1)I have copied my demo.ini file inside /etc/uwsgi/app-enabled/demo.ini
2)I have installed the package apt-get install uwsgi-plugin-python
3)Added the plugins= python in demi.ini file
now when i hit the command sudo service uwsgi status it shows output which?
FROM base_image
RUN apt-get -y install uwsgi
COPY workspace /home/nt/workspace
RUN ln -s /home/nt/workspace/backend.conf /etc/nginx/sites-enabled/backend.conf
RUN ln -s /home/nt/workspace/nti-backend/environment/development.ini /etc/uwsgi/apps-enabled/
RUN pip install -r /home/nt/workspace/nti-backend/requirements.txt
ENTRYPOINT sh /home/nt/workspace/startup.sh && /bin/bash

Some RUNs won't work on docker but will when inside a container

I've got a Dockerfile for some lua and torch related tasks and I'm trying to install some rocks using luarocks.
FROM ubuntu:14.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update -y
RUN apt-get install -y curl git
RUN curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
RUN git clone https://github.com/torch/distro.git ~/torch --recursive
RUN cd ~/torch; ./install.sh
RUN source ~/.bashrc
RUN luarocks install nngraph
RUN luarocks install optim
RUN luarocks install nn
RUN luarocks install cltorch
RUN luarocks install clnn
docker build runs fine up until the first luarocks call: RUN luarocks install nngraph at which point it stops and throws the error:
/bin/sh: luarocks: command not found
If I comment out the luarocks lines, the build runs fine. Using that image, I can create a container and using bash, run luarocks as expected.
Of course, I don't particularly want to have to do this every time I start up the container, so I'm wondering if there's anything I can do to make this work. I have a feeling that this problem has something to do with the line RUN rm /bin/sh && ln -s /bin/bash /bin/sh but I need that to be able to run the line RUN source ~/.bashrc.
Thanks.
Each RUN command runs on its own shell and a new layer is committed.
From the Docker documentations:
RUN (the command is run in a shell - /bin/sh -c - shell
form)
So when you run luarocks install <app> it will not be the same shell you source your profile.
You have to provide the full path for luarocks to run. See below a modified Dockerfile I successfully run:
FROM ubuntu:14.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update -y
RUN apt-get install -y curl git
RUN curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
RUN git clone https://github.com/torch/distro.git ~/torch --recursive
RUN cd ~/torch; ./install.sh
RUN source ~/.bashrc
RUN /root/torch/install/bin/luarocks install nngraph
RUN /root/torch/install/bin/luarocks install optim
RUN /root/torch/install/bin/luarocks install nn
RUN /root/torch/install/bin/luarocks install cltorch
RUN /root/torch/install/bin/luarocks install clnn
For more details see docker RUN documentation here.
As Alex da Silva pointed it out, sourcing .bashrc happens in another shell in your Dockerfile.
You could also try that to have your luarocks commands executed in the same shell with your sourced bashrc:
...
RUN source ~/.bashrc && luarocks install nngraph
RUN source ~/.bashrc && luarocks install optim
RUN source ~/.bashrc && luarocks install nn
RUN source ~/.bashrc && luarocks install cltorch
RUN source ~/.bashrc && luarocks install clnn

Resources