Dockerfile: not able to run bin command ubuntu - docker

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.

Related

How to install elasticsearch in a docker container?

I am trying to install elasticsearch in an ubuntu docker container. This is my Dockerfile:
FROM ubuntu:21.04 as elastic_install
RUN apt-get update
RUN apt-get install -y wget gnupg apt-transport-https openjdk-8-jdk
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-7.x.list
RUN apt-get update && apt-get install -y elasticsearch
When I now try to run elasticsearch, it is killed after a few seconds with the following message:
root#18c3d6649c1b:/# /usr/share/elasticsearch/bin/elasticsearch
Killed
root#18c3d6649c1b:/# /usr/share/elasticsearch/bin/elasticsearch -d
/usr/share/elasticsearch/bin/elasticsearch: line 95: 369 Killed exec "$JAVA" "$XSHARE" $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -Des.path.conf="$ES_PATH_CONF" -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" -Des.distribution.type="$ES_DISTRIBUTION_TYPE" -Des.bundled_jdk="$ES_BUNDLED_JDK" -cp "$ES_CLASSPATH" org.elasticsearch.bootstrap.Elasticsearch "$#" <<< "$KEYSTORE_PASSWORD"
root#18c3d6649c1b:/#
How do I install/run elasticsearch correctly? Am I missing something crucial?
When directly running elasticsearch, the environment variables ES_PATH_CONFIG and ES_JAVA_OPTS must be defined.
elasticuser#c5f357e42e51:/# ES_PATH_CONF=/etc/elasticsearch ES_JAVA_OPTS="-Xms8g -Xmx8g" /usr/share/elasticsearch/bin/elasticsearch

ubuntu container install rvm failing

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.

Install sdkman in docker image

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

Creating MongoDB image error from Docker official tutorial

Here is the official tutorial to create mongoDB img.
I followed exactly the tutorial and generated the following Dockerfile
# https://docs.docker.com/engine/examples/mongodb/#creating-a-dockerfile-for-mongodb
# Dockerizing MongoDB: Dockerfile for building MongoDB images
# Based on ubuntu:latest, installs MongoDB following the instructions from:
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
# Format: FROM repository[:version]
FROM ubuntu:latest
# Installation:
# Import MongoDB public GPG key AND create a MongoDB list file
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN apt-get install -y --no-install-recommends software-properties-common
RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
# Update apt-get sources AND install MongoDB
RUN apt-get update && apt-get install -y mongodb-org
# MongoDB requires a data directory. Let’s create it as the final step of our installation instructions.
# Create the MongoDB data directory
RUN mkdir -p /data/db
# Expose port 27017 from the container to the host
EXPOSE 27017
# Set usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["/usr/bin/mongod"]
But when I execute
$ docker build --tag my/repo .
I got the following error:
What is going on? Why it fails? How to fix it?
EDIT:
After adjust the command order, my final script is this:
# Format: FROM repository[:version]
FROM ubuntu:latest
# Update apt-get sources AND install MongoDB
RUN apt-get update
# Installation:
# Import MongoDB public GPG key AND create a MongoDB list file
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN apt-get install -y --no-install-recommends software-properties-common
# RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
RUN apt-get install -y mongodb-org
# MongoDB requires a data directory. Let’s create it as the final step of our installation instructions.
# Create the MongoDB data directory
RUN mkdir -p /data/db
# Expose port 27017 from the container to the host
EXPOSE 27017
# Set usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["/usr/bin/mongod"]
Then I got the following error:
Next, then I added "RUN apt-get install sudo", then I got the following error:
3 strikes down, I am not confident this whole thing will work. Here is my final Dockerfile.
# https://docs.docker.com/engine/examples/mongodb/#creating-a-dockerfile-for-mongodb
# Dockerizing MongoDB: Dockerfile for building MongoDB images
# Based on ubuntu:latest, installs MongoDB following the instructions from:
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
# Format: FROM repository[:version]
FROM ubuntu:latest
# Update apt-get sources AND install MongoDB
RUN apt-get update
# Installation:
# Import MongoDB public GPG key AND create a MongoDB list file
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN apt-get install -y --no-install-recommends software-properties-common
RUN apt-get install sudo
# RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
RUN apt-get install -y mongodb-org
# MongoDB requires a data directory. Let’s create it as the final step of our installation instructions.
# Create the MongoDB data directory
RUN mkdir -p /data/db
# Expose port 27017 from the container to the host
EXPOSE 27017
# Set usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["/usr/bin/mongod"]
If you can make it work, please paste your Dockerfile and I'd love to learn what is wrong in my script. I followed the tutorial and it doesn't work.
A quick google search for your exact error message found this.
This is an error from apt saying it can't find the software-properties-common package in its repositories. When a package change be found, it usually means apt needs updating.
You are running apt-get update but you're running it after the update line.
RUN apt-get install -y --no-install-recommends software-properties-common
...
RUN apt-get update && apt-get install -y mongodb-org
Instead, run it first
RUN apt-get update
RUN apt-get install -y --no-install-recommends software-properties-common
...
RUN apt-get install -y mongodb-org
Update: Your update says you're now getting an error when installing the mongodb package. This is because you've loaded a deb package file and need to update apt yet again so that it knows about it. At this point, the easiest thing to do is just prefix any apt-get commands that complain about not finding packages with an update.
RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common
...
RUN apt-get update && apt-get install -y mongodb-org

installing heroku failed: Name or service not known

im try to install heroku on my ubuntu 12.04
i ran this code on my terminal
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
but it fails, the following errors appeared. what should i do?
try out the alternate way of installation. Using the below commands
sudo apt-add-repository 'deb http://toolbelt.herokuapp.com/ubuntu ./'
wget -O- https://toolbelt.heroku.com/apt/release.key | apt-key add -
sudo apt-get update
sudo apt-get install heroku-toolbelt
i think this can be worked

Resources