Docker has no package manager - docker

Using the image firesh/nginx-lua. After running the docker Image I want to install some things but it has no apt / apt-get or any other package manager.
I tried to install apt on the docker but it requires curl, which does not exist as well.
Any solution for that? I cannot install anything manually on this docker
Thanks..

It's because the base image used alpine, it has apk, you can use apk as apk is the default package manager on alpine. You can add things using apk add <desired_thing>, before this also do apk update.
Ex: for adding curl:
apk update
apk add curl

Related

Cannot explain why Alpine apk upgrade command does not update ncurses package although a newer version exists

I have a Dockerfile as:
FROM nginx:1.21.3-alpine
RUN apk update && apk add bash \
&& apk upgrade
I can see that package ncurses is installed and the version is 6.2_p20210612-r0.
Now, There is a newer package available in the main repository edge branch with version 6.2_p20211002-r0 here.
As far as I understand after building an image from the above mentioned Dockerfile the version of ncurses should be updated to 6.2_p20211002-r0 BUT instead it stays as 6.2_p20210612-r0. I cannot understand why?
I confirmed this by running a container after build and running:
apk info -a ncurses
The output was:
ncurses-6.2_p20210612-r0 installed size:
284 KiB
The nginx:1.21.3-alpine image is based on Alpine 3.14 (see cat /etc/os-release), and therefore ncurses is updated with the version of the Alpine 3.14 repository, which is currently 6.2_p20210612-r0.
For installing ncurses from edge (currently version 6.2_p20211002-r0), you could specify the edge repository explicitly in the apk command:
apk add ncurses --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
Mixing and matching packages from different repositories this way might be OK in some cases, but has to be tested carefully. For ncurses, some functionality might be broken, since the matching ncurses-libs package should be installed as well, but some of the package images depend on ncurses-libs, so re-installing it triggers update of these packages. Moreover, the nginx-module-njs dependent package must be removed. If this is acceptable, you could modify the Dockerfile as follows:
FROM nginx:1.21.3-alpine
RUN apk update && \
apk del ncurses ncurses-libs nginx-module-njs && \
apk add ncurses ncurses-libs --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main && \
apk add bash && \
apk upgrade

How to add chrome browser to TestCafe docker image?

