ARG

On building a docker image you may want to have some variables (you can also have them in docker-compose)

you can define ARG in docker file (you can also set default value for them in docker file)

for example :

# in docker file
ARG some_variable_name = xxxx
ARG uid

#on building image : 
$ docker build --build-arg some_variable_name=a_value

ENV

ENV variables are also available during the build, as soon as you introduce them with an ENV instruction. However, unlike ARG, they are also accessible by containers started from the final image. ENV values can be overridden when starting a container, more on that below.

# no default value
ENV hey
# a default value
ENV foo /bar
# or ENV foo=/bar

# ENV values can be used during the build
ADD . $foo
# or ADD . ${foo}
# translates to: ADD . /bar


on running docker : 
$ docker run -e "env_var_name=another_value" alpine env

RUN

for example :

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

ADD , COPY

COPY and ADD are both Dockerfile instructions that serve a similar purpose. They let you copy files from a specific location into a Docker image.

ADD

ADD  does that same but in addition, it also supports 2 other sources. 

  1. A URL instead of a local file/directory.
  2. Extract tar from the source directory into the destination.

COPY

COPY takes in a source and destination. It only lets you copy in a local or directory from your host (the machine-building the Docker image) into the Docker image itself.

for example :

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR

for example:

# Set working directory
WORKDIR /var/www

USER

for example:

USER $user

Leave a Reply

Your email address will not be published. Required fields are marked *