0

Below one is my docker build command

docker build -t test/magento2:1.0.0 --build-arg BASE_URL=http://www.hostname.net/ --build-arg DATABASE_HOST=localhost --build-arg DATABASE_NAME=magento --build-arg DATABASE_USER=root --build-arg DATABASE_PASSWORD=root --build-arg ADMIN_USERNAME=test --build-arg ADMIN_FIRSTNAME=test --build-arg ADMIN_LASTNAME=Mobi --build-arg ADMIN_EMAIL=support@test.mobi --build-arg ADMIN_PASSWORD=test@123 --build-arg DEFAULT_LANGUAGE=en_US --build-arg DEFAULT_CURRENCY=INR --build-arg DEFAULT_TIMEZONE=Asia/Kolkata --build-arg BACKEND_FRONTNAME=admin .

Dockerfile

ARG BASE_URL
ARG DATABASE_HOST
ARG DATABASE_NAME
ARG DATABASE_USER
ARG DATABASE_PASSWORD
ARG ADMIN_USERNAME
ARG ADMIN_FIRSTNAME
ARG ADMIN_LASTNAME
ARG ADMIN_EMAIL
ARG ADMIN_PASSWORD
ARG DEFAULT_LANGUAGE
ARG DEFAULT_CURRENCY
ARG DEFAULT_TIMEZONE
ARG BACKEND_FRONTNAME

RUN service mysql start && \
    cd /var/www/html && php bin/magento setup:install --base-url=$BASE_URL --db-host=$DATABASE_HOST --db-name=$DATABASE_NAME --db-user=$DATABASE_USER --db-password=$DATABASE_PASSWORD --admin-firstname=$ADMIN_FIRSTNAME --admin-lastname=$ADMIN_LASTNAME --admin-email=$ADMIN_EMAIL --admin-user=$ADMIN_USERNAME --admin-password=$ADMIN_PASSWORD --language=$DEFAULT_LANGUAGE --currency=$DEFAULT_CURRENCY --timezone=$DEFAULT_TIMEZONE --use-rewrites=1 --backend-frontname=$BACKEND_FRONTNAME

It is working fine, but I'm looking something

docker run <here I need to pass my arguments>

I'm thinking about ENV but it makes confusion. I don't know how to pass env variable from docker run command to dockerfile.

I believe there is a way to done.

can anyone help me on this?

user2915097
  • 30,758
  • 6
  • 57
  • 59
Bilal Usean
  • 2,322
  • 3
  • 22
  • 45

1 Answers1

2

you can pass argument to

docker run

so, when you run a container

just check

docker run --help

and you will get, among other things

-e, --env value Set environment variables (default []) --env-file value Read in a file of environment variables (default [])

ENV is taken care of at build time

if you want

"I don't know how to pass env variable from docker run command to dockerfile"

you can't, docker run starts a container from a created image, a Dockerfile helps you build a new image

The flow

A Dockerfile -> docker build -t myuser/myimage:v12.3 . my new image

launch a container docker run myuser/myimage:v12.3 myoptions from my image myuser/myimage:v12.3

user2915097
  • 30,758
  • 6
  • 57
  • 59
  • thanks! I need to run above `dockerfile RUN` while create container. what options I need to use? is CMD suite? – Bilal Usean Apr 20 '17 at 07:06
  • Check `docker run --env` – user2915097 Apr 20 '17 at 07:21
  • I know buddy `docker run -e` command. When I run this I need to install magento as per env variable. My doubt is where I need to write this logic to install magento in dockerfile. This is I'm looking exactly, in below link he target the shell script to install magento https://github.com/alankent/docker-magento2-demo-apache/blob/master/Dockerfile#L33 docker run commands seems `docker run -e PUBLIC_HOST=yourhost.example.com .....` As per my understanding dockerfile RUN does't execute while `docker run`, then how he execute shell script while `docker run`. – Bilal Usean Apr 20 '17 at 07:34
  • notice at the end of your link `ENTRYPOINT ["bash", "-c"] CMD ["/usr/local/bin/runserver"]` the CMD and ENTRYPOINT are starting the process in the image – user2915097 Apr 20 '17 at 07:39
  • Your Dockerfile lacks a CMD or ENTRYPOINT, check http://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile – user2915097 Apr 20 '17 at 07:43