the problem
Recently inside a docker container, using apt install
failed to acquire the lock for dpkg
.
the command output
The output from apt install
:
$ sudo apt install ruby
Waiting dpkg lock for 10, 1/60, info: Locked by command: /usr/bin/apt install gdb
Waiting dpkg lock for 10, 2/60, info: Locked by command: /usr/bin/apt install gdb
^C
debug process
Checked no running apt/dpkg process:
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
lolv 1 0.0 0.0 20396 3868 pts/0 Ss+ Oct31 0:00 /bin/bash
lolv 13525 0.0 0.0 20396 3940 pts/1 Ss+ Oct31 0:00 bash
lolv 13538 0.0 0.0 20396 4016 pts/2 Ss Oct31 0:00 bash
lolv 24306 0.0 0.0 6324 872 pts/2 S+ Oct31 0:00 tail -f tests/logs/10311337
lolv 30268 0.0 0.0 20396 3900 pts/3 Ss 05:20 0:00 bash
lolv 30573 0.0 0.0 36160 3272 pts/3 R+ 05:27 0:00 ps aux
Tried to remove all the locks possibly hold by either apt
or dpkg
, but apt install
still failed with waiting for dpkg
lock:
$ sudo rm -rf /var/lib/dpkg/lock
$ sudo rm -rf /var/cache/apt/archives/lock
$ sudo rm -rf /var/lib/apt/lists/lock
$ sudo rm -rf /var/lib/dpkg/lock-frontend
$ sudo rm -rf /var/cache/apt/archives/lock
$ sudo apt install ruby
Waiting dpkg lock for 10, 1/60, info: Locked by command: /usr/bin/apt install gdb
^C
final solution
Searched a little bit, find there is a debug option to skip waiting for the lock.
From the aot.conf
:
DEBUG OPTIONS
Enabling options in the Debug:: section will cause debugging information to
be sent to the standard error stream of the program utilizing the apt
libraries, or enable special program modes that are primarily useful for
debugging the behavior of apt. Most of these options are not interesting to a
normal user, but a few may be:
• Debug::NoLocking disables all file locking. This can be used to run
some operations (for instance, apt-get -s install) as a non-root user.
$ sudo apt -o 'Debug::NoLocking=true' install ruby
Reading package lists... Done
Building dependency tree
Reading state information... Done
...