Unable to install vim or nano inside docker container

梦想与她 提交于 2019-12-02 23:55:18

First I create the docker:

sudo docker run -t -i ubuntu /bin/bash

Instead of this you can enter in a running docker with his number or name:

sudo docker exec -it be8aa338d656 bash

Then inside the docker run this code:

apt-get update
apt-get install vim nano

The solution is to run docker with:

docker run --net=host
Mangat Rai Modi

It looks like your docker is unable to connect to internet. Try this:-

sysctl -w net.ipv4.ip_forward=1

Then restart:-

service docker restart

If still not working, read here:- My docker container has no internet

Absolutely no luck at all with apt or apt-get. The docker I am using from someone else doesn't seem to have the /etc/apt sources configured correct (or disabled). I need to edit the configurations.

Luckily dpkg and curl are available inside the container. I used the binaries for my amd64. https://launchpad.net/ubuntu/+source/vim/2:7.4.712-2ubuntu4

mkdir /tmp/vim cd /tmp/vim

curl http://launchpadlibrarian.net/221875822/vim_7.4.712-2ubuntu4_amd64.deb > vim.deb curl http://launchpadlibrarian.net/221873815/vim-common_7.4.712-2ubuntu4_arm64.deb > vim-common.deb curl http://launchpadlibrarian.net/221875814/vim-runtime_7.4.712-2ubuntu4_all.deb > vim-runtime.deb curl https://launchpad.net/ubuntu/wily/amd64/vim/2:7.4.712-2ubuntu4 > vim.deb curl http://mirrors.kernel.org/ubuntu/pool/main/g/gpm/libgpm2_1.20.4-6.1_amd64.deb > libgpm2.deb

dpkg -i *.deb

It's not the best solution, but at least now I can edit the configuration files.

Some customized docker images have just the bare minimum dependencies to run. This sometimes means that even apt package manager is not be installed by default and recreating another docker image from scratch is not an option.

But, I realized that most docker images come preinstalled with yum package manager.

So you can install vim or nano using;

yum install vim

or

yum install nano

Here is how you can use wget to fetch and install a nano lib or binary or whatever it was called and then use it in to edit a file in the python:latest image.

$ cd ~
$ wget http://www.nano-editor.org/dist/v2.4/nano-2.4.2.tar.gz

$ tar -xzf nano-2.4.2.tar.gz
$ cd nano-2.4.2
$ ./configure
$ make
$ make install  # removed sudo from this line

test it

$ touch file
$ nano file
# close with `ctrl+z enter`
$ rm file # delete that test file

UPDATE: apt-get worked for me... I bet other people weren't running update first.

$ apt-get update
$ apt-get install nano
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!