Docker Community Forums

Share and learn in the Docker community.

Install vim in docker container on creation?

(Twigz) #1


I would have thought I’d figure this out by now, but I can’t. How can I install packages onto my container once the image is being built?

I thought you could do it by:

    context: .
    dockerfile: Dockerfile

 FROM app
 RUN apt-get update && apt-get install vim -y &&
 apt-get install nmap -y

But this does not work. Any help would be appreciated.

(Bodnar) #2

Your Dockerfile needs a valid image defined in the FROM command. By the looks of it, you are trying to run apt, which is typically from an ubuntu/debian linux. Try adding FROM ubuntu:latest to your Dockerfile.

As a side note, you wont need to split your apt-get install packages like that. You can do all at once like:

FROM ubuntu:latest
RUN apt-get update \
    && apt-get install -y \
        nmap \

It is recommended to split your commands & packages by line and sort them so it is easier to maintain.

(Twigz) #3

Thanks for taking the time to respond.

A couple of follow up questions:

  1. In your example, is this not creating an Ubuntu container? If it is, this seems like a wasted container as it would just be a fresh Ubuntu install with my desired packages. It would seem to be better to just install my packages on an already existing container, e.g., nginx image.

  2. Also, I though nginx, would a valid image since it’s what I am calling. Or does this mean, a valid image that is capable of making the commands? For instance, in this example, “RUN nginx start” would be acceptable.

  3. If I run the container in your example, will all other containers be able to use those installed packages as well or do I have to “link” them in order to be used?

Thanks again

(John Rofrano) #4

It would seem to be better to just install my packages on an already existing container, e.g., nginx image.

If you wanted to add to the nginx image the proper way would be to build a new image FROM the nginx image like this:

FROM nginx
RUN apt-get update \
    && apt-get install -y \
        nmap \

This would give you a new image with nginx and whatever else you want. if you just want to add static content then that is an easy way to do it. Just add COPY commands to your Dockerfile to add your content.

If, however, you are building a dynamic web application, I would not install anything into the nginx image except a config file that forwards requests to your application running in another container. You can use docker-compose to specify the dependencies and bring both containers up and down together.