I am trying to install rvm in ubuntu docker image with following dockerfile
FROM ubuntu:18.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -q && \
apt-get install -qy procps curl ca-certificates gnupg2 build-essential --no-install-recommends && apt-get clean
RUN curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
RUN curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
RUN curl -sSL https://get.rvm.io | bash -s stable
RUN . /etc/profile.d/rvm.sh
RUN rvm install 1.9.3-dev
But at last command I get
Step 8/9 : RUN rvm install 1.9.3-dev
---> Running in 1b1c6454868d
/bin/sh: 1: rvm: not found
The command '/bin/sh -c rvm install 1.9.3-dev' returned a non-zero code: 127
An idea what's wrong here ?
The command . /etc/profile.d/rvm.sh does not persist into the next RUN layer. That shell file modifies a few things, like the PATH variable, and without it, rvm will not be found in PATH. You can source it and run rvm in the same layer.
RUN bash -c "source /etc/profile.d/rvm.sh && rvm install 1.9.3-dev"
Also, see this related answer regarding rvm in Docker.
Related
I run a given Dockerfile in order to build image for my TeamCity Agent
FROM jetbrains/teamcity-agent:2022.10.1-linux-sudo
RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
RUN sudo sh -c 'echo deb https://apt.kubernetes.io/ kubernetes-xenial main > /etc/apt/sources.list.d/kubernetes.list'
RUN curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
# https://github.com/AdoptOpenJDK/openjdk-docker/blob/master/12/jdk/ubuntu/Dockerfile.hotspot.releases.full
RUN sudo apt-get update && \
sudo apt-get install -y ffmpeg gnupg2 git sudo kubectl \
binfmt-support qemu-user-static mc jq
#RUN wget -O - https://apt.kitware.com/keys/kitware-archive-la3est.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
#RUN sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main' && \
# sudo apt-get update && \
RUN sudo apt install -y cmake build-essential wget
RUN sudo curl -L https://nodejs.org/dist/v14.17.3/node-v14.17.3-linux-x64.tar.gz --output node-v14.17.3-linux-x64.tar.gz
RUN sudo tar -xvf node-v14.17.3-linux-x64.tar.gz
RUN echo 'export PATH="$HOME/node-v14.17.3-linux-x64/bin:$PATH"' >> ~/.bashrc
RUN echo "The version of Node.js is $(node -v)"
All the code was right, but then I decided to add node.js installation to the Dockerfile. that begins from this line:
RUN sudo curl -L https://nodejs.org/dist/v14.17.3/node-v14.17.3-linux-x64.tar.gz --output node-v14.17.3-linux-x64.tar.gz
However, the problem right now is that I have the following error, during execution of the last line of the Dockerfile:
RUN echo "The version of Node.js is $(node -v)"
Output for this line is:
Step 10/22 : RUN echo "The version of Node.js is $(node -v)"
21:07:41 ---> Running in 863b0e75e45a
21:07:42 /bin/sh: 1: node: not found
You need to make the 2 following changed in your Dockerfile for your node installation to be included in your $PATH env var -
Remove the $HOME variable from the path you're concating, as you are currently downloading node to your root folder and not the $HOME folder -
RUN echo 'export PATH="/node-v14.17.3-linux-x64/bin:$PATH"' >> ~/.bashrc
Either source ~/.bashrc explicitly for the $PATH changes to take place or run the export command as part of the Dockerfile
Once you apply these 2 changes, the error should go away.
Trying to get elasticsearch installed and running into an error here in my dockerfile. Looks like it's unable to run bin.
#JDK 1.8 on Ubuntu for ElasticSearch
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get -y update
RUN apt-get -y install openjdk-8-jre
RUN wget -qO – https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add –
RUN apt-get install apt-transport-https
RUN echo “deb https://artifacts.elastic.co/packages/6.x/apt stable main” | tee -a /etc/apt/sources.list.d/elastic-6.x.list
RUN apt-get update
RUN apt-get install elasticsearch
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-phonetic
RUN -service elasticsearch start
RUN gedit /etc/elasticsearch/jvm.options
RUN gedit /etc/elasticsearch/elasticsearch.yml
RUN curl -XGET ‘http://localhost:9200/_cat/health?v&pretty’
Step 21/70 : RUN wget -qO – https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add –
---> Running in 7558b8a264b8
Warning: apt-key output should not be parsed (stdout is not a terminal)
gpg: no valid OpenPGP data found.
The command '/bin/sh -c wget -qO – https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add –' returned a non-zero code: 2
Kind of new to docker so any help would be greatly appreciated. I'm running root user so i don't need to add sudo in front of any of these commands.
It seems there is an issue installing the keys like that. Similar problem here and here.
The suggested solution is to split the command like this:
wget -q https://artifacts.elastic.co/GPG-KEY-elasticsearch
apt-key add GPG-KEY-elasticsearch
In your case, I suspect the output of the wget command is not the GPG key. It might be something else (e.g. proxy response) or an error. Try to remove the silent flag (-q) to see what's really going on.
Hope that helps.
I am following these instructions to build a docker image from python3.7 that also contains ruby - i need 2.1.5 specifically (don't ask).
So my Dockerfile is this:
FROM python:3.7
SHELL ["/bin/bash", "-c"]
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
curl \
dirmngr \
gnupg2 \
&& curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - \
&& gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \
&& curl -sSL https://get.rvm.io | bash -s stable \
&& usermod -a -G rvm root \
&& source /etc/profile.d/rvm.sh \
&& rvm install ruby-2.1.5
The build completes with success but the end image does not have ruby in its path which is the result of this command source /etc/profile.d/rvm.sh actually not having any effect during the build.
As soon as I get a cmd in the container and running it, ruby is available.
Why is that?
See this:
The RUN instruction will execute any commands in a new layer on top of the current image and commit the results.
So, all RUN in Dockerfile will just affect the image build, not container. You should put any source in entrypoint or cmd. Or make symbol link in Dockerfile to link it to /bin/.
If you source a script inside a shell that only exists for the command, it will not have any lasting effect on any future commands.
Try this:
RUN /bin/bash -c "source /etc/profile.d/rvm.sh; command1; command2; command3;"
Getting error while installing SDKMAN! in Ubuntu 16.04 docker 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 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"
make sure you have curl, wget, unzip & zip. With them I am able to install Sdkman successfully. Following is my Docker content
FROM ubuntu:18.04
RUN apt-get update
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -qq -y install curl wget unzip zip
RUN curl -s "https://get.sdkman.io" | bash
RUN source "$HOME/.sdkman/bin/sdkman-init.sh"
TL;DR
Install unzip & zip, which means change
RUN apt-get -qq -y install curl
to
RUN apt-get -qq -y install curl unzip zip
or better
RUN apt-get -qq -y install \
curl \
unzip \
zip
Explanation
When you try to build the Dockerfile, you will get
.....
Step 5/6 : RUN curl -s https://get.sdkman.io | bash
---> Running in 1ce678a59561
--- SDKMAN LOGO ---
Now attempting installation...
Looking for a previous installation of SDKMAN...
Looking for unzip...
Not found.
======================================================================================================
Please install unzip on your system using your favourite package manager.
Restart after installing unzip.
======================================================================================================
Removing intermediate container 1ce678a59561
---> 22211eafd50c
Step 6/6 : RUN source "$HOME/.sdkman/bin/sdkman-init.sh"
---> Running in 1c5cb7d79ef0
/bin/sh: /root/.sdkman/bin/sdkman-init.sh: No such file or directory
The command '/bin/sh -c source "$HOME/.sdkman/bin/sdkman-init.sh"' returned a non-zero code: 1
What you need to do is written just there. This part:
======================================================================================================
Please install unzip on your system using your favourite package manager.
Restart after installing unzip.
======================================================================================================
When you install unzip, you get the same error with zip. After installing it, everything works fine.
So, read your logs/command output. :-)
*P.S. It would be better if curl -s https://get.sdkman.io | bash exited with non-zero code. This way it fails on the next command. But that is not a thing you can fix ;) *
It looks like the sdkman install failed.
When I ran your code above it complained about missing the unzip and zip packages.
After satisfying the dependencies, you'll also need to mark the init script as executable with:
chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh"
So your Dockerfile should look something like:
FROM ubuntu:16.04
RUN apt-get update
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -q -y install curl zip unzip
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"
P.S: Beaten to the punch!
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get -qq -y install \
curl \
unzip \
zip
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -qq -y install curl
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"
docker pull kubile/ubuntu-sdkman:23.04
You can try this image.
This Dockerfile seems to work with versions current as of February 2023:
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y curl zip unzip
RUN curl -s "https://get.sdkman.io" | bash
# this SHELL command is needed to allow using source
SHELL ["/bin/bash", "-c"]
# seems you need to put 'sdk install...'' lines in same RUN command as 'source...'.
RUN source "/root/.sdkman/bin/sdkman-init.sh" \
&& sdk install java 19.0.2-tem \
&& sdk install sbt 1.8.2 \
&& sdk install scala 2.13.10
I am attempting to create a docker image of a rails app using rvm (as non-root) and am running into permission errors:
Dockerfile:
FROM ubuntu
RUN apt-get update -q
RUN apt-get install -qy curl
RUN apt-get install -y libpq-dev
RUN apt-get install -y imagemagick --fix-missing
RUN apt-get install -y curl patch gawk g++ gcc make libc6-dev patch libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev
RUN useradd -ms /bin/bash app
USER app
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
RUN curl -sSL https://get.rvm.io | bash -s stable
RUN /bin/bash -c -l 'rvm install 2.2.1'
RUN /bin/bash -c -l 'rvm use 2.2.1'
RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
RUN /bin/bash -c -l 'gem install bundler --no-ri --no-rdoc'
RUN /bin/bash -c -l 'mkdir /home/app/rails_app'
WORKDIR /home/app/rails_app
ADD Gemfile /home/app/rails_app/Gemfile
ADD Gemfile.lock /home/app/rails_app/Gemfile.lock
RUN /bin/bash -c -l 'bundle install'
ADD . /home/app/rails_app
EXPOSE 3000
CMD /bin/bash -c -l 'RAILS_ENV=production rails server -p 3000'
The image builds fine but when I run the container with docker run
I get the following error:
/home/app/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:367:in `delete': Permission denied # unlink_internal - /home/app/rails_app/tmp/pids/server.pid (Errno::EACCES)
If I add:
USER root
RUN /bin/bash -c -l 'chmod -R 777 /home/app/rails_app/'
RUN /bin/bash -c -l 'chown -R app:app /home/app/rails_app/'
USER app
The container runs but the rails server did not start and there is nothing in the logs. Executing /bin/bash on the running container and trying to start the rails server ends in rails: command not found while logged in as app. Any Ideas?
Thanks