dockerdockerfile

docker image created from Dockerfile cannot run


I'm playing around with Nvidia RAPIDS docker container. When I run their docker directly, I can see the container up and running:

docker run --gpus all --pull always --rm -it -d --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 rapidsai/base:24.12-cuda12.5-py3.12

shows

CONTAINER ID   IMAGE                                 COMMAND                  CREATED         STATUS         PORTS     NAMES
1a8732f6b7c6   rapidsai/base:24.12-cuda12.5-py3.12   "/home/rapids/entryp…"   3 seconds ago   Up 2 seconds             happy_brahmagupta

Now this container does not have specific binaries I want. For example, vim. So I created a new Dockerfile that uses this image:

FROM rapidsai/base:25.02a-cuda11.8-py3.12-amd64
WORKDIR /home/rapids

CMD ["apt-get", "install", "vim"]

When I build and run the image, I see no container running:

docker run --gpus all --pull always --rm -it -d --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 samanaghazadeh/custom-docker

gives me

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

If I add /bin/bash at the end of the command, I can see the container running. But then, I cannot run vim. Looks like CMD ["apt-get", "install", "vim"] is not even executed.

I'm very new to Docker and cannot understand what I'm doing wrong.


Solution

  • Install vim with apt-get in a RUN command.

    # Use the existing rapidsai/base image as the base
    FROM rapidsai/base:25.02a-cuda11.8-py3.12-amd64
    
    # Update package lists and install vim
    RUN apt-get update && \
        apt-get install -y vim && \
        rm -rf /var/lib/apt/lists/*
    
    # (Optional) Set the default command if needed
    # This step is usually unnecessary unless you want to override the base image's CMD or ENTRYPOINT
    # CMD ["bash"]
    

    You can then build the image docker build -t rapidsai-with-vim:latest .

    And run the image docker run -it rapidsai-with-vim:latest bash

    Once inside the container, try launching vim: vim --version