TestCafe docker image is having only chromium,firefox. I want use same image to run tests on chrome & tried to build docker image by installing chrome browser using testcafe base image (linux/amd64). But running into issues.
docker run -v ${PWD}/tests:/tests -it testcafe/testcafe chromium,firefox tests/shared/abc.js
https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/use-testcafe-docker-image.html#test-in-docker-containers
apt-get is the package manager for Ubuntu and other Debian-based distros,
apk for Alpine
for my base image type linux/amd64(https://hub.docker.com/r/testcafe/testcafe/tags?page=1&ordering=last_updated)
ERROR [2/5] RUN apk update && apk add --no-cache
ERROR [2/5] RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && sudo dpkg -i google-chrome-stable_current_amd64.deb
Was trying like below in docker file:(Not sure exact preprequisites section & install Chrome section)
#Step 0: Choose base
FROM testcafe/testcafe
#Step 1 : Install the pre-requisite
RUN apk update
RUN apt-get install -y curl
RUN apt-get install -y p7zip
p7zip-full
unace
zip
unzip
bzip2
#Version numbers
ARG CHROME_VERSION=89.0.4389.114
#Step 2: Install Chrome
RUN curl http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_$CHROME_VERSION-1_amd64.deb -o /chrome.deb
RUN dpkg -i /chrome.deb
RUN rm /chrome.deb
CMD ["echo", " hello, Welcome to Kiran's custom testcafe docker image!"]
Appreciate if anyone suggest commands in docker file for this object.
Unfortunately, there seems to be no reliable way to install Google Chrome on Alpine Linux. The dpkg package used in your example is intended for Debian-based distributions. While it is available on Alpine Linux as well, it is usually good for lightweight packages only. With heavy packages, it is likely to fail because some of its dependencies are unavailable on Alpine.
That is why the apk package manager is preferred for Alpine Linux. However, google-chrome is not available for apk (only chromium is). See https://stackoverflow.com/a/58781506.
If you need to use a full-featured google-chrome for testing, please consider using a Debian-based Docker image instead of the Alpine-based TestCafe image.

How to correctly install programs in docker?

I know that every line of RUN ... will add a layer to the docker image and that it is recommended to make RUN commands connected with &&. But my question is:
Is better this:
RUN apk update && apk upgrade \
&& apk add openssh \
&& apk add --update nodejs nodejs-npm \
&& npm install -g #angular/cli \
&& apk add openjdk11 \
&& apk add maven \
&& apk add git
Or this:
RUN apk update && apk upgrade
RUN apk add openssh
RUN apk add --update nodejs nodejs-npm
RUN npm install -g #angular/cli
RUN apk add openjdk11
RUN apk add maven
RUN apk add git
The first one creates just one layer but when a version of anything changes the image would have to start from the beginning, not from cash. The second approach will create more layers but when just the version of git changes only the git layer needs to be build again and all previous layers can be used from cash.
I'd recommend:
Install all the OS packages in a single apk invocation: there is some overhead in starting the package manager (more noticeable with dpkg/apt) and it is faster if you start it once and install several packages
If you need to run an update command, always run it in the same RUN command as your other package-manager steps. This avoids some trouble with Docker layer caching (again, very noticeable with apt) where docker build doesn't re-run update, but then it does try to run a changed install step; when it tries to install a package using yesterday's package index, the upload of that package that happened today deleted yesterday's file and the download will fail.
Don't npm install single packages. That means your package.json file is incomplete. Add it there.
I've seen recommendations both ways as to whether or not to run a full upgrade. Keeping up-to-date on security fixes is important; the underlying base images on Docker Hub also update pretty regularly. So if your image is FROM alpine:latest, doing a docker build --pull will get you much of the effect of an explicit apk upgrade.
Stylistically, if I need any substantial number of packages, I find the list a little more maintainable if I sort it alphabetically and put one package on a line, but this is purely personal preference.
Putting this all together would transform your example into:
RUN apk update \
&& apk upgrade \
&& apk add \
git \
maven \
nodejs \
nodejs-npm \
openjdk11 \
openssh
COPY package.json package-lock.json . # includes #angular/cli
RUN npm ci
Don't be afraid to use multiple containers, if that makes sense. (What's your application that uses both Java and Node together; can it be split into two single-language parts?) Don't install unnecessary developer-oriented tools in your image. (Does your application invoke git while it's running; do you install a dependency directly from GitHub; or can you remove git?) Don't try to run an ssh daemon in your container. (It breaks the "one process per container" rule which instantly makes things harder to manage; 90% of the SO examples have a hard-coded user password plus sudo rights, which is not really a security best practice; managing the credentials is essentially impossible.)
Both approaches are on the extreem, you need to try to minimize the layers for "reusability" at the same time to optimize for lower number of layers.
Based on your example, the build can be organized as follows:
RUN apk update && apk upgrade \
&& apk add openssh \
&& apk add --update nodejs nodejs-npm \
&& apk add openjdk11 \
&& apk add maven \
&& apk add git
RUN npm install -g #angular/cli \
Now I have only 2 layers, first one is bringing the OS packages and the second one dealing with the node.js packages. Now this can better be reused in other builds.
Once you have done this modification, you can move to multistage build where you will be able to better control and reuse the intermediate containers like in this example

Can't install hadoop in a dockerfile which has ubuntu as base image

When I run the following code, I get this error, E: Unable to locate package hadoop
FROM ubuntu:20.04
RUN apt-get update -y \
&& apt-get install -y apt-utils \
&& apt-get install python3.8 -y
RUN apt-get install jupyter -y
RUN apt-get install hadoop -y
RUN rm -rf /var/lib/apt/lists/*
ADD sample.py /
LABEL maintainer=Ammar
CMD [ "python", "./sample.py" ]
This link: https://computingforgeeks.com/install-apache-hadoop-hbase-on-ubuntu-linux/ contains full example of Hadoop installation. I think the same should be done in Docker step-by-step.
apt-get install hadoop not working in ubuntu without adding external repositories. But if you know external repo, then you must add softwaree-properties-common package (like this: https://stackoverflow.com/a/52091668/1852444)
and then add your repository by apt-add-repository command.
Some "foss" softwares and Softwares which do not comes under foss are not added in ubuntu repository so they cannot be install using apt because apt use these repositories to install package.
hadoop is one of these packages which is not added to ubuntu repo. For more info about repository you can check here
You can pull and use one of the hadoop container image created and pushed in dockerhub by others instead of creating it for scratch.
If you still want to create your own hadoop container image you can check out this example hadoop dockerfile

Howto download Chromium v77 in Dockerfile with Alpine?

I am currently using the node:12-alpine Docker image and I am trying to install Chromium version 77, but I am unable to figure out how as I can not find a package for it.
I am fine with changing to a different docker image if that would allow me to install Chromium version 77.
Question:
How can I download and install Chromium version 77 in a docker image?
You can use 3.x version of alpine which has Chromium v77
FROM alpine:3.10
RUN apk update && apk add --no-cache chromium
PS: I also added chromium-driver and libcanberra-gtk3 module for my requirement.
FROM alpine:3.7
RUN apk add --no-cache --virtual .build-deps curl \
&& curl -fSL https://chrome.com/chrome.tar.gz -o chrome.tar.gz
Just download it, it should be fine.
download chrome:
chrome download

Resources