Creating MongoDB image error from Docker official tutorial - docker

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

Related

Completely delete a Ubuntu based docker container along with underlying layers of MySQL and JDK

I have created custom docker image using Ubuntu 16.04 xenial as base image, and installed JDK-1.8 and MY-SQL layer on it. Following is sample snap-shot of my Dockerfile to create image.
# Use 0.9.19 as this is the last tag that uses Ubuntu 16.04 xenial
FROM phusion/baseimage:0.9.19
# Set correct environment variables.
ENV HOME /root
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
# Maintained by Abhi
MAINTAINER Abhishek <abhi#gmail.com>
# Set the locale. Default locale causes some Perl regexes to fail.
# http://jaredmarkell.com/docker-and-locales/
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV MYSQL_PWD pass123admin
# Fix warning "debconf: delaying package configuration, since apt-utils is not installed " during build.
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
# The base Ubuntu images don't come with sudo, so Add sudo
RUN apt-get update && apt-get install -y sudo
# Install JDK 8
RUN echo "deb http://debian.opennms.org/ stable main" >> /etc/apt/sources.list \
&& curl -sS http://debian.opennms.org/OPENNMS-GPG-KEY | apt-key add - \
&& apt-get update -y \
&& echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections \
&& apt-get install oracle-java8-installer -y
## Install all software available via apt-get
RUN echo "mysql-server mysql-server/root_password password $MYSQL_PWD" | debconf-set-selections \
&& echo "mysql-server mysql-server/root_password_again password $MYSQL_PWD" | debconf-set-selections \
&& apt-get update -y && apt-get install -y \
mysql-server
Everything works as expected for building the image and creating the container.
But whenever I tried to remove the Docker-Container created using this image. It is not removing MY-SQL layer within it.
I used $ docker rm mycontainer mycontainer command to delete the container created using above image.
But when I recreated the container using above image (also uses --force-recreate option), I was able to see my previous data in MySql Database. This means $ docker rm can not remove the container completely with underlying layers.
Is there a way to delete completely remove docker-container including it's underlying layers of MySQL or JDK?
Thanks in advance.

How to write docker-compose file for bbb (big blue button)?

I find a Big Blue Button Dockerfile on [ bigbluebutton /docker ][1] [1]: https://github.com/bigbluebutton/docker
And second week I tryed to write docker-compose.yml file.
How to write docker-compose.yml file. I tried but not success.
This is Dockerfile [ bigbluebutton /docker ][1] [1]: https://github.com/bigbluebutton/docker
FROM ubuntu:16.04
MAINTAINER ffdixon#bigbluebutton.org
ENV DEBIAN_FRONTEND noninteractive
# RUN echo 'Acquire::http::Proxy "http://192.168.0.130:3142";' > /etc/apt/apt.conf.d/01proxy
RUN apt-get update && apt-get install -y wget
RUN echo "deb http://ubuntu.bigbluebutton.org/xenial-200 bigbluebutton-xenial main " | tee /etc/apt/sources.list.d/bigbluebutton.list
RUN wget http://ubuntu.bigbluebutton.org/repo/bigbluebutton.asc -O- | apt-key add -
RUN apt-get update && apt-get -y dist-upgrade
# -- Setup tomcat7 to run under docker
RUN apt-get install -y \
haveged \
net-tools \
supervisor \
sudo \
tomcat7
RUN sed -i 's|securerandom.source=file:/dev/random|securerandom.source=file:/dev/urandom|g' /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/java.security
ADD mod/tomcat7 /etc/init.d/tomcat7
RUN chmod +x /etc/init.d/tomcat7
RUN apt-get install -y language-pack-en
RUN update-locale LANG=en_US.UTF-8
# -- Install BigBlueButton
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN apt-get install -y bigbluebutton
RUN apt-get install -y bbb-demo
# -- Install mongodb (for HTML5 client)
RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
RUN echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
RUN sudo apt-get update && sudo apt-get install -y mongodb-org curl
# -- Install nodejs (for HTML5 client)
RUN apt-get install -y apt-transport-https
RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
RUN echo 'deb http://deb.nodesource.com/node_8.x xenial main' > /etc/apt/sources.list.d/nodesource.list
RUN echo 'deb-src http://deb.nodesource.com/node_8.x xenial main' >> /etc/apt/sources.list.d/nodesource.list
RUN apt-get update && apt-get install -y nodejs
# -- Install HTML5 client
RUN apt-get install -y bbb-html5
# -- Install supervisor to run all the BigBlueButton processes (replaces systemd)
RUN apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# -- Modify FreeSWITCH event_socket.conf.xml to listen to IPV4
ADD mod/event_socket.conf.xml /opt/freeswitch/etc/freeswitch/autoload_configs
# -- Finish startup
ADD setup.sh /root/setup.sh
ENTRYPOINT ["/root/setup.sh"]
CMD []
So this is my docker-compose file. But that file not worked. I lack knowledge and qualification.
version: '3'
services:
bigbluebutton:
build: .
image: bigbluebutton/bigbluebutton
ports:
- "80:80"
expose:
- "1935/tcp"
- "5066/tcp"
- "2202"
Thanks for your answers.
just you need lines below in Docckerfiles becuse bbb need configure and this code passing this step;
`-RUN apt-get install -y bigbluebutton(remove)
+RUN apt-get install -y bigbluebutton || :
+RUN gem install bundler -v 1.16.1
+RUN apt-get install -y bigbluebutton
RUN apt-get install -y bbb-demo`
this is not bug just compile error.
I think you did not indent correctly expose subsection. I would write:
version: '3'
services:
bigbluebutton:
build: .
image: bigbluebutton/bigbluebutton
ports:
- "80:80"
expose:
- "1935/tcp"
- "5066/tcp"
- "2202"
If you use bigbluebutton/bigbluebutton image from DockerHub, you don't need neither build section nor Dockerfile itself.

