Home > Enterprise >  Access argument from docker build inside script
Access argument from docker build inside script

Time:10-16

So in dockerfile I am running entrypoint:

ARG WP_IMAGE=latest
FROM wordpress:$WP_IMAGE

ARG VERSION

RUN curl -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
    && chmod  x /usr/local/bin/wp

RUN apt update && apt install -y vim

ADD ./bin/ /
RUN chmod  x /*.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["apache2-foreground"]

And I have this script entrypoint.sh:

#!/bin/bash

/usr/local/bin/docker-entrypoint.sh php-fpm || /configure.sh

exec "$@"

And there is configure.sh script and inside this script I want to access this argument from Dockerfile VERSION.
This is how I build my docker docker-compose build --build-arg WP_IMAGE=latest --build-arg VERSION=7.0 && docker-compose up -d.

CodePudding user response:

You can use ENV keyword in Dockerfile like:

ARG VERSION
ENV VERSION=${VERSION}

Now the script running in the image can access VERSION from the environment.

The ENV instruction sets the environment variable to the value . The environment variables set using ENV will persist when a container is run from the resulting image.

  • Related