apt-get fails within container without sudo [closed] - docker

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 months ago.
Improve this question
I have observed a problem where apt-get install will fail within a container where:
the package is already installed and,
sudo is not used.
This can be recreated by creating a simple container, e.g.
docker run -it ubuntu:latest /bin/bash
Within the container, run the following:
apt-get install software-properties-common
apt-get install software-properties-common
The second time, this will fail with a "Killed" message. If you then prepend the statement with sudo it will complete successfully:
sudo apt-get install software-properties-common
If the user within the container is root, why is sudo required to reinstall an existing package? I do not believe this is related to the AUFS file system as prepending with sudo will complete.
This is using docker 1.10 and an Ubuntu image.

The main point is the use of sudo
It doesn't fail on Debian 11:
# docker run -it ubuntu:latest /bin/bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
00f50047d606: Pull complete
Digest: sha256:20fa2d7bb4de7723f542be5923b06c4d704370f0390e4ae9e1c833c8785644c1
Status: Downloaded newer image for ubuntu:latest
# apt-get update
Hit:1 http://ports.ubuntu.com/ubuntu-ports jammy InRelease
Hit:2 http://ports.ubuntu.com/ubuntu-ports jammy-updates InRelease
Hit:3 http://ports.ubuntu.com/ubuntu-ports jammy-backports InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease
Reading package lists... Done
# apt-get install software-properties-common
Reading package lists... Done
...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
Processing triggers for dbus (1.12.20-2ubuntu4) ...
# apt-get install software-properties-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
software-properties-common is already the newest version (0.99.22.3).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
There may be something corrupt on your system. If running these don't help, you may need to reinstall:
apt-get update
apt-get upgrade

You need to install sudo package by following commands.
apt update && apt upgrade
apt install sudo

Related

error in docker build - Err:1 http://deb.debian.org/debian stretch/main amd64 unzip amd64 6.0-21+deb9u1 404 Not Found

I am doing a docker build on my MacBook Pro and it always keeps failing with following error:
Reading package lists...
Building dependency tree...
Reading state information...
Suggested packages:
zip
The following NEW packages will be installed:
unzip
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 170 kB of archives.
After this operation, 547 kB of additional disk space will be used.
Err:1 http://deb.debian.org/debian stretch/main amd64 unzip amd64 6.0-21+deb9u1
404 Not Found
E: Failed to fetch http://deb.debian.org/debian/pool/main/u/unzip/unzip_6.0-21+deb9u1_amd64.deb 404 Not Found
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
The command '/bin/sh -c apt-get install unzip' returned a non-zero code: 100
docker version:
Docker version 19.03.8, build afacb8b
MacOS: Mojave 10.14.6
Dockerfile snippet:
FROM debian:latest
RUN apt-get update
RUN apt-get install -y ca-certificates
RUN apt-get install unzip
The build works fine in our travis CI which is using docker-ce=17.09.0~ce-0~ubuntu
Any suggestions on how to debug it further? Initially we thought it may be a temporary issue on debian side but the problem has persisted so likely an issue with my environment.
Combine the three RUN lines you show into a single command:
FROM debian:latest
RUN apt-get update \
&& apt-get install -y \
ca-certificates \
unzip
There's a combination of two things that leads to that 404 error. On the one hand, Docker will cache individual Dockerfile steps: it sees that, starting from debian:latest, it's already RUN apt-get update, so it uses the version of that command from yesterday. On the other hand, Debian updates their repositories fairly frequently with very minor updates (see the +deb9u1 part of that version number) and when they do they delete the previous version from their repositories. This combination means you can be in a sequence where you're using a cached version of the apt-get update index, but the package version it mentions doesn't exist any more.
Combining these lines together like this means Docker will always run both apt-get update and apt-get install together; if you add a package to the list it will re-run the update step before trying to download things. That avoids this problem, at the cost of a little extra download time when the package list changes.

