Search code examples
dockerdocker-build

Docker - dockerfile parse error on unknown instruction: [global]


How to fix Docker error Failed to solve: dockerfile parse error on line xx: unknown instruction: [global].

FROM ubuntu:latest

RUN /bin/bash -c 'cat <<EOF > /etc/pip.conf.d/pip.conf
[global]
index-url = https://repo.org/pypi/org.python.pypi/simple
trusted-host = repo.org
EOF'

Solution

  • Docker can't see that the RUN statement continues on the next line. To fix it, you can use heredoc on the RUN statement as well, so you get something like this

    FROM ubuntu:latest
    
    RUN <<EOF_RUN
    cat <<EOF > /etc/pip.conf.d/pip.conf
    [global]
    index-url = https://repo.org/pypi/org.python.pypi/simple
    trusted-host = repo.org
    EOF
    EOF_RUN
    

    or use a COPY statement, which also supports heredoc, for something a little bit cleaner, like this

    FROM ubuntu:latest
    
    COPY <<EOF /etc/pip.conf.d/pip.conf
    [global]
    index-url = https://repo.org/pypi/org.python.pypi/simple
    trusted-host = repo.org
    EOF