Saturday, June 22, 2019

Override env. variable and shell script

Override env. variable and shell script defined in Docker file in run command.

build an image

docker build -t busybox .

run container with env. variable & run CMD in Dockerfile

docker run busybox

override env. variable in Dockerfile
docker run --env ENV_TARGET=yahoo.com busybox

override CMD in Dockerfile
docker run busybox sh -c 'whoami && pwd'

Dockerfile

FROM busybox

WORKDIR /app
ENV ENV_TARGET google.com
COPY subs.sh subs.sh
RUN chmod +x subs.sh
CMD ["/app/subs.sh"]

subs.sh

#!/bin/sh

ping -c 2 ${ENV_TARGET}

No comments:

Post a Comment