3

I have observed a problem where apt-get install will fail within a container where:

  1. the package is already installed and,
  2. 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.

wildpalms
  • 39
  • 2
  • 1
    You should do `apt-get update` first – user2915097 Feb 29 '16 at 07:53
  • If I do like you, the first apt-get installs, the second gives `software-properties-common is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.` so there is something wrong. Ubuntu 14.04, docker 1.10.2-rc1 for me – user2915097 Feb 29 '16 at 18:50
  • This makes no difference. The main point is the use of sudo. using apt-get install software-properties-common && apt-get update then apt-get install software-properties-common will fail. If you then use sudo apt-get install software-properties-common, it will work. The heart of this problem is the requirement to use sudo, despite being root. – wildpalms Mar 01 '16 at 10:53
  • @user2915097 didn't work. ` apt-get update Reading package lists... Done E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied) E: Unable to lock directory /var/lib/apt/lists/` – Charlie Parker Sep 15 '22 at 02:38
  • actually I get this issue too: https://unix.stackexchange.com/questions/354928/bash-sudo-command-not-found – Charlie Parker Sep 15 '22 at 02:40
  • related: https://stackoverflow.com/questions/72058458/run-ubuntu-docker-container-as-user-with-sudo-access creating a user in docker with sudo access – Charlie Parker Sep 15 '22 at 02:44
  • 1
    When neither sudo nor apt-get is available in container, you can also jump into running container as root user using command `docker exec -u root -t -i container_id /bin/bash`. Did you try this? – Charlie Parker Sep 15 '22 at 02:49

2 Answers2

0

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
James Risner
  • 5,451
  • 11
  • 25
  • 47
-2

You need to install sudo package by following commands.

apt update && apt upgrade apt install sudo