1

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'
asked Feb 21, 2025 at 7:23

2 Answers 2

3

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
answered Feb 21, 2025 at 9:00
Sign up to request clarification or add additional context in comments.

Comments

0

You can avoid this quoting problem entirely by creating the file on the host system and then COPYing it into the image.

# on the host, pip.conf
[global]
index-url = https://repo.org/pypi/org.python.pypi/simple
trusted-host = repo.org
# in the Dockerfile
COPY pip.conf /etc/pip.conf.d/pip.conf

If you need to change some contents of the file at image-build time it may be possible to use sed(1) or envsubst(1) to post-process it, like

COPY pip.conf.tmpl /tmp
RUN sed -e s/PYPI_HOST/repo.org/g /tmp/pip.conf.tmpl > /etc/pip.conf.d/pip.conf

Docker automatically wraps RUN commands' contents in sh -c for you and you never need to RUN bash -c '...'. Removing a layer of quoting may help some similar problems.

answered Feb 21, 2025 at 11:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.