The RUN keyword

The next important keyword is RUN. The argument for RUN is any valid Linux command, such as the following:

RUN yum install -y wget

The preceding command is using the CentOS package manager yum to install the wget package into the running container. This assumes that our base image is CentOS or RHEL. If we had Ubuntu as our base image, then the command would look similar to the following:

RUN apt-get update && apt-get install -y wget

It would look like this because Ubuntu uses apt-get as a package manager. Similarly, we could define a line with RUN like this:

RUN mkdir -p /app && cd /app

We could also do this:

RUN tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz

Here, the former creates a /app folder in the container and navigates to it, and the latter untars a file to a given location. It is completely fine, and even recommended, for you to format a Linux command using more than one physical line, such as this:

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
libexpat1 \
libffi6 \
libgdbm3 \
libreadline7 \
libsqlite3-0 \
libssl1.1 \
&& rm -rf /var/lib/apt/lists/*

If we use more than one line, we need to put a backslash (\) at the end of the lines to indicate to the shell that the command continues on the next line.

Try to find out what the preceding command does.