Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create Dockerfile to RUN command with "&"?

I have the following command in a Dockerfile. Which is executed everytime I create a new image. The issue is that this command fails because I have a & in Xvfb :99 &. What is a good way around it? Adding quotes did not help.

RUN set -ex \
&& apt-get update -yqq \
&& apt-get upgrade -yqq \
&& apt-get install -yqq --no-install-recommends \
    python3-pip \
    python3-requests \
    software-properties-common \
    python-software-properties \
    xvfb \
&& Xvfb :99 & \
&& export DISPLAY=:99 

Here is the exact error: /bin/sh: 1: Syntax error: "&&" unexpected

like image 772
Tigerjz32 Avatar asked Dec 02 '25 22:12

Tigerjz32


1 Answers

When trying to run multiple commands with background process you have to group the command and & using ().
so The run statement should look as follows.

RUN set -ex \
&& apt-get update -yqq \
&& apt-get upgrade -yqq \
&& apt-get install -yqq --no-install-recommends \
    python3-pip \
    python3-requests \
    software-properties-common \
    python-software-properties \
    xvfb \
&& ( Xvfb :99 & ) \
&& export DISPLAY=:99

Reference: Run multiple commands as bg in Linux

like image 136
Mani Avatar answered Dec 04 '25 11:12

Mani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!