The error you are seeing is because you run a command in the background and ask the shell to conditionally run another command based on the exit status of the background command. There isn't a way for the shell to do that logically. You can remove the &&
after the background process, but you are left with a bigger issue.
The result of a RUN
command in a Dockerfile is the filesystem changes after the pid 1 exits. With a command in the background, pid 1 (your shell) will immediately exit (when it runs out of commands to run). Background processes will be killed with the termination of the container. And changes to the shell state like variables being exported are lost when the shell running as pid 1 exits.
For your purposes, you likely want to move the background processes to part of your container entrypoint. E.g.
RUN apt-get update -yqq \
&& apt-get install -yqq --no-install-recommends \
python3-pip \
python3-requests \
software-properties-common \
python-software-properties \
xvfb \
&& rm -rf /var/lib/apt/lists/*
ENTRPOINT Xvfb :99 & \
export DISPLAY=:99 \
&& some-command-that-needs-a-ui
Note that I've removed the apt-get upgrade
, if you need packages upgraded in your image, then I'd do that with a newer base image. I typically make my entrypoint a shell script instead of long command like this, you may find it easier to move the above into an entrypoint.sh with contents like:
#!/bin/sh
set -ex
Xvfb :99 &
export DISPLAY=:99
some-command-that-needs-a-ui
Note that in both of these examples, you need to specify your some-command-that-needs-a-ui
. I can't say what that is since you didn't include it in the question.