docker run -e pass environment variables
1. Dockerfile
FROM openjdk:8-jdk-alpine MAINTAINER fengqiangboy shenzhen <fengqiangboy@> RUN mkdir -p /usr/local/proxy-server COPY /usr/local/proxy-server RUN cd /usr/local/proxy-server && \ chmod +x WORKDIR /usr/local/proxy-server # Set the environment variable USERNAME The default value is admin, which can be modified later by docker run -e USERNAME="XXXXXX". This environment variable can also be obtained in the container.ENV USERNAME admin RUN echo 'USERNAME=' $USERNAME # Print the default value# Run the script, $USERNAME passes parameters into the script, and cannot use CMD [], variables cannot be read in this wayCMD sh $USERNAME
2.
#!/bin/bash MODULE=$1 # Define the variable to the first parameter of $USERNAME passed aboveecho 'MODULE=' ${MODULE} # Print
If you want to replace the parameters, use the command
sed -i "s/<USERNAME>/$USERNAME/"
, double quotes must be used, variables cannot be read in single quotes
View the final file directory
[root@wanfei test-docker]# ls Dockerfile
3. Make a mirror
[root@wanfei test-docker]# docker build -t www/test-docker .
4. Run the mirror
[root@wanfei test-docker]# docker run --name docker -e USERNAME="WANFEI" www/test-docker MODULE= WANFEI
Print successfully
WANFEI
This is the article about docker run -e passing environment variables. For more related docker run -e passing environment variables, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!