Docker How To Install Packages
These are the commands you would generally use to install a package on a Debian/Ubuntu based system ( nginx as an example ):
sudo apt update -y # update repo info
sudo apt install nginx -y # install package
Install Package as Part of Docker Build
Use the following steps to install a package in a docker image and container:
Create a project dir:
mkdir test1
cd test1
Create a docker file:
vi DockerfileFROM ubuntu RUN apt update -y RUN apt install nginx -y
Build it:
docker build -t mygoodimage .
Run your image as a container:
docker run -i -t mygoodimage
Install Package on Running Container
Launch a shell on a running container named “inspiring_dhawan”:
docker exec -it inspiring_dhawan bash
Update repo and install packages. You normally won’t need sudo since you will be running as root inside the container.
apt update -y
apt install nginx -y