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 [email protected] --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?

6
  • maybe using ARG in docker file? Commented Jul 27, 2017 at 11:53
  • How did you solve this problem. I am on something similar on docker magento2 container Commented Nov 27, 2017 at 10:41
  • @TaraPrasadGurung up to my mind, I added entrypoint, which executes shell script while docker run, that shell script check whether the magento is installed or not. If not install, it installs. If install, it ignores. Commented Nov 27, 2017 at 11:02
  • what about the paramters to pass with run with -e from where are you passing that Commented Nov 27, 2017 at 11:08
  • e.g) docker run -e a=b.... use this environment value in entrypoint shell script to install magento Commented Nov 27, 2017 at 11:18

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

5 Comments

thanks! I need to run above dockerfile RUN while create container. what options I need to use? is CMD suite?
Check docker run --env
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 github.com/alankent/docker-magento2-demo-apache/blob/master/… 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.
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
Your Dockerfile lacks a CMD or ENTRYPOINT, check stackoverflow.com/questions/21553353/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.