[Docker Container] Failed to install apt package inside container?

Docker is a great tool for virtual development. Its like a virtual machine but not like virtual machine. Its means its create an isolated environment where every application have isolated setup for their own package.

I am not going to describe the definition of docker from beginning but if you are interested you can check out this link below

Docker beginner journey

Lets Jump into the topic

Why apt package not found inside container?

Though docker creates an isolated environment but Docker container has no kernel of his own, Containers run based on your host kernel. Its like a child inside mother belly having brain :p I mean if you use CentOs you can still install Ubuntu by docker but Ubuntu will use the CentOs kernel, because host Os is CentOs.

Though the container serve from host OS kernel, several package of your host OS wont available inside running container. Because docker image will install specific things which was instructed in dockerfile.

I assume you know that already.

So how we install apt packages inside a container?

Might be you already tried to open any file by

shell> nano test.log

But it wont open, It will through error, it will say

bash: nano: command not found

But when you try to install nano

shell> sudo apt-get install nano

It will say

E: Unable to locate package nano

So, Whats the solution?

Solution is, run

shell> sudo apt-get update

After finished all the scanning, run

shell> sudo apt-get install nano

Your nano package will be installed now.

Next time, when you need to install something you don’t need to run apt-get update again.

Love to work with new technologies, explore new challenges and watch Movies & Anime