Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

bash-completion does not work for apt-get #75

Closed
omicronns opened this issue Jan 14, 2017 · 4 comments
Closed

bash-completion does not work for apt-get #75

omicronns opened this issue Jan 14, 2017 · 4 comments

Comments

@omicronns
Copy link

I have written following dockerfile:

FROM ubuntu:yakkety

RUN apt-get update && apt-get install -y \
    bash-completion

# Uncomment bash-completion switch
RUN sed -i.bak "32,38s/.//" /etc/bash.bashrc

But when I run this image:

docker run -it ubuntu-base

bash-completion for apt-get install does not work,

# apt-get install libopen <TAB>

gives me a beep from a speaker and no output.

I am running docker 1.12.6 on Windows 10.

@tianon
Copy link
Owner

tianon commented Feb 16, 2017

I can confirm that installing bash-completion enables some completion, but does indeed seem to not complete for package names. I guess it'd probably be interesting to try reproducing in a more "vanilla" chroot and see if it's caused by something we've done or whether it's something that needs to be reported upstream:

FROM ubuntu:yakkety

RUN apt-get update -qq && apt-get install -yqq bash-completion && rm -rf /var/lib/apt/lists/*
$ docker build -
...
Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM ubuntu:yakkety
 ---> 31005225a745
Step 2/2 : RUN apt-get update -qq && apt-get install -yqq bash-completion && rm -rf /var/lib/apt/lists/*
 ---> Running in f2652cdfb4fd
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package bash-completion.
(Reading database ... 6513 files and directories currently installed.)
Preparing to unpack .../bash-completion_1%3a2.1-4.3ubuntu1_all.deb ...
Unpacking bash-completion (1:2.1-4.3ubuntu1) ...
Setting up bash-completion (1:2.1-4.3ubuntu1) ...
 ---> 3fbf18528d4e
Removing intermediate container f2652cdfb4fd
Successfully built 3fbf18528d4e
$ docker run -it --rm 3fbf18528d4e bash --login -i
root@c65f6c083a4c:/# apt-get update -qq
root@c65f6c083a4c:/# apt-get in^I # completes to "install"
root@c65f6c083a4c:/# apt-get install libopen^I # (nothing)

@wikrie
Copy link

wikrie commented Mar 16, 2017

Upate: I can confirm that issue for a quick solution I use ZSH, there the bash_completition is fully working, but not with bash.

@wjzhou
Copy link

wjzhou commented May 3, 2018

I run into this today. (I'm using docker to run ubuntu 1604 opengl GUI software in ubuntu 1804)
I think I figure out why this happens and how to "fix" it for my usage

There are two problems here:

  1. bash-completion is not installed
    $apt-get install bash-completion
  2. the cache file used by apt completion is deleted by docker apt setting
    $ rm /etc/apt/apt.conf.d/docker-clean
    After this, restart the bash and run a apt-get update should enable the bash-completion

Long explains of the issue:
The bash completion use a command to generate the package completion list:

/usr/share/bash-completion/completions/apt:190
COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \..

however, this apt-cache --no-generate pkgnames $cur has problem in the docker version

$apt-cache --no-generate pkgnames test
E: Could not open file  - open (2: No such file or directory)

This is because of the docker-clean apt setting.

#/etc/apt/apt.conf.d/docker-clean
DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };
APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };
Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";

Two problems for the completion:

  1. Dir::Cache::pkgcache "" which is the reason for the emply filename of the error message open file - open (the filename supposed to be before the -)
  2. the setting will try to remove the pkgcache file after each apt invoke

I can understand why we want to remove the pkgcache. So my solution is just a partial fix. But it serve my purpose well. My docker is a long run container and I prefer the cache.

@tianon
Copy link
Owner

tianon commented Dec 24, 2018

Nice, good find! 👍 (and thanks for giving such a detailed explanation)

Closing, since this is caused by configuration that's by design (and the workaround is now documented here, and for me is the second Google result for "docker ubuntu apt-get bash completion").

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants