If you can’t run curl, vi, nano, bash, wget and similar commands inside an Alpine Docker container, it is very likely that those packages are not pre-installed to your image when it is being built.

In such cases, you can simply run below commands to install necessary packages to your Alpine Docker container.

// Determine Docker container name and get shell access to it
$ docker ps
$ docker exec -it <container_name> sh

// Update your current package list
$ apk update

// Install curl 
$ apk add curl
$ curl --version

// Install wget
$ apk add wget
$ wget --version

// Install vim 
$ apk add vim
$ vi --version

// Install nano
$ apk add nano
$ nano --version

// install bash and switch current shell to bash
$ apk add bash
$ bash --version
$ bash

// Add any other package
$ apk add <package_name>

// Search more packages
$ apk search -v 'node'

Add packages to Dockerfile

In case if you need these packages frequently, adding them to Dockerfile will help you pre-install all of them when the Docker image is being built.

RUN apk add --no-cache <package_name>

A sample Dockerfile for a Node.js application with such package installation is mentioned below.

$ vi Dockerfile

FROM node:10-alpine

RUN apk update && apk add --no-cache curl vim wget bash

RUN mkdir -p /src/app
WORKDIR /src/app

COPY package.json /src/app/package.json
RUN npm install
COPY . /src/app

EXPOSE 3000
CMD [ "npm", "start" ]

Now you can access your container with bash shell and use the above-installed packages straightaway.

$ docker ps
$ docker exec -it <container_name> bash

👉 Any questions? Please comment below.


Leave a comment