Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

How to Install Linux Packages Inside a Docker Container?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Once you understand how to pull base Docker Images from the Docker registry, you can now simply pull OS distributions such as Ubuntu, CentOS, etc directly from the Docker hub. However, the OS Image that you have pulled simply contains a raw file system without any packages installed inside it. When you work on projects inside Docker Containers, you will definitely need some libraries and packages either right from the beginning of the development phase or on the go. 

In this article, we will see how to install packages and libraries inside Docker Containers using 2 different methods. We will also try to install Firefox and vim text editor inside Ubuntu Docker Container.

Method 1: Using Command Line Interface

Step 1: Open the terminal of your local system and run the Ubuntu Docker Image from the Docker Registry. If your system has no previous pulls, it will start pulling from the registry.

sudo docker run -it ubuntu bash
Running Ubuntu Container

Running Ubuntu Container

Step 2: Now, you have opened the bash of your Ubuntu Docker Container. To install any packages, you first need to update the OS.

apt-get -y update
Updating the Container

Updating the Container

Step 3: After you have updated the Docker Container, you can now install the Firefox and Vim packages inside it.

apt-get -y install firefox
apt-get -y install vim

Installing Firefox

Installing Firefox

Installing Vim

Installing Vim

You can now easily use these packages through the bash itself.

Method 2: Using Dockerfile

You can also directly specify the packages you need to install in the dockerfile using the RUN instruction. This method is preferable over the CLI method because building a dockerfile is very essential if you are working on projects inside Docker. It gives better version control and provides a blueprint of the entire Docker Image.

Step 1: Write your instructions inside a dockerfile.

FROM ubuntu:latest
RUN apt-get -y update && apt-get -y install firefox && apt-get -y install vim

Step 2: Build the Image using the Docker Build command.

sudo docker build -t sample-image .
Building the Image

Building the Image

Step 3: Run the container and verify the installed packages

sudo docker run -it sample-image bash
vim
firefox

Running the Container

Running the Container

Vim Text Editor running inside Container

Vim Text Editor running inside Container

My Personal Notes arrow_drop_up
Last Updated : 06 Oct, 2021
Like Article
Save Article
Similar Reads