Search code examples
mysqldockerlesspager

How do you install ´less´ command in Docker container?


I'm using a mariadb container:

image: mariadb:10.5.8

While in the container and in a mysql session I'm trying to set:

pager less -SFX

When I run:

select * from sometable;

I get

sh: 1: less: not found

The reason I want to set pager less -SFX is so that the terminal output table would format correctly. How do I install less in this container?


Solution

  • If you only need less in the interactive session you can simply install it with apt before entering mysql:

    apt update && apt install less
    

    If you want less to be always installed and available you need to create a new docker image based on the mariadb image where you add less:

    # images/Dockerfile
    FROM mariadb:10.5.8
    
    RUN apt update && apt install -y less
    

    And to use it replace the image property in your docker-compose.yml with

        build: ./images/