Cannot install php, apache and postgres on ubuntu base image in dockerfile - docker

I started studying docker recently and wanted to install php, apache and postgres in a ubuntu base image. But cannot run it after build.
Here is my Dockerfile
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get -qq -y install curl
RUN apt-get -y install apache2
RUN apt-get -y install php7.0
RUN apt-get -y install libapache2-mod-php7.0
RUN apt-get -y install php7.0-mysql
RUN apt-get -y install php7.0-pgsql
RUN apt-get -y install php7.0-gd
RUN apt-get -y install php-pear
RUN apt-get -y install php7.0-curl
COPY . /var/www/html
EXPOSE 80
Can you please help me?
Thanks.

there are several issues here. First of all, I have the impression that you're mixing up docker and virtual machines. For this I suggest to go and read what are the differences.
Concerning your question, the problem is that the base image (ubuntu:16.04) has CMD bash (or something similar, I really didn't check) and therefore php is not considered.
In order to start apache, you should append the following:
CMD . /etc/apache2/envvars && /usr/sbin/apache2ctl -DFOREGROUND
Anyway, I'd suggest you give a check to the php official image.

Related

Man pages not being installed in python docker image [duplicate]

I use the following Dockerfile to build an image and start a container. But once I am in the container, I still can not find manpages. Does anybody know how to solve this problem?
$ cat Dockerfile
FROM ubuntu
RUN apt -y update && apt -y upgrade
RUN apt-get -y install build-essential
RUN apt-get -y install vim
RUN apt-get -y install man
RUN apt-get -y install gawk
RUN apt-get -y install mawk
$ man man
No manual entry for man
See 'man 7 undocumented' for help when manual pages are not available.
$ find /usr/share/man /usr/local/share/man -type f
You need to make a change to your /etc/dpkg/dpkg.cfg.d/excludes within the container. You can do this in your Dockerfile with the following command:
RUN sed -i 's:^path-exclude=/usr/share/man:#path-exclude=/usr/share/man:' \
/etc/dpkg/dpkg.cfg.d/excludes
Then make another update to your Dockerfile to install the man pages
RUN apt-get update && \
apt-get install -y \
man \
manpages-posix
There is a easier way to enable the MAN command.
In terminal, just execute the command below:
unminimize
It will ask if you like to continue [Y/n]
Just press:
Y
It will take a while to finish all the processing.
After that, test this:
man man
Simple as that
Thanks to #kazushi

Docker build stops on software-properties-common when run with `apt update`

I have 2 dockerfiles:
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y \
software-properties-common \
python3
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-get update && apt-get install -y \
python3
The thing is: when I run the first of them (with docker build) the build process hangs on:
The software-properties-common package is asking me about the geographical area - I cannot provide any input, it is not allowed when building images, I suppose.
However, when I build the second dockerfile, this problem does not occur. I'm curious - why is that?
Add the following line in your Dockerfile and build again.
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
I found that running
ln -fs /usr/share/zoneinfo/UTC /etc/localtime
before setting DEBIAN_FRONTEND=noninteractive worked for me. (You'd want to replace the bit after zoneinfo with whatever is applicable for you.)
If you need it to be set dynamically, [this answer] (https://stackoverflow.com/a/63153978/1995015) suggests calling out to a website that can provide that.

Docker: cannot install openssh-server

I build the Docker based on Ubuntu 16 and want to allow PuTTY access to the Ubuntu.
I have added the line to the docker file:
#Download base image ubuntu 16.04
FROM ubuntu:16.04
# Update Software repository
RUN apt-get update
# Install nginx, php-fpm and supervisord from ubuntu repository
RUN apt-get install -y nginx php7.0-fpm supervisor && \
rm -rf /var/lib/apt/lists/*
RUN apt-get autoclean -y supervisor
RUN apt-get install openssh-server -y supervisor
But when I build the image it gives me
Step 5/18 : RUN apt-get install openssh-server -y supervisor --->
Running in c9425deece29 Reading package lists... Building dependency
tree... Reading state information... E: Unable to locate package
openssh-server
How to fix it? My task is: to allow connection from a host (Windows) to the docker container via PuTTY.
Following Dockerfile should work.
#Download base image ubuntu 16.04
FROM ubuntu:16.04
# Update Software repository
RUN apt-get update && \
apt-get upgrade -y
RUN apt-get install openssh-server -y supervisor
# Install nginx, php-fpm and supervisord from ubuntu repository
RUN apt-get install -y nginx php7.0-fpm supervisor && \
rm -rf /var/lib/apt/lists/*
RUN apt-get autoclean -y supervisor
There is two thing it seems problematic to me.
After update I'm always using upgrade to update all packages on my system. It's not necessary but I find it's a good practice
You are removing /var/lib/apt/lists/ * then you are trying to install openssh-server. apt can't find anything on that path when it need.

Building Go Application using confluent-kafka-go on Linux

I am trying to create a docker image with my go application. The application (which was developed on MacOS) depends on confluent-kafka-go which in turn depends on librdkafka-dev which I install in the Docker image like so:
FROM golang:1.1
RUN apt-get update
RUN apt-get -y install librdkafka-dev
VOLUME /workspace
WORKDIR /workspace/src/my/app/folder
ENTRYPOINT ["/bin/sh", "-c"]
I am getting the following error:
my/app/folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka
../folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka/00version.go:44:2: error: #error "confluent-kafka-go requires librdkafka v0.11.5 or later. Install the latest version of librdkafka from the Confluent repositories, see http://docs.confluent.io/current/installation.html"
As far as I understand the latest version is installed.
How can I fix it?
I had a similar issue a few weeks ago. IIRC confluent-kafka-go requires a recent version of librdkafka-dev, which simply was not yet released to alpine or others.
I was able to find it for ubuntu though, so my solution (which was more involved than I hoped for, but it worked), was to start from clean ubuntu, install librdkafka-dev, install Go version that I want and compile inside docker.
Here's how it looks:
FROM ubuntu
# Install the C lib for kafka
RUN apt-get update
RUN apt-get install -y --no-install-recommends apt-utils wget gnupg software-properties-common
RUN apt-get install -y apt-transport-https ca-certificates
RUN wget -qO - https://packages.confluent.io/deb/5.1/archive.key | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/5.1 stable main"
RUN apt-get update
RUN apt-get install -y librdkafka-dev
# Install Go
RUN add-apt-repository ppa:longsleep/golang-backports
RUN apt-get update
RUN apt-get install -y golang-1.11-go
# build the library
WORKDIR /go/src/gitlab.appsflyer.com/rantav/kafka-mirror-tester
COPY *.go ./
COPY // the rest of your go files. You may copy recursive if you want
COPY vendor vendor
RUN GOPATH=/go GOOS=linux /usr/lib/go-1.11/bin/go build -a -o main .
EXPOSE 8000
ENTRYPOINT ["./main"]
You can specify a version of package to be installed in apt-get command.
e.g
apt-get install librdkafka-dev=0.11.6~1confluent5.0.1-1
If that doesn't work then I think the apt sources doesn't have version 0.11.5 of librdkafka.
You can add a repository with the right version of librdkafka in /etc/apt/sources.list as described here:
https://docs.confluent.io/current/installation/installing_cp/deb-ubuntu.html#systemd-ubuntu-debian-install

How to install man pages on an ubuntu docker image?

I use the following Dockerfile to build an image and start a container. But once I am in the container, I still can not find manpages. Does anybody know how to solve this problem?
$ cat Dockerfile
FROM ubuntu
RUN apt -y update && apt -y upgrade
RUN apt-get -y install build-essential
RUN apt-get -y install vim
RUN apt-get -y install man
RUN apt-get -y install gawk
RUN apt-get -y install mawk
$ man man
No manual entry for man
See 'man 7 undocumented' for help when manual pages are not available.
$ find /usr/share/man /usr/local/share/man -type f
You need to make a change to your /etc/dpkg/dpkg.cfg.d/excludes within the container. You can do this in your Dockerfile with the following command:
RUN sed -i 's:^path-exclude=/usr/share/man:#path-exclude=/usr/share/man:' \
/etc/dpkg/dpkg.cfg.d/excludes
Then make another update to your Dockerfile to install the man pages
RUN apt-get update && \
apt-get install -y \
man \
manpages-posix
There is a easier way to enable the MAN command.
In terminal, just execute the command below:
unminimize
It will ask if you like to continue [Y/n]
Just press:
Y
It will take a while to finish all the processing.
After that, test this:
man man
Simple as that
Thanks to #kazushi

Resources