Here is a more detailed guide on how to install an application inside a Docker container by going inside the container:
Step 1: Start the Container
Before you can install an application inside a Docker container, you need to start the container. You can do this by running the following command:
docker start <container_name>
Replace with the actual name of your container.
Step 2: Exec into the Container
Once the container is running, you can access its terminal by using the docker exec command. This allows you to execute commands inside the container as if you were sitting in front of it. To do this, run:
docker exec -it <container_name> /bin/bash
The -it flags stand for “interactive” and “tty”, which allow you to interact with the container’s terminal. /bin/bash specifies the command to run inside the container, which in this case is the Bash shell.
Step 3: Install Dependencies
Now that you’re inside the container, you can install dependencies and the application using package managers like apt-get, pip, or npm. For example, if you’re using Ubuntu-based container, you can update the package list and install a package like this:
apt-get update
apt-get install -y <package_name>
Replace with the actual name of the package you want to install.
Step 4: Exit the Container
Once you’ve finished installing and configuring the application, you can exit the container by typing exit. This will return you to your host machine’s terminal.
Example Scenario
Let’s say you want to install a vim application inside a Docker container. You’ve already created a container named my-node-app from the official Node.js image. Here’s how you could install the application:
- Start the container: docker start my-app
- Exec into the container: docker exec -it my-app /bin/bash
- Install dependencies: For Alpine,Â
vi
 is installed as part of the base OS. InstallingÂvim
 would be: apk -U add vim For Debian and Ubuntu: apt-get update && apt-get install -y vim For CentOS,Âvi
 is usually installed with the base OS. ForÂvim
: yum install -y vim - Exit the container: exit