Docker's role is to provide an isolated environment for the application to facilitate deployment.
Dockerfile has an env option that lets us add some environment variables to the generated image, and what these environment variables do.
Can be used as a flag to represent some parameters for the deployed environment.
For example, we need a docker to deploy a MySQL. Then we can add an identity to indicate how this MySQL is started, such as can be started by cluster mode, or can be started by a single machine, it is obvious that the two modes of the start command is different.
Then we can use the Dockerfile env to implement this automated startup application process.
For example, we can provide a default env in Dockerfile with a value of non-cluster, which means that the default startup mode is standalone.
Thus, when we run a container, if we do not overwrite this parameter, then the environment variable is non-cluster. Instead, we can override this parameter to cluster by using the-e parameter of Run or docker-compose environment, and the environment variable in the container that starts is cluster.
This is the role of environment variables, and we can specify the container's environment variables when we run a container to represent different startup parameters.
But the light has this environment variable and there is no egg, because it is only a variable or identification, and further we need a shell script to read the environment variables to determine how we start, and thus run the corresponding command. This script can be added to the container via the Add command, and then run with cmd or entrypoint.
Therefore, personal feeling, through the environment variable + start the script to maximize the implementation of the deployment of the application automation. The real boot process command is in the script, and the script reads the environment variables we set.
A small example:
Dockerfile
From Ubuntu:latest
ADD./run.sh/
run chmod 777/run.sh
CMD ["/run.sh"]
Docker-compose:
Version: ' 3.2 '
services:
app1:
image:test-env
Environment:
-e1=10
Run.sh:
#!/bin/bash
If [$E 1-lt] then
echo "yes"
else
echo "No"
fi
The output content is judged by passing different E1.