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'
2 Answers 2
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
Comments
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.