Installing python using Dockerfile not working [duplicate]

I just made a very simple Docker file in my terminal, basically I did the following:
mkdir pgrouted
cd pgrouted
touch Dockerfile
Now I open the Docker file in the nano editor, and I add the following commands to the Docker file:
FROM ubuntu
MAINTAINER Gautam <gautamx07#yahoo.com>
LABEL Description="pgrouting excercise" Vendor="skanatek" Version="1.0"
ENV BBOX="-122.8,45.4,-122.5,45.6"
# Add pgRouting launchpad repository
RUN sudo apt-add-repository -y ppa:ubuntugis/ppa
RUN sudo apt-add-repository -y ppa:georepublic/pgrouting
RUN sudo apt-get update
# Install pgRouting package (for Ubuntu 14.04)
RUN sudo apt-get install postgresql-9.3-pgrouting
# Install osm2pgrouting package
RUN sudo apt-get install osm2pgrouting
# Install workshop material (optional, but maybe slightly outdated)
RUN sudo apt-get install pgrouting-workshop
# For workshops at conferences and events:
# Download and install from http://trac.osgeo.org/osgeo/wiki/Live_GIS_Workshop_Install
RUN wget --no-check-certificate https://launchpad.net/~georepublic/+archive/pgrouting/+files/pgrouting-workshop_2.0.6-ppa1_all.deb
RUN sudo dpkg -i pgrouting-workshop_2.0.6-ppa1_all.deb
# Review: Not sure weather this should be in the dockerfile
RUN cp -R /usr/share/pgrouting/workshop ~/Desktop/pgrouting-workshop
# Log in as user "user"
RUN psql -U postgres
# Create routing database
RUN CREATE DATABASE routing;
# Add PostGIS functions
RUN CREATE EXTENSION postgis;
# Add pgRouting core functions
CREATE EXTENSION pgrouting;
# Download using Overpass XAPI (larger extracts possible than with default OSM API)
wget --progress=dot:mega -O "sampledata.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][#meta]"
The entire Dockerfile can be see HERE at a glance.
Now when I try to build the Dockerfile, like so:
docker build -t gautam/pgrouted:v1 .
The Dockerfile runs and then I get the below error:
Step 4 : RUN sudo apt-add-repository -y ppa:ubuntugis/ppa
---> Running in c93c3c5fd5e8
sudo: apt-add-repository: command not found
The command '/bin/sh -c sudo apt-add-repository -y ppa:ubuntugis/ppa' returned a non-zero code: 1
Why am I getting this error?
apt-add-repository is just not in the base Ubuntu image. You'll first need to install it. try apt-get install software-properties-common
By the way, you don't need to use sudo in the Dockerfile because the commands run as root by default unless you change to another user with the USER command.
Add these lines before running apt-add-repository command
RUN apt-get update && \
apt-get install -y software-properties-common && \
rm -rf /var/lib/apt/lists/*
thats worked for me:
RUN apt-get update --fix-missing && \
apt-get install -y software-properties-common && \
rm -rf /var/lib/apt/lists/* && \
add-apt-repository ppa:ondrej/php && \
apt install -y nginx php7.4-fpm php7.4-mysql php7.4-curl net-tools telnet php7.4-gd php-mail php7.4 php7.4-common php7.4-sqlite3 php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-xml php7.4-cli php7.4-zip php7.4-soap unzip && \
rm -rf /var/lib/apt/lists/* && \
apt clean

Dockerinzing Play framework

I am developing a web app using play fraework2.6. I am trying to have java8, postgres and nginx in my dockerfile. Here's the docker file:
FROM ubuntu:14.04
#INSTALL
RUN \
echo "deb http://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list \
&& sudo apt-get update -y --force-yes \
&& sudo apt-get install -y --force-yes sbt
RUN apt-get update && apt-get -y upgrade && apt-get -y install software-properties-common && add-apt-repository ppa:webupd8team/java -y && apt-get update
RUN (echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections) && apt-get install -y oracle-java8-installer oracle-java8-set-default
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV PATH $JAVA_HOME/bin:$PATH
ENV SBT_OPTS="-Xmx2048M"
ENV SBT_OPTS="-XX:MaxPermSize=2048m"
# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# Add PostgreSQL's repository. It contains the most recent stable release
# of PostgreSQL, ``9.3``.
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3
# There are some warnings (in red) that show up during the build. You can hide
# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python-software-properties postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
# Install Nginx
RUN sudo apt-get install -y nginx
# RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf
# Note: The official Debian and Ubuntu images automatically ``apt-get clean``
# after each ``apt-get``
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed``
USER postgres
# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and
# then create a database `docker` owned by the ``docker`` role.
# Note: here we use ``&&\`` to run commands one after the other - the ``\``
# allows the RUN command to span multiple lines.
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER crm_play WITH SUPERUSER PASSWORD 'prod#123';" &&\
createdb -O crm_play crm_play
# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
# Expose the PostgreSQL port
EXPOSE 5432
# Add VOLUMEs to allow backup of config, logs and databases
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
# Set the default command to run when starting the container
# CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
WORKDIR /java/src/project
RUN sbt update
EXPOSE 9000
ENTRYPOINT ["sbt", "run"]
COPY . /java/src/project
First of all is this the correct way to do this. Also build takes too much of time to build. I am building like this:
docker build -t image:tag .
build downloads all dependencies in sbt and other dependencies mentioned in docker file. After that I run
docker run -it -p 9000:9000 image:tag
It again starts downloading all the dependencies. What I am doing wrong here?

apt-add-repository: command not found error in Dockerfile

I just made a very simple Docker file in my terminal, basically I did the following:
mkdir pgrouted
cd pgrouted
touch Dockerfile
Now I open the Docker file in the nano editor, and I add the following commands to the Docker file:
FROM ubuntu
MAINTAINER Gautam <gautamx07#yahoo.com>
LABEL Description="pgrouting excercise" Vendor="skanatek" Version="1.0"
ENV BBOX="-122.8,45.4,-122.5,45.6"
# Add pgRouting launchpad repository
RUN sudo apt-add-repository -y ppa:ubuntugis/ppa
RUN sudo apt-add-repository -y ppa:georepublic/pgrouting
RUN sudo apt-get update
# Install pgRouting package (for Ubuntu 14.04)
RUN sudo apt-get install postgresql-9.3-pgrouting
# Install osm2pgrouting package
RUN sudo apt-get install osm2pgrouting
# Install workshop material (optional, but maybe slightly outdated)
RUN sudo apt-get install pgrouting-workshop
# For workshops at conferences and events:
# Download and install from http://trac.osgeo.org/osgeo/wiki/Live_GIS_Workshop_Install
RUN wget --no-check-certificate https://launchpad.net/~georepublic/+archive/pgrouting/+files/pgrouting-workshop_2.0.6-ppa1_all.deb
RUN sudo dpkg -i pgrouting-workshop_2.0.6-ppa1_all.deb
# Review: Not sure weather this should be in the dockerfile
RUN cp -R /usr/share/pgrouting/workshop ~/Desktop/pgrouting-workshop
# Log in as user "user"
RUN psql -U postgres
# Create routing database
RUN CREATE DATABASE routing;
# Add PostGIS functions
RUN CREATE EXTENSION postgis;
# Add pgRouting core functions
CREATE EXTENSION pgrouting;
# Download using Overpass XAPI (larger extracts possible than with default OSM API)
wget --progress=dot:mega -O "sampledata.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][#meta]"
The entire Dockerfile can be see HERE at a glance.
Now when I try to build the Dockerfile, like so:
docker build -t gautam/pgrouted:v1 .
The Dockerfile runs and then I get the below error:
Step 4 : RUN sudo apt-add-repository -y ppa:ubuntugis/ppa
---> Running in c93c3c5fd5e8
sudo: apt-add-repository: command not found
The command '/bin/sh -c sudo apt-add-repository -y ppa:ubuntugis/ppa' returned a non-zero code: 1
Why am I getting this error?
apt-add-repository is just not in the base Ubuntu image. You'll first need to install it. try apt-get install software-properties-common
By the way, you don't need to use sudo in the Dockerfile because the commands run as root by default unless you change to another user with the USER command.
Add these lines before running apt-add-repository command
RUN apt-get update && \
apt-get install -y software-properties-common && \
rm -rf /var/lib/apt/lists/*
thats worked for me:
RUN apt-get update --fix-missing && \
apt-get install -y software-properties-common && \
rm -rf /var/lib/apt/lists/* && \
add-apt-repository ppa:ondrej/php && \
apt install -y nginx php7.4-fpm php7.4-mysql php7.4-curl net-tools telnet php7.4-gd php-mail php7.4 php7.4-common php7.4-sqlite3 php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-xml php7.4-cli php7.4-zip php7.4-soap unzip && \
rm -rf /var/lib/apt/lists/* && \
apt clean

Resources