Snowcrash
Snowcrash

Reputation: 86317

DockerFile and environment variable

According to this: https://hub.docker.com/_/mysql/

I can set the MySQL root password with:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

I assumed that MYSQL_ROOT_PASSWORD would be an environment variable that's set using ARG (e.g. Get environment variable value in Dockerfile ) however, looking at the DockerFile (https://github.com/docker-library/mysql/blob/696fc899126ae00771b5d87bdadae836e704ae7d/8.0/Dockerfile ) I don't see this ARG.

So, how is this root password being set?

Upvotes: 0

Views: 449

Answers (2)

Rockvlv
Rockvlv

Reputation: 129

Let me clarify a bit about parameters in Dockerfile.

ARG - is only available during docker image build. Let’s say, you want to store in docker image a hash commit of you source code.

ARG Commit

than you build a docker image:

docker build -t someimage —build-arg Commit=<somehash>

ENV - values that are available for docker containers and can be used as a part of RUN command.

On actual runtime, you can change ENV variable or add new env variables by adding it to run string:

docker run -e SOME_VAR=somevar someimage.

Hope this will help you.

Upvotes: 0

vivekyad4v
vivekyad4v

Reputation: 14903

It's actually used in the entrypoint script -
Ref - https://github.com/docker-library/mysql/blob/696fc899126ae00771b5d87bdadae836e704ae7d/8.0/docker-entrypoint.sh

Entrypoint config in Dockerfile -

COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]

Upvotes: 2

Related Questions