How to add couchdb server into docker creation file - docker

I have a docker file like this :
FROM ubuntu:12.04
MAINTAINER me <me#c.com>
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install supervisor \
apache2 \
mysql-server \
php5 \
libapache2-mod-php5 \
php5-mysql \
php5-mcrypt
#ssh
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed 's#session\s*required\s*pam_loginuid.so#session optional pam_loginuid.so#g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22 80
ADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
My question is how do I add a couchdb server into this docker file?
I can get a built-in couchdb docker image from here : https://hub.docker.com/r/klaemo/couchdb/, but how do I create a image like this my self? I can't find any documentation regarding the process!
I spent 3 hours tried to googled but got no luck, so I will take the risk to ask even if this is a dump question!

Is there a specific version of couchdb that you want in your docker container?
If not, since you are using Ubuntu 12.04 as your base image, you can get the couchdb 1.0.1 binaries from the Ubuntu 12.04/precise [universe] repository easily by adding couchdb to your apt-get list like this:
FROM ubuntu:12.04
MAINTAINER me <me#c.com>
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install supervisor \
apache2 \
mysql-server \
php5 \
libapache2-mod-php5 \
php5-mysql \
php5-mcrypt \
couchdb
#[--Rest of your dockerfile goes here unchanged--]
You can alternatively use the PPA maintained by the Apache CouchDB team to get latest stable releases for your base image based on the officially released tar balls. For this option you can use the following dockerfile:
# To install the ppa finder tool in your docker container
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install python-software-properties
RUN add-apt-repository ppa:couchdb/stable -y
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install supervisor \
apache2 \
mysql-server \
php5 \
libapache2-mod-php5 \
php5-mysql \
php5-mcrypt \
couchdb
#[--Rest of your dockerfile goes here unchanged--]
If you want the latest or a specific version of couchdb in your docker container then you might have to build couchdb from the source code. Note that this approach will require you to install many more packages (g++ erlang-dev erlang-manpages erlang-base-hipe erlang-eunit, libmozjs185-dev libicu-dev libcurl4-gnutls-dev libtool) onto your container to be able to build couchdb from source. However you may be able to purge/remove the packages that are required only to build couchdb. The complete list of dependencies can be found on the official couchdb build wiki on apache. If you really want THE latest version then you can refer to this dockerfile and add update your dockerfile accordingly. Here is a complete dockerfile [UNTESTED] for your ease of use:
FROM ubuntu:12.04
MAINTAINER me <me#c.com>
ENV COUCHDB_VERSION master
RUN groupadd -r couchdb && useradd -d /usr/src/couchdb -g couchdb couchdb
# download dependencies
RUN apt-get update -y -qq && apt-get install -y --no-install-recommends \
build-essential \
erlang-dev \
erlang-manpages \
erlang-base-hipe \
erlang-eunit \
erlang-nox \
erlang-xmerl \
erlang-inets \
libmozjs185-dev \
libicu-dev \
libcurl4-gnutls-dev \
libtool
RUN cd /usr/src && git clone https://git-wip-us.apache.org/repos/asf/couchdb.git \
&& cd couchdb && git checkout $COUCHDB_VERSION \
&& cd /usr/src/couchdb && ./configure && make
# You can optionally purge/remove the packages you installed to build the couchdb from source.
# permissions
RUN chmod +x /usr/src/couchdb/dev/run && chown -R couchdb:couchdb /usr/src/couchdb
USER couchdb
EXPOSE 5984 15984 25984 35984 15986 25986 35986
#[--Rest of your dockerfile can go here as required--]

Related

Kartoza Geoserver on Heroku

