alpine docker image for cakephp - alpine-linux

I am struggling trying to dockerize an app for CakePHP 3. I already did with a PHP apache image but it is pretty big, for that reason I am trying to dockerize the app in an alpine container. I also need npm, but I cannot install npm, I have received a lot of errors during the build. After executing the container the "npm" command is "not found" either.
This is the docker file I have:
FROM php:7.4-fpm-alpine
ARG ENV=development
ARG UID=1000
ARG HOST_OS=Linux
ENV APP_ENV=$ENV
ENV HOST_OS=$HOST_OS
RUN apk add --update nodejs-current npm
WORKDIR /var/www/html/webroot // The package.json is here.
# Setup GD extension
RUN apk add --no-cache \
bash \
curl \
supervisor \
freetype \
libjpeg-turbo \
libpng \
freetype-dev \
libzip-dev \
libjpeg-turbo-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-enable gd \
&& apk del --no-cache \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
&& rm -rf /tmp/*
RUN npm install -g npm
RUN docker-php-ext-install pdo_mysql zip bcmath
The errors:
build/libtool.m4:70: AC_LIBTOOL_SETUP is expanded from...
build/libtool.m4:52: _AC_PROG_LIBTOOL is expanded from...
build/libtool.m4:39: AC_PROG_LIBTOOL is expanded from...
configure.ac:161: the top level
configure.ac:161: warning: The macro `AC_LANG_C' is obsolete.
configure.ac:161: You should run autoupdate.
./lib/autoconf/c.m4:72: AC_LANG_C is expanded from...
lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from...
./lib/autoconf/general.m4:2270: AC_CACHE_CHECK is expanded from...
build/libtool.m4:561: _LT_AC_LOCK is expanded from...
build/libtool.m4:1184: AC_LIBTOOL_SYS_HARD_LINK_LOCKS is expanded from...
build/libtool.m4:2727: _LT_AC_LANG_C_CONFIG is expanded from...
....... // I stoped here because there are more in red color.
UPDATE: The npm package is not installed, when I execute the container "npm -i" does not work, I can see "not found". I can install the package directly in the container, but it is not installed during the build.

Related

how to run an app with flutter-pi from a docker container

I'm running a flutter app on a raspberry pi 4, I'm using flutter-pi. Everything works fine, but I want to take it to a higher level.
I want to encapsulate the app and all flutter-pi dependencies in a docker container.
I am using the ubuntu:jammy image as a base, I have installed all the dependencies according to flutter-pi.
When I run the app I get this error:
[locales] Warning: The system has no configured locale. The default "C" locale may or may not be supported by the app.
[keyboard] Could not load keyboard configuration from "/etc/default/keyboard". Default keyboard config will be used. load_file: No such file or directory
[flutter-pi] Could not query DRM device list: No such file or directory
NOTE: the raspberry is configured to do a console auto login and does not have a graphical interface
I have developed a flutter-pi application and encapsulated it in a container.
What I noticed is that this error (Could not query DRM device list: No such file or directory) happens to me only sometimes, the configuration is always the same but sometimes I faced it and some times I didn't.
I'm assuming it is related with the host system in which the docker containers are running, because as I previously said the configuration of the container is always the same in both the working container and the not working one.
I'm attaching down below the configuration of my dockerfile (it's made of 2 dockerfiles but it's only 1 container that I'm running, the second dockerfile uses the first one which is built in emotionsrl/tower-display-base).
The display_launcher.py only runs the flutter (flutter-pi --release ./spotlink_build) after a few checks that are not related with the rest.
FROM ubuntu
RUN apt -y update \
&& apt -y install git \
&& apt -y install wget \
&& apt -y install build-essential
WORKDIR /TOWER_DISPLAY
# STEP 1 DIPENDENZE
RUN git clone --depth 1 \
https://github.com/ardera/flutter-engine-binaries-for-arm.git \
engine-binaries && cd engine-binaries && ./install.sh
# STEP 2 DIPENDENZE
ENV TZ=Europe/Rome
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt -y install cmake \
libgl1-mesa-dev \
libgles2-mesa-dev \
libegl1-mesa-dev \
libdrm-dev \
libgbm-dev
RUN DEBIAN_FRONTEND='noninteractive' apt -y install ttf-mscorefonts-installer
RUN apt -y install fontconfig \
libsystemd-dev \
libinput-dev \
libudev-dev \
libxkbcommon-dev
#STEP 3 DIPENDENZE
RUN fc-cache
###########################
# COMPILING
RUN git clone https://github.com/ardera/flutter-pi
WORKDIR /TOWER_DISPLAY/flutter-pi/build
RUN cmake ..
RUN make -j `nproc`
RUN make install
FROM emotionsrl/tower-display-base
WORKDIR /TOWER_DISPLAY
COPY spotlink_build ./spotlink_build
COPY display_launcher.py ./display_launcher.py
CMD python3 ./display_launcher.py

The repository 'http://apt.postgresql.org/pub/repos/apt stretch-pgdg Release' does not have a Release file?

I have an error when I am building my Docker containers. It seems that there are problems with Postgres Stretch for Debian. I saw that Debian strech was removed and no longer supported.
I found similar problem here: The repository 'http://apt.postgresql.org/pub/repos/apt stretch-pgdg Release' does not have a Release file but i didn't managed to solve my problem.
Here is an error:
W: The repository 'http://apt.postgresql.org/pub/repos/apt stretch-pgdg Release' does not have a Release file.
E: Failed to fetch http://apt.postgresql.org/pub/repos/apt/dists/stretch-pgdg/11/binary-amd64/Packages 404 Not Found [IP: 147.75.85.69 80]
E: Some index files failed to download. They have been ignored, or old ones used instead.
ERROR: Service 'db' failed to build: The command '/bin/sh -c apt-get update && apt-get install dos2unix && apt-get clean' returned a non-zero code: 100
And here's part of my Dockerfile that I'm trying to run:
FROM debian:jessie
MAINTAINER Open Knowledge
# Install required system packages
RUN apt-get -q -y update \
&& DEBIAN_FRONTEND=noninteractive apt-get -q -y upgrade \
&& apt-get -q -y install \
curl \
python-dev \
python-pip \
python-virtualenv \
python-wheel \
libpq-dev \
libxml2-dev \
libxslt-dev \
libgeos-dev \
libssl-dev \
libxslt-dev \
libgeos-dev \
libssl-dev \
libffi-dev \
postgresql-client \
build-essential \
git-core \
vim \
wget \
&& apt-get -q clean \
&& apt-get install -y dos2unix
Do you maybe know what I should add or remove in my Dockerfile file to solve this problem?
Thanks in advance
Debian stretch is no longer supported
You could use this deb package instead:
deb https://apt-archive.postgresql.org/pub/repos/apt stretch-pgdg main

AWS Lambda - Swift Operation not permitted

I am trying to compile Swift code via AWS Lambda.
Therefore I am using an Ubuntu 18.04 Image as base.
The Swift Version is 5.0.1.
When the image is executed locally, it works fine.
When I try to execute it in AWS Lambda, I get the following error:
/usr/bin/ld.gold: fatal error: /tmp/project/src/a.out: Operation not
permitted\nclang-7: error: linker command failed with exit code 1 (use
-v to see invocation)
I think that the problem is caused by the read-only aws lambda container, that only allows to write into the /tmp/ folder.
Do you know how to fix this error? It seems that swift needs permissions for folders, it doesnt have permission for?
Dockerfile
FROM ubuntu:18.04
# install clang
RUN apt-get update
RUN apt-get install -y clang
# install wget
RUN apt-get install -y wget
# install swift dependencies
RUN apt-get install -y libcurl3 libpython2.7 libpython2.7-dev
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y --no-install-recommends \
binutils \
git \
libc6-dev \
libcurl4 \
libedit2 \
libgcc-5-dev \
libpython2.7 \
libsqlite3-0 \
libstdc++-5-dev \
libxml2 \
pkg-config \
tzdata \
zlib1g-dev \
libbsd-dev
RUN apt-get install -y libicu-dev
# install swift 5.0.1
RUN wget https://swift.org/builds/swift-5.0.1-release/ubuntu1804/swift-5.0.1-RELEASE/swift-5.0.1-RELEASE-ubuntu18.04.tar.gz RUN tar xzf swift-5.0.1-RELEASE-ubuntu18.04.tar.gz RUN mv swift-5.0.1-RELEASE-ubuntu18.04 /usr/lib/swift RUN echo "export PATH=/usr/lib/swift/usr/bin:$PATH" >> ~/.bashrc
RUN . ~/.bashrc
RUN chmod -R o+r /usr/lib/swift
This is the command executed in the AWS-Lambda handler function:
swiftc hello_world.swift -o a.out
hello_world.swift
print("Hello World!")
Your output must be set in tmp folder
swiftc hello_world.swift -o /tmp/a.out

Problem installing modules with cpanm in Perl

I am absolutely new to Perl world. I've picked up a project left behind by a former employee & trying to get it to work. The project was originally in docker form & the requirement now is to run it in a non-docker form (don't get me started on this!) The project works like a charm in it's docker form. I've made the assumption that if I were to install all the packages installed in the docker file, the script should work. In the process of installing the packages, I am bumping into issues.
While the docker image uses ubuntu, the server I am trying on now uses RHEL7
DOCKER FILE
FROM ubuntu:focal-20200703 as ubuntu
FROM ubuntu as mytool
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y -qq build-essential libssl-dev tzdata bash curl wget perl cpanminus libcrypt-ssleay-perl libnet-ssleay-perl
RUN cpanm -n Data::Printer \
Log::Log4perl \
List::Util \
Test::More \
JSON \
JSON::XS \
YAML \
YAML::XS \
GitLab::API::v4 \
IO::Socket::SSL \
HTML::HashTable \
REST::Client \
MIME::Base64 \
File::Spec \
File::Basename \
File::Path \
List::MoreUtils \
DateTime::Format::ISO8601 \
Digest::MD5
ENV TZ=Pacific/Auckland
RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
COPY docker/context/usr/local/bin/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY docker/context/usr/local/etc/mytool/mytool.env.ctmpl /usr/local/etc/mytool/mytool.env.ctmpl
RUN mkdir -p /usr/local/bin /usr/local/bin/cache.d
WORKDIR /usr/local/bin
COPY mytool /usr/local/bin/
COPY lib/ /usr/local/bin/lib
# Container pilot obligatory parameters START
ENV SERVICE_NAME=mytool
ENV SERVICE_PRE_EXEC=/bin/true
ENV SERVICE_HEALTHCHECK_EXEC="test -f /usr/local/etc/mytool/mytool.env"
ENV SERVICE_TEMPLATE_CONFIG_PAIRS=/usr/local/etc/mytool/mytool.env.ctmpl:/usr/local/etc/mytool/mytool.env
EXPOSE 8080
ENTRYPOINT [""]
CMD ["/usr/local/bin/entrypoint.sh"]
# Container pilot obligatory parameters END
I've installed build-essential libssl-dev tzdata bash curl wget perl cpanminus libcrypt-ssleay-perl libnet-ssleay-perl successfully.
Problem is with cpanm stuff from the docker file
[root#npcrver01 home]# cpanm Log::Log4perl
! Finding Log::Log4perl on cpanmetadb failed.
! cannot open file '/root/.cpanm/sources/http%www.cpan.org/02packages.details.txt.gz': No such file or directory opening compressed index
! Couldn't find module or a distribution Log::Log4perl ()
Please could someone help me here
gosh it's the proxy setting. I had to do
export https_proxy=http://<IP>:<port>
export http_proxy=http://<IP>:<port>
export HTTPS_PROXY=http://<IP>:<port>
export HTTP_PROXY=http://<IP>:<port>
Everything is working fine now

Prepare coursier artifact for offline use inside container

I have an sbt project producing my artifact xyz.
I would like to put it along with all its dependencies in the docker container so it can be used using
coursier launch --mode offline xyz
The important part is that preparation should take use of local cursier cache from host.
I tried
executing sbt publishLocal,
then resolving my artifact dependencies (cursier resolve xyz),
then preparing to directories - local & cache - by copying resolved artifact into them
then copying those directories into docker container (as coursier cache and ivy local respectively).
This didn't work because coursier doesn't list .pom and .xml files in its output. I tried copying whole directories (abc/1.0.0 instead of abc/1.0.0/some.jar) but AFAIK there is no reliable way to know how many folders up one has to go because maven and ivy have different dir structures.
while my usecase is not quite identical to yours -- I figure I'd write up my findings and maybe my solution works for you as well!
here's my sample dockerfile, I used this to install scalafmt in an offline-compatible way
FROM ubuntu:jammy
RUN : \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* # */ stackoverflow highlighting bug
ARG CS=v2.1.0-RC4
ARG CS_SHA256=176e92e08ab292531aa0c4993dbc9f2c99dec79578752f3b9285f54f306db572
ARG JDK_SHA256=aef49cc7aa606de2044302e757fa94c8e144818e93487081c4fd319ca858134b
ENV PATH=/opt/coursier/bin:$PATH
RUN : \
&& curl --location --silent --output /tmp/cs.gz "https://github.com/coursier/coursier/releases/download/${CS}/cs-x86_64-pc-linux.gz" \
&& echo "${CS_SHA256} /tmp/cs.gz" | sha256sum --check \
&& curl --location --silent --output /tmp/jdk.tgz "https://download.java.net/openjdk/jdk17/ri/openjdk-17+35_linux-x64_bin.tar.gz" \
&& echo "${JDK_SHA256} /tmp/jdk.tgz" | sha256sum --check \
&& mkdir -p /opt/coursier \
&& tar --strip-components=1 -C /opt/coursier -xf /tmp/jdk.tgz \
&& gunzip /tmp/cs.gz \
&& mv /tmp/cs /opt/coursier/bin \
&& chmod +x /opt/coursier/bin/cs \
&& rm /tmp/jdk.tgz
ENV COURSIER_CACHE=/opt/.cs-cache
RUN : \
&& cs fetch scalafmt:3.6.1 \
&& cs install scalafmt:3.6.1 --dir /opt/wd/bin
the key to offline execution for me was to use cs fetch and set COURSIER_CACHE
here's the offline execution succeeding:
$ docker run --net=none --rm -ti cs /opt/wd/bin/scalafmt --version
scalafmt 3.6.1