Unable to install vim or nano inside docker container

Trying to install inside a docker, either vim or nano but I only get this:

0% [Connecting to archive.ubuntu.com (91.189.88.152)]

Exit docker and do ping archive.ubuntu.com and I get reply, do the same time inside docker it does not respond.

What could be the problem?


Solution 1:

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

Solution 2:

Here is how you can use wget to fetch and installnano and then use it in to edit a file in the python:latest docker 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

Now 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

Solution 3:

Question is very old but if anyone looking for the solution, here's how I have solved it, in my Dockerfile I have written this :

RUN apt-get -y update
RUN apt-get -y install vim nano

-y gives automatic yes to continue the command. Works like a charm!

Solution 4:

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