I am new to docker and not an IT-specialist. I try to install Kartoza Geoserver in Docker on Heroku, but so far no success. Does anyone has experience with this and can explain me the settings in the dockerfile and the steps specifically for a Heroku install?
So far I tried a build with a modified dockerfile but I always get the same error (in the log trail) when opening/launching geoserver on Heroku:
"Error: groupadd: cannot open /etc/group".
I guess it is an permission/privileges issue.
Any sharing of experience on modifying the docker file so that the image is read by Heroku would be helpfull.
Modifying the settings in the dockerfile:
Removed the port forwarding from dockerfile
Add RUN adduser -D myuser USER myuser to dockerfile
Result dockerfile:
#--------- Generic stuff all our Dockerfiles should start with so we get caching ------------
ARG IMAGE_VERSION=9.0.65-jdk11-openjdk-slim-buster
ARG JAVA_HOME=/usr/local/openjdk-11
FROM tomcat:$IMAGE_VERSION
LABEL maintainer="Tim Sutton<tim#linfiniti.com>"
ARG GS_VERSION=2.22.0
ARG WAR_URL=https://downloads.sourceforge.net/project/geoserver/GeoServer/${GS_VERSION}/geoserver-${GS_VERSION}-war.zip
ARG STABLE_PLUGIN_BASE_URL=https://sourceforge.net/projects/geoserver/files/GeoServer
ARG DOWNLOAD_ALL_STABLE_EXTENSIONS=1
ARG DOWNLOAD_ALL_COMMUNITY_EXTENSIONS=1
ARG HTTPS_PORT=8443
ENV DEBIAN_FRONTEND=noninteractive
#Install extra fonts to use with sld font markers
RUN adduser -D myuser
USER myuser
RUN set -eux; \
apt-get update; \
apt-get -y --no-install-recommends install \
locales gnupg2 wget ca-certificates rpl pwgen software-properties-common iputils-ping \
apt-transport-https curl gettext fonts-cantarell lmodern ttf-aenigma \
ttf-bitstream-vera ttf-sjfonts tv-fonts libapr1-dev libssl-dev \
wget zip unzip curl xsltproc certbot cabextract gettext postgresql-client figlet gosu gdal-bin; \
# Install gdal3 - bullseye doesn't build libgdal-java anymore so we can't upgrade
curl https://deb.meteo.guru/velivole-keyring.asc | apt-key add - \
&& echo "deb https://deb.meteo.guru/debian buster main" > /etc/apt/sources.list.d/meteo.guru.list \
&& apt-get update \
&& apt-get -y --no-install-recommends install gdal-bin libgdal-java; \
dpkg-divert --local --rename --add /sbin/initctl \
&& (echo "Yes, do as I say!" | apt-get remove --force-yes login) \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*; \
# verify that the binary works
gosu nobody true
ENV \
JAVA_HOME=${JAVA_HOME} \
DEBIAN_FRONTEND=noninteractive \
GEOSERVER_DATA_DIR=/opt/geoserver/data_dir \
GDAL_DATA=/usr/share/gdal \
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/tomcat/native-jni-lib:/usr/lib/jni:/usr/local/apr/lib:/opt/libjpeg-turbo/lib64:/usr/lib:/usr/lib/x86_64-linux-gnu" \
FOOTPRINTS_DATA_DIR=/opt/footprints_dir \
GEOWEBCACHE_CACHE_DIR=/opt/geoserver/data_dir/gwc \
CERT_DIR=/etc/certs \
RANDFILE=/etc/certs/.rnd \
FONTS_DIR=/opt/fonts \
GEOSERVER_HOME=/geoserver \
EXTRA_CONFIG_DIR=/settings \
COMMUNITY_PLUGINS_DIR=/community_plugins \
STABLE_PLUGINS_DIR=/stable_plugins
WORKDIR /scripts
ADD resources /tmp/resources
ADD build_data /build_data
ADD scripts /scripts
RUN echo $GS_VERSION > /scripts/geoserver_version.txt ;\
chmod +x /scripts/*.sh;/scripts/setup.sh \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN echo 'figlet -t "Kartoza Docker GeoServer"' >> ~/.bashrc
WORKDIR ${GEOSERVER_HOME}
ENTRYPOINT ["/bin/bash", "/scripts/entrypoint.sh"]
Then build it with argument --platform linux/amd64 (I use arm64 architecture). Then pushed it to Heroku. All the time I get the same error.

Shiny app (leafviz) in docker container not loading in browser

I am building a docker container to use the Leafcutter and Leafviz analysis tools. The final visualization commanded from an R file uses shiny app, it works fine on my machine but when ran in the container I can't connect to it.
I run the container with the following line of code:
docker run -dit --name leaf --rm -p 1234:1234 leafcutter
All is in order when I check with docker ps:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
783f550df965 leafcutter "bash" 2 minutes ago Up 2 minutes 0.0.0.0:1234->1234/tcp, :::1234->1234/tcp leaf
Executing the pipeline in the container calls several snakefiles, and the last rule of the last one calls the R file:
Rscript /path/to/run_leafviz.R -i {input}
That script calls several functions before calling leafviz() which basically just runs the shiny app, I've modified the options like so:
shiny::runApp(launch.browser=FALSE, appDir = system.file("application", package = "leafviz"), host = "0.0.0.0", port = 1234)
All the shiny files and packages are installed with the R leafviz package. When I execute my container all goes fine, the output shows "Listening on http://0.0.0.0:1234", but when I try to connect I get the "connexion failed" page.
My Dockerfile is fairly large but here are the most relevant parts:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
#Install Ubuntu packages
RUN apt-get update && apt-get install \
-y cmake -y curl \
-y default-jre \
-y gdebi-core \
-y less -y libarchive13 -y libbz2-dev -y libcairo2-dev -y libcurl4-openssl-dev -y libgsl-dev \
-y liblzma-dev -y libncurses5-dev -y libncursesw5-dev -y libssl-dev -y libxml2-dev -y libxt-dev \
-y pandoc -y pandoc-citeproc -y python-pip \
-y tabix \
-y unzip \
-y wget \
-y zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
#Install conda, snakemake, samtools, regtools...
#[...]
#Install R
LABEL org.label-schema.license="GPL-2.0" \
org.label-schema.vcs-url="https://github.com/rocker-org/r-apt" \
org.label-schema.vendor="Rocker Project" \
maintainer="Dirk Eddelbuettel <edd#debian.org>"
RUN useradd docker \
&& mkdir /home/docker \
&& chown docker:docker /home/docker \
&& addgroup docker staff
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
littler r-base r-base-dev r-recommended r-cran-docopt
RUN ln -s /usr/lib/R/site-library/littler/examples/install.r /usr/local/bin/install.r \
&& ln -s /usr/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r \
&& ln -s /usr/lib/R/site-library/littler/examples/installGithub.r /usr/local/bin/installGithub.r \
&& ln -s /usr/lib/R/site-library/littler/examples/testInstalled.r /usr/local/bin/testInstalled.r \
&& rm -rf /tmp/downloaded_packages/ /tmp/*.rds \
&& rm -rf /var/lib/apt/lists/*
#Install shiny server (I have tried with and without this RUN command)
RUN wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
VERSION=$(cat version.txt) && \
wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
gdebi -n ss-latest.deb && \
rm -f version.txt ss-latest.deb
EXPOSE 1234
#Install R packages
COPY install_packages.R /tmp/install_packages.R
RUN Rscript /tmp/install_packages.R
CMD ["bash"]
I've been learning docker quite chaotically so I don't know if some elements are clashing, but I have exposed the container port and published it to the host and no error message seems to indicate there is a problem coming from somewhere else. I would really appreciate some help.

`bash: webots: command not found` in my docker container because of multiple FROMs

I have a docker container that has Webots and ROS2 installed. However, running webots while inside the container returns bash: webots: command not found. Why?
Container that does run webots (but no ROS2)
Here's a container run from the Webots installation instructions that DOES successfully run webots (but lacks ROS2 like I need):
$ xhost +local:root > /dev/null 2>&1 #so webots won't say unable to load Qt platform plugin "xcb"
$ docker run -it -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw cyberbotics/webots:R2021a-ubuntu20.04
Container that does NOT run webots
Here's my docker container which does NOT successfully run webots, but instead says bash: webots: command not found. However, it DOES successfully run webots_ros2 demos (I think the issue has to do with how I'm inheriting from two containers, because if I swap the order of my two ARG and FROM statements, webots is found but ros2 is not. I'm not sure the solution though):
Dockerfile
# inherit both the ROS2 and Webots containers
ARG BASE_IMAGE_WEBOTS=cyberbotics/webots:R2021a-ubuntu20.04
ARG IMAGE_ROS2=niurover/ros2_foxy:latest
FROM $BASE_IMAGE_WEBOTS AS base
FROM $IMAGE_ROS2 AS image_ros2
# resolve a missing dependency for webots demo
RUN apt-get update && apt-get install -y \
libxtst6 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Finally open a bash command to let the user interact
CMD ["/bin/bash"]
launch.sh (used to launch docker container)
#! /bin/bash
CONTAINER_USER=$USER
CONTAINER_NAME=webots_ros2_foxy
USER_ID=$UID
IMAGE=niurover/webots_ros2_foxy:latest
if [ $(uname -r | sed -n 's/.*\( *Microsoft *\).*/\1/ip') ];
then
xhost +local:$CONTAINER_USER
xhost +local:root
fi
sudo docker run -it --rm \
--name $CONTAINER_NAME \
--user=$USER_ID\
--env="DISPLAY" \
--env="CONTAINER_NAME=$CONTAINER_NAME" \
--workdir="/home/$CONTAINER_USER" \
--volume="/home/$CONTAINER_USER:/home/$CONTAINER_USER" \
--volume="/etc/group:/etc/group:ro" \
--volume="/etc/passwd:/etc/passwd:ro" \
--volume="/etc/shadow:/etc/shadow:ro" \
--volume="/etc/sudoers.d:/etc/sudoers.d:ro" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
$IMAGE bash\
if [ $(uname -r | sed -n 's/.*\( *Microsoft *\).*/\1/ip') ];
then
xhost -local:$CONTAINER_USER
xhost -local:root
fi
Summary
As you can see, both containers use cyberbotics/webots:R2021a-ubuntu20.04, and the second container uses all of the options of the first container, but with some extras. Why does the first container run webots successfully, while the second container can't find the command?
I ended up using Leonardo Dagnino's suggestion, and it worked. I had to copy a couple successive ROS2 containers' contents to make the tree hierarchy work off of the webots base image, but it got me where I was going. For prosperity, here is the new Dockerfile in full:
# Use Webots docker container as base
ARG BASE_IMAGE_WEBOTS=cyberbotics/webots:R2021a-ubuntu20.04
FROM $BASE_IMAGE_WEBOTS AS base
# ==================================================================================
# niurover/ros2_foxy uses osrf/ros:foxy-desktop as its base, so I need to add code from
# container heirarchy all the way back to where it can stem off of `base` from above
# ==================================================================================
# ----------------------------------------------------------------------------------
# taken from Dockerfile for ros:foxy-ros-core-focal found at:
# https://github.com/osrf/docker_images/blob/master/ros/foxy/ubuntu/focal/ros-core/Dockerfile
# ----------------------------------------------------------------------------------
## setup timezone # NOTE commented out since timezone should already be set up
#RUN echo 'Etc/UTC' > /etc/timezone && \
# ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
# apt-get update && \
# apt-get install -q -y --no-install-recommends tzdata && \
# rm -rf /var/lib/apt/lists/*
# install packages
RUN apt-get update && apt-get install -q -y --no-install-recommends \
dirmngr \
gnupg2 \
&& rm -rf /var/lib/apt/lists/*
# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
# setup sources.list
RUN echo "deb http://packages.ros.org/ros2/ubuntu focal main" > /etc/apt/sources.list.d/ros2-latest.list
# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV ROS_DISTRO foxy
# install ros2 packages
RUN apt-get update && apt-get install -y --no-install-recommends \
ros-foxy-ros-core=0.9.2-1* \
&& rm -rf /var/lib/apt/lists/*
## setup entrypoint # NOTE ignore this part of their Dockerfile
#COPY ./ros_entrypoint.sh /
#
#ENTRYPOINT ["/ros_entrypoint.sh"]
#CMD ["bash"]
# ----------------------------------------------------------------------------------
# taken from Dockerfile for ros:foxy-ros-base-focal found at:
# https://github.com/osrf/docker_images/blob/master/ros/foxy/ubuntu/focal/ros-base/Dockerfile
# ----------------------------------------------------------------------------------
# install bootstrap tools
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
git \
python3-colcon-common-extensions \
python3-colcon-mixin \
python3-rosdep \
python3-vcstool \
&& rm -rf /var/lib/apt/lists/*
# bootstrap rosdep
RUN rosdep init && \
rosdep update --rosdistro $ROS_DISTRO
# setup colcon mixin and metadata
RUN colcon mixin add default \
https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml && \
colcon mixin update && \
colcon metadata add default \
https://raw.githubusercontent.com/colcon/colcon-metadata-repository/master/index.yaml && \
colcon metadata update
# install ros2 packages
RUN apt-get update && apt-get install -y --no-install-recommends \
ros-foxy-ros-base=0.9.2-1* \
&& rm -rf /var/lib/apt/lists/*
# ----------------------------------------------------------------------------------
# taken from Dockerfile for osrf/ros:foxy-desktop-focal (or is it osrf/ros:foxy-desktop?) found at:
# https://github.com/osrf/docker_images/blob/master/ros/foxy/ubuntu/focal/desktop/Dockerfile
# ----------------------------------------------------------------------------------
# This is an auto generated Dockerfile for ros:desktop
# generated from docker_images_ros2/create_ros_image.Dockerfile.em
#FROM ros:foxy-ros-base-focal # NOTE commented out since satisfied by above
# install ros2 packages
RUN apt-get update && apt-get install -y --no-install-recommends \
ros-foxy-desktop=0.9.2-1* \
&& rm -rf /var/lib/apt/lists/*
# ----------------------------------------------------------------------------------
# taken from Dockerfile for niurover/ros2_foxy found at:
# https://github.com/NIURoverTeam/Dockerfiles/blob/master/ros2_foxy/Dockerfile
# ----------------------------------------------------------------------------------
#ARG BASE_IMAGE=osrf/ros:foxy-desktop # NOTE commented out since satisfied by above
# Install work packages
#FROM $BASE_IMAGE as base # NOTE commented out since satisfied by above
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
tmux \
curl \
wget \
vim \
sudo \
unzip \
python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install ROS Packages
RUN apt-get update && apt-get install -y \
ros-foxy-turtlesim \
~nros-foxy-rqt* \
ros-foxy-teleop-tools \
ros-foxy-joy-linux \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install pyserial
#CMD ["bash"] # NOTE ignore this part of the Dockerfile
# ----------------------------------------------------------------------------------
# new stuff added on top of niurover/ros2_foxy to assist with Webots + ROS2
# ----------------------------------------------------------------------------------
# resolve a missing dependency for webots demo
RUN apt-get update && apt-get install -y \
libxtst6 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Finally open a bash command to let the user interact
CMD ["/bin/bash"]
When you have multiple FROM commands, you're not "inheriting" both of their contents into the same image - you're doing a multi-stage build. This allows you to COPY from that stage specifying the --from option. By default, the last stage in your Dockerfile will be the target (so, in your example, you're only actually using the ros2 image. The webots image is not actually being used there.
You have two options here:
Copy just the files you need from the webots image using COPY --from=base
This will probably be hard and finicky. You'll need to copy all dependencies; and if they're acquired through your package manager (apt-get), you'll leave dpkg's local database inconsistent.
Copy one of the Dockerfiles and change their FROM
This will probably work fine as long as they both use the same base distribution. You can go into one of the project's repositories and grab their Dockerfile, rebuilding it from the other image - just change, for example, cyberbotics/webots:R2021a-ubuntu20.04's Dockerfile to have FROM niurover/ros2_foxy:latest. It may require tinkering with the other commands there, though.

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

Multiple dependent ? Dockerfiles building a LAMP container

I'm trying to build a LAMP container and I have already built several containers: httpd 2.4.23, redis 3.0.7, mysql 5.6.30 by compiling them myself from source code downloaded archives. I have based all of these above on the debian container.
Now that I'm doing the php 5.6.20 container it complains that it does not know about apache and mysql.
Here is the Dockerfile for the php container:
FROM debian
RUN apt-get update
RUN apt-get install -y build-essential;
RUN apt-get install -y cmake;
RUN apt-get install -y libfreetype6-dev libjpeg-dev libpng12-dev libcurl4-openssl-dev libbz2-dev libxml2-dev libxslt-dev libgd2-xpm-dev php5-imap libz-dev
WORKDIR /usr/bin/
COPY php-5.6.20.tar.gz /usr/bin/
RUN gzip -d php-5.6.20.tar.gz
RUN tar -xvf php-5.6.20.tar
RUN ln -s php-5.6.20 php
WORKDIR /usr/bin/php/
RUN ./configure \
--prefix=/usr/bin/ \
--with-apxs2=/usr/bin/apache/bin/apxs \
--with-config-file-path=/usr/bin/php-5.6.20/ \
--enable-libgcc \
--with-mysqli=/usr/bin/mysql/mysql_config \
--with-zlib-dir=/usr \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-gd \
--enable-gd-native-ttf \
--with-freetype-dir=/usr \
--enable-ftp \
--enable-xml \
--enable-zip \
--with-bz2 \
--enable-wddx \
--without-pear \
--enable-mbstring \
--with-curl
RUN make
RUN make install
I wonder if I should base it instead on: FROM httpd:2.4.23. But then I would need to base httpd on the mysql one, and / or on the redis one... I don't really like that setup.
I have also installed Docker Compose but I wonder if it could be helpful in my situation.
UPDATE: Here is the fully working Dockerfile
FROM debian
RUN apt-get update
RUN apt-get install -y build-essential;
RUN apt-get install -y cmake;
RUN apt-get install -y openssl libssl-dev;
RUN apt-get install -y libpcre3 libpcre3-dev
WORKDIR /usr/bin/
COPY httpd-2.4.23.tar.gz /usr/bin/
RUN gzip -d httpd-2.4.23.tar.gz
RUN tar -xvf httpd-2.4.23.tar
RUN ln -s httpd-2.4.23 httpd
COPY apr-1.5.2.tar.gz /usr/bin/httpd/srclib/
COPY apr-util-1.5.4.tar.gz /usr/bin/httpd/srclib/
WORKDIR /usr/bin/httpd/srclib/
RUN gzip -d apr-1.5.2.tar.gz
RUN gzip -d apr-util-1.5.4.tar.gz
RUN tar -xvf apr-1.5.2.tar
RUN tar -xvf apr-util-1.5.4.tar
RUN ln -s apr-1.5.2 apr;
RUN ln -s apr-util-1.5.4 apr-util
WORKDIR /usr/bin/httpd/
RUN ./configure \
--prefix=/usr/bin/apache \
--enable-rewrite \
--enable-deflate \
--enable-ssl
RUN make
RUN make install
RUN apt-get update
RUN apt-get install -y libncurses-dev
COPY mysql-5.6.30.tar.gz /usr/bin/
WORKDIR /usr/bin/
RUN gzip -d mysql-5.6.30.tar.gz
RUN tar -xvf mysql-5.6.30.tar
RUN ln -s mysql-5.6.30 mysql
WORKDIR /usr/bin/mysql/
RUN mkdir install; mkdir install/data; mkdir install/var; mkdir install/etc; mkdir install/tmp
RUN cd /usr/bin/mysql/; cmake \
-DCMAKE_INSTALL_PREFIX=/usr/bin/mysql/install \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/bin/mysql/install/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/bin/mysql/install/boost \
-DMYSQL_UNIX_ADDR=/usr/bin/mysql/install/tmp/mysql.sock
RUN make
RUN make install
RUN apt-get update
RUN apt-get install -y libfreetype6-dev libjpeg-dev libpng12-dev libcurl4-openssl-dev libbz2-dev libxml2-dev libxslt-dev libgd2-xpm-dev php5-imap libz-dev
WORKDIR /usr/bin/
COPY php-5.6.20.tar.gz /usr/bin/
RUN gzip -d php-5.6.20.tar.gz
RUN tar -xvf php-5.6.20.tar
RUN ln -s php-5.6.20 php
WORKDIR /usr/bin/php/
RUN ./configure \
--prefix=/usr/bin/php \
--with-apxs2=/usr/bin/apache/bin/apxs \
--with-config-file-path=/usr/bin/php-5.6.20/ \
--enable-libgcc \
--with-mysqli=/usr/bin/mysql/install/bin/mysql_config \
--with-zlib-dir=/usr \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-gd \
--enable-gd-native-ttf \
--with-freetype-dir=/usr \
--enable-ftp \
--enable-xml \
--enable-zip \
--with-bz2 \
--enable-wddx \
--without-pear \
--enable-mbstring \
--with-openssl
--with-curl
RUN make
RUN make install
ENTRYPOINT ["/usr/bin/apache/bin/apachectl", "start", "-D FOREGROUND"]
EXPOSE 80
# Build the container: docker build -t stephaneeybert/httpd:2.4.23 .
# Run the container: docker run -d -p 127.0.0.1:80:80 --name httpd stephaneeybert/httpd:2.4.23
# Check that the port is open: nmap -p 8081 localhost
If you need apache running in your container, you can install apache in your image with above Dockerfile, just as the same as you install the build-essential stuffs. Which means:
RUN apt-get install -y apache2
or similar command. If you also need the configure for this apache application, you can use ADD or COPY command to add your configure file from outside to inside of your container. More details can be found here.
If you need apache as an independent container, you can use docker-compse to achieve it. Start apache in another container, then use depends_on to config the dependency between your containers. You may use ports to change the port number of each container, so they can communicate between each other.

Resources