docker installation failed on Ubuntu 20.04 LTS(Vmware) [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 months ago.
The community reviewed whether to reopen this question 5 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I am following the docker installation on Ubuntu 20.04 using https://docs.docker.com/engine/install/ubuntu/ in Ubuntu VM on VMware.
But when running the command to add the repository to Ubuntu.
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
I am getting below error
Get:1 http://us.archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Ign:2 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 http://dl.google.com/linux/chrome/deb stable Release
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease
Ign:6 https://download.docker.com/linux/ubuntu focal InRelease
Err:7 https://download.docker.com/linux/ubuntu focal Release
404 Not Found [IP: 13.225.7.126 443]
Get:8 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [89.1 kB]
Hit:9 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
E: The repository 'https://download.docker.com/linux/ubuntu focal Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
when running command
sudo apt-get install docker-ce docker-ce-cli containerd.io
I get error
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'docker-ce' has no installation candidate
E: Unable to locate package docker-ce-cli
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io'
E: Couldn't find any package by regex 'containerd.io'
What is the reason for this?
I am new to docker.
Is there a workaround to this or should I install docker using source code or something?
Thank you.
For the moment, you can use :
sudo apt-get install -y docker.io
And then check with :
docker -v
According to the documentation followed by a test on my PC, these instructions will install docker successfully on WMware Ubuntu focal:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Docker has not released the repository for focal fossa (20.04) yet. As #Wared said, running
sudo apt install -y docker.io
will get docker from ubuntu repository.
I am able to use all my docker images that I used to in 18.04 successfully on 20.04 with this docker installation.
I know the question is about Ubuntu 20. But in case you are trying to install it on Linux Mint 20 (like me), the problem looks the same but the answer is different.
The installation guide tells you to add the PPA like this:
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
However, the $(lsb_release -cs) part is the problem, because it passes the release name as a parameter to the repository command. In Ubuntu 20 that command outputs focal and everything goes well, but in Linux Mint that command outputs ulyana and it fails because docker does not have that release.
If you want to install it on mint, just replace that command with the focal string so you get the ubuntu focal version:
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
focal \
stable"
According to the information at https://docs.docker.com/engine/install/ubuntu/ Ubuntu 20.04 is not supported at the moment.
The docker repositories for Ubuntu 20.04 LTS arent ready yet (I dont understand why they didnt concentrate on that instead of getting out a version for non LTS releases like 19.10!).
But the version that is already available in the Ubuntu Universe repository is recent, so just use this in the meantime.
When the guys at Docker are ready to publish their 20.04 repo, just follow this instruction: https://docs.docker.com/engine/install/ubuntu/
..then, of course also including the section "Uninstalling old versions". This way, you can already start to use Docker on Ubuntu 20.04
The above error occurs due to unclean copy of the commands. Please consider this and copy the command once again to resolve the error. It helped me rectify the same error.
This is what solved my problem:
dpkg -i --ignore-depends=docker-ce lando-stable.deb
FROM https://docs.lando.dev/getting-started/installation.html#caveats

Cannot retrieve latest version of Debian package inside Docker container

Inside a docker container (created from a node:9 image) I am trying to install stress-ng package using apt-get. However, for some reason an old version of the package is retrieved everytime I try to install it. For installing the package I use the commands:
root#7e7a683bf288:/usr/src/app# apt-get update
root#7e7a683bf288:/usr/src/app# apt-get install stress-ng
I get the following version:
root#7e7a683bf288:/usr/src/app# stress-ng --version
stress-ng, version 0.01.32
However, I would like to get the latest version if possible, 0.09.42-1 (https://packages.ubuntu.com/cosmic/stress-ng). I have tried some of the solutions in similar questions but was not able to get this to work.
Additional info:
root#7e7a683bf288:/usr/src/app# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root#7e7a683bf288:/usr/src/app# cat /etc/apt/sources.list
deb http://deb.debian.org/debian jessie main
deb http://security.debian.org/debian-security jessie/updates main
deb http://deb.debian.org/debian jessie-updates main
root#7e7a683bf288:/usr/src/app# add-apt-repository
bash: add-apt-repository: command not found
You have to add the unstable repo to your sources.list. When I did that, I still couldn't install stress-ng as it stated:
root#096865e3637f:/# apt-get install stress-ng
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libc6-dev : Breaks: binutils (< 2.26) but 2.25-5+deb8u1 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
So before installing I had to remove binutils.
Maybe that is an option for you.
The complete Dockerfile looks like:
FROM node:9
RUN echo "deb http://http.us.debian.org/debian unstable main non-free contrib" >> /etc/apt/sources.list && \
echo "deb-src http://http.us.debian.org/debian unstable main non-free contrib" >> /etc/apt/sources.list && \
apt-get remove binutils -y && \
apt-get update && \
apt-get install stress-ng -y
CMD stress-ng --version
stress-ng --version:
stress-ng, version 0.09.50 💻🔥
So, it is not 0.09.42, but the latest (unstable) version - as requested.

Docker: Having issues installing apt-utils

I am trying to install apt-utils on Docker because when I was just doing apt-get update, I was getting the error: debconf: delaying package configuration, since apt-utils is not installed. So I added a line to install apt-utils (along with curl):
RUN apt-get update && apt-get install -y apt-utils && apt-get install -y curl
But, I am still getting that error leading me to believe that my command didn't work. Below is my output when I try to build the image.
Step 5/12 : RUN apt-get update && apt-get install -y apt-utils && apt-get install -y curl
---> Running in 6e6565ff01bd
Get:1 http://security.debian.org jessie/updates InRelease [94.4 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:3 http://deb.debian.org jessie Release.gpg [2420 B]
Get:4 http://deb.debian.org jessie Release [148 kB]
Get:5 http://security.debian.org jessie/updates/main amd64 Packages [624 kB]
Get:6 http://deb.debian.org jessie-updates/main amd64 Packages [23.0 kB]
Get:7 http://deb.debian.org jessie/main amd64 Packages [9098 kB]
Fetched 10.1 MB in 6s (1541 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
libapt-inst1.5
The following NEW packages will be installed:
apt-utils libapt-inst1.5
0 upgraded, 2 newly installed, 0 to remove and 24 not upgraded.
Need to get 537 kB of archives.
After this operation, 1333 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian/ jessie/main libapt-inst1.5 amd64 1.0.9.8.4 [169 kB]
Get:2 http://deb.debian.org/debian/ jessie/main apt-utils amd64 1.0.9.8.4 [368 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 537 kB in 0s (557 kB/s)
Selecting previously unselected package libapt-inst1.5:amd64.
(Reading database ... 21676 files and directories currently installed.)
Preparing to unpack .../libapt-inst1.5_1.0.9.8.4_amd64.deb ...
Unpacking libapt-inst1.5:amd64 (1.0.9.8.4) ...
Selecting previously unselected package apt-utils.
Preparing to unpack .../apt-utils_1.0.9.8.4_amd64.deb ...
Unpacking apt-utils (1.0.9.8.4) ...
Setting up libapt-inst1.5:amd64 (1.0.9.8.4) ...
Setting up apt-utils (1.0.9.8.4) ...
Processing triggers for libc-bin (2.19-18+deb8u10) ...
Reading package lists...
Building dependency tree...
Reading state information...
curl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 24 not upgraded.
Removing intermediate container 6e6565ff01bd
---> f65e29c6a6b9
Step 6/12 : RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
---> Running in f5764ba56103
Detected operating system as debian/8.
Checking for curl...
Detected curl...
Checking for gpg...
Detected gpg...
Running apt-get update... done.
Installing debian-archive-keyring which is needed for installing
apt-transport-https on many Debian systems.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/github_git-lfs.list...done.
Importing packagecloud gpg key... done.
Running apt-get update... done.
The repository is setup! You can now install packages.
Removing intermediate container f5764ba56103
---> a4e64687ab73
What is causing this and how can I fix it?
This is not actually an error and it is safe to ignore it. I have built a large number of container images without ever having apt-utils on any of them and regardless of this warning message, all package installs go through and work normally.
Anyway, if you want to have apt-utils - install it. It will give you this warning once and then it will disappear for future invocations of apt-get (as you can see in your own log, curl got installed without that message).
NOTE if you install apt-utils, you will get other warnings (because now the installer can run interactive config and will attempt that and fail). To suppress those and have packages that have interactive config with their defaults, run apt-get like this
DEBIAN_FRONTEND=noninteractive apt-get install -y pkgs....
After searching over the Internet, I have found some alternatives worth to be mentioned, instead of every time putting DEBIAN_FRONTEND=noninteractive in front of apt-get install -y {your-pkgs}:
Alternative 1: ARG DEBIAN_FRONTEND=noninteractive
Important: According to the feedbacks alternative 2 & 3 work for most of you, while alternative 1 does not. This is why this alternative is crossed out, but is kept for the sake of traceability & completeness.
The ARG instruction defines a variable that users can pass at
build-time to the builder with the docker build command using the
--build-arg = flag. (Reference: [6])
Solution characteristics:
ARG directive is set only during the build
The option 'noninteractive' is set as default value for the build-time only.
Since it is an argument, it can be changed by passing another value for this argument with e.g. docker build --build-arg DEBIAN_FRONTEND=newt
Example:
ARG DEBIAN_FRONTEND=noninteractive
...
RUN apt-get -yq install {your-pkgs}
Alternative 2: On-the-fly
It is the solution from Leo K.
Solution characteristics:
It can be set where is it needed. So a good fine-grained solution.
It can be set in a different value in a specific command, so it is not globally set.
The scope is the RUN and won't affect other directives.
Example:
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install {your-pkgs}
Alternative 3: ENV DEBIAN_FRONTEND=noninteractive
Setting ENV DEBIAN_FRONTEND noninteractive would also be an alternative but it is highly discouraged.
Another way would be to set at the beginning and unset it at the end of the Dockerfile.
Solution characteristics:
ENV directive will persists the environment variable after the build (not recommended), furthermore
It can be error prone if you forget to set it back to the default value.
Because it is set with ENV, it will be inherited by all images and containes built from the image, effectively changing their behaviour. (As mentioned in [1]) People using those images run into problems when installing software interactively, because installers do not show any dialog boxes.
The default frontend is DEBIAN_FRONTEND=newt (see [2], so it has to be set at the end of the file.
Example:
# Set for all apt-get install, must be at the very beginning of the Dockerfile.
ENV DEBIAN_FRONTEND noninteractive
...
# Non-interactive modes get set back.
ENV DEBIAN_FRONTEND newt
Alternative 4: RUN export DEBIAN_FRONTEND=noninteractive
Solution characteristics:
Quite similar to the alternative 2
By decoupling, the cohesion is suffering: why there is an export of this variable and to what it belongs to (apt-get).
The scope is the RUN and won't affect other directives.
Example:
# Set the frontend and then install your package
RUN export DEBIAN_FRONTEND=noninteractive && \
...
apt-get -yq install {your-pkgs} && \
...
More to read (references)
ENV DEBIAN_FRONTEND noninteractive
debconf: delaying package configuration, since apt-utils is not installed
point out that ENV DEBIAN_FRONTEND will persist, so its not recommended
Docker frequently asked questions (FAQ)
Debian Installer Parameters
Official documentation - ARG
Please run apt-get install apt-utils and voilà. Installed and no warnings.
This is an ongoing issue with no great solution... I went with this, it's sub-optimal, but it works:
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y apt-utils 2>&1 | \
grep -v "^debconf: delaying package configuration, since apt-utils.*"
Explanation:
grep -v reverse matches, lines starting with that will begone!
ARG is the new ENV if you don't need it at runtime.
We can then use apt-get all day without that error showing when building the image from scratch.
Proof that this works:
https://asciinema.org/a/WJCDEYcxCIy6EF7eXw0MAnK3c

'make' command not found in docker container

I have a docker image which is running docker host with ubuntu 14.04.
In one of the containers, I am trying to run zookeeper and install librdkafka libraries(pre-requisite library) for kafka to connect to 3rd party software. I need the 'make' command to build my librdkafka libraries inside the container from where I will be running the kafka adapters/connectors.
However, interestingly I am not able to run 'make' command inside the container, it works perfectly on the docker host. When i try using
apt-get install make
I get the following message which is not making much sense to me:
root#svi-esp-service:/# apt-get install make
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package make is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'make' has no installation candidate
Can someone help me to understand why the make is not getting installed in the container and why cant i run it? I am behind time and need this command running in the container..its really annoying.
Just as a heads up, I have following in the list file:
root#svi-esp-service:/# cat /etc/apt/sources.list
deb http://http.debian.net/debian jessie main
deb http://http.debian.net/debian jessie-updates main
deb http://security.debian.org jessie/updates main
Help really appreciated!
Update APT's package lists by running apt-get update first:
apt-get update && apt-get install make
RUN apt install build-essential -y --no-install-recommends
I recommend apt over apt-get
This will not only install 'make' but others as well, likely needed for development.
-y and --no-install-recommends so it won't block build ;)

Resources