dockerdebian-stretch

Problems installing csvtk with Docker using debian:stretch-slim


I am a newbie to Docker and I am trying to install csvtk via Docker using debian:stretch-slim.

This below is my Dockerfile

FROM debian:stretch-slim
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    jq                 \
    perl               \
    python3            \
    wget               \
    && rm -rf /var/lib/apt/lists/*

RUN wget -qO- https://github.com/shenwei356/csvtk/releases/download/v0.23.0/csvtk_linux_amd64.tar.gz | tar -xz \
     && cp csvtk /usr/local/bin/

It fails at the csvtk step with the below error message:

Step 3/3 : RUN wget -qO- https://github.com/shenwei356/csvtk/releases/download/v0.23.0/csvtk_linux_amd64.tar.gz | tar -xz      && cp csvtk /usr/local/bin/
 ---> Running in 0f3a0e75a5de

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
The command '/bin/sh -c wget -qO- https://github.com/shenwei356/csvtk/releases/download/v0.23.0/csvtk_linux_amd64.tar.gz | tar -xz      && cp csvtk /usr/local/bin/' returned a non-zero code: 2

I would appreciate any help/suggestions.

Thanks in advance.


Solution

  • wget was exiting with error code meaning 5 SSL verification failed on wget. From this answer, you just needed to install ca-certificates before wget.

    This Dockerfile should build successfully:

    FROM debian:stretch-slim
    RUN apt-get update \
        && apt-get install -y --no-install-recommends \
        jq                 \
        perl               \
        python3            \
        wget               \
        # added this package to help with ssl certs in Docker
        ca-certificates    \
        && rm -rf /var/lib/apt/lists/*
    
    RUN wget -qO- https://github.com/shenwei356/csvtk/releases/download/v0.23.0/csvtk_linux_amd64.tar.gz | tar -xz \
         && cp csvtk /usr/local/bin/
    

    As a general tip when debugging issues like these, it's likely easiest to remove the offending RUN line from your Dockerfile and then try building and running the container in a shell and manually executing the commands you want. Like this:

    docker build -t test:v1 .
    docker run --rm -it test:v1 /bin/bash
    # run commands manually and check the full error output
    

    While combining different RUN instructions with && is best practice to reduce the number of image layers, it's difficult to debug when building.