bash: vim: command not found inside a container means the image ships without
the editor: in the tested ubuntu:24.04 and ASP.NET Core runtime images
vim, vi and nano were all missing. Run
apt-get update, then apt-get install -y vim (or
nano).
Watch the package name: vim-tiny installs vi
and vim.tiny, not a command called vim. For a one-line change
you may not need an editor at all; sed -i worked without installing
anything.
The error
docker exec fix10-lc-r3 bash -ic 'vim /etc/hosts 2>&1'
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
bash: vim: command not found
The first two lines come from starting an interactive shell without a terminal. The other
editors fared no better in a fresh ubuntu:24.04 container:
docker exec fix10-lc-r2 bash -c 'vim /etc/hosts 2>&1; echo exit=$?; nano /etc/hosts 2>&1; echo exit=$?; vi /etc/hosts 2>&1; echo exit=$?'
bash: line 1: vim: command not found
exit=127
bash: line 1: nano: command not found
exit=127
bash: line 1: vi: command not found
exit=127
Why it happens
The images tested here contain no editor package, so bash finds nothing called
vim, vi or nano on the PATH and
returns 127. Both containers ran Ubuntu 24.04.5 LTS; the ASP.NET Core runtime image is
built on the same release and lacked the same three commands.
A fresh container also has no package lists, so install the editor after
apt-get update, not before. There was no fallback either: the
generic /usr/bin/editor command did not exist, and neither did systemctl, so a guide that tells you to edit a
service file and restart it does not fit a plain container:
docker exec fix10-lc-r2 bash -c 'systemctl status 2>&1; echo exit=$?; ls /usr/bin/editor /etc/alternatives/editor 2>&1'
bash: line 1: systemctl: command not found
exit=127
ls: cannot access '/usr/bin/editor': No such file or directory
ls: cannot access '/etc/alternatives/editor': No such file or directory
The fix
docker exec fix10-lc-r2 bash -c 'apt-get update > /dev/null 2>&1; echo update-exit=$?; apt-get install -y nano > /dev/null 2>&1; echo install-exit=$?; command -v nano; nano --version | head -1'
update-exit=0
install-exit=0
/usr/bin/nano
GNU nano, version 7.2
docker exec fix10-lc-r2 bash -c 'apt-get install -y vim > /dev/null 2>&1; echo install-exit=$?; command -v vim; vim --version | head -1'
install-exit=0
/usr/bin/vim
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Aug 24 2026 22:13:04)
Before the full vim package, the same container got vim-tiny,
and vim was still not found:
docker exec fix10-lc-r2 bash -c 'apt-get install -y vim-tiny > /dev/null 2>&1; echo install-exit=$?; command -v vim vim.tiny vi; vim 2>&1 | head -1; echo exit=$?'
install-exit=0
/usr/bin/vim.tiny
/usr/bin/vi
bash: line 1: vim: command not found
exit=0
(The exit=0 there is the exit code of head, the last command
of the pipe.) With vim-tiny, type vi. And for a single change,
skip the editor:
docker exec fix10-lc-r2 bash -c 'printf ''127.0.0.1 localhost\n'' > /root/demo.txt; sed -i ''s/localhost/localhost demo-host/'' /root/demo.txt; cat /root/demo.txt'
127.0.0.1 localhost demo-host
An install made with docker exec did not outlive its container in a test
with ping (a new container from the same image lacked the command), while an image built
with the update and install in one Dockerfile RUN line had it; the same
applies if you want an editor in every container.
How it was reproduced
The captures were made in containers created from ubuntu:24.04 (Ubuntu
24.04.5 LTS, bash 5.2.21, apt 2.8.3) and mcr.microsoft.com/dotnet/aspnet:10.0
with docker run -d --name ... sleep infinity on Docker Engine 29.9.3. The
installed versions were GNU nano 7.2 and VIM 9.1. The fix10-lc- container
names are the test's own.
Every command was sent from Windows PowerShell 5.1 exactly as shown, with the -c text in single quotes so it reached the container unchanged; a single quote inside that text is written twice, as PowerShell requires.
Frequently asked
- How do I install vim in a Docker container?
- Run apt-get update, then apt-get install -y vim. In the test command -v vim then printed /usr/bin/vim.
- Why does vim say command not found after installing vim-tiny?
- vim-tiny installs vi and vim.tiny, not vim. In the test command -v found only those two; type vi, or install the vim package.
- How do I edit a file in a container without an editor?
- Use sed -i for a small change. In the test sed -i changed a line of a file and cat showed the new text without installing anything.
More decoded errors in the Fixes category. If
sudo is missing too, see
bash: sudo: command not found.