设置环境变量
--env
或者-e
指定docker的环境变量 key=value
<span class="token function">docker</span> run -e <span class="token assign-left variable">POSTGRES_USER</span><span class="token operator">=</span><span class="token string">'postgres'</span> -e <span class="token assign-left variable">POSTGRES_PASSWORD</span><span class="token operator">=</span><span class="token string">'密码'</span> <span class="token punctuation">..</span>. <span class="token function">docker</span> run --env <span class="token assign-left variable">env</span><span class="token operator">=</span>dev -d -p <span class="token number">8888</span>:8080 balance <span class="token function">docker</span> run -e spring.datasource.url<span class="token operator">=</span><span class="token string">'jdbc:mysql://10.0.0.17:3306/laker'</span> -d -p <span class="token number">8080</span>:8080 lak er-java:v1<span class="token function">docker</span> run -e <span class="token assign-left variable">POSTGRES_USER</span><span class="token operator">=</span><span class="token string">'postgres'</span> -e <span class="token assign-left variable">POSTGRES_PASSWORD</span><span class="token operator">=</span><span class="token string">'密码'</span> <span class="token punctuation">..</span>. <span class="token function">docker</span> run --env <span class="token assign-left variable">env</span><span class="token operator">=</span>dev -d -p <span class="token number">8888</span>:8080 balance <span class="token function">docker</span> run -e spring.datasource.url<span class="token operator">=</span><span class="token string">'jdbc:mysql://10.0.0.17:3306/laker'</span> -d -p <span class="token number">8080</span>:8080 lak er-java:v1docker run -e POSTGRES_USER='postgres' -e POSTGRES_PASSWORD='密码' ... docker run --env env=dev -d -p 8888:8080 balance docker run -e spring.datasource.url='jdbc:mysql://10.0.0.17:3306/laker' -d -p 8080:8080 lak er-java:v1
查看环境变量
方式一 docker inspect 命令来查看
<span class="token function">docker</span> inspect 容器id<span class="token function">docker</span> inspect 容器iddocker inspect 容器id
如果是Windows的话可以用可视化界面,原理一样。
方式二 docker exec 容器id env
PS C:<span class="token punctuation">\</span>laker<span class="token punctuation">\</span>laker<span class="token punctuation">\</span>easy-admin<span class="token operator">></span> <span class="token function">docker</span> <span class="token builtin class-name">exec</span> 0d9f644cdce8 <span class="token function">env</span> <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span>/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin <span class="token assign-left variable"><span class="token environment constant">HOSTNAME</span></span><span class="token operator">=</span>0d9f644cdce8 spring.datasource.url<span class="token operator">=</span>jdbc:mysql://10.140.201.17:3306/laker?serverTimezone<span class="token operator">=</span>GMT%2B8<span class="token operator">&</span><span class="token assign-left variable">characterEncoding</span><span class="token operator">=</span>utf8<span class="token operator">&</span><span class="token assign-left variable">useSSL</span><span class="token operator">=</span>false <span class="token assign-left variable">JAVA_HOME</span><span class="token operator">=</span>/usr/local/openjdk-8 <span class="token assign-left variable"><span class="token environment constant">LANG</span></span><span class="token operator">=</span>C.UTF-8 <span class="token assign-left variable">JAVA_VERSION</span><span class="token operator">=</span>8u342 <span class="token assign-left variable"><span class="token environment constant">HOME</span></span><span class="token operator">=</span>/rootPS C:<span class="token punctuation">\</span>laker<span class="token punctuation">\</span>laker<span class="token punctuation">\</span>easy-admin<span class="token operator">></span> <span class="token function">docker</span> <span class="token builtin class-name">exec</span> 0d9f644cdce8 <span class="token function">env</span> <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span>/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin <span class="token assign-left variable"><span class="token environment constant">HOSTNAME</span></span><span class="token operator">=</span>0d9f644cdce8 spring.datasource.url<span class="token operator">=</span>jdbc:mysql://10.140.201.17:3306/laker?serverTimezone<span class="token operator">=</span>GMT%2B8<span class="token operator">&</span><span class="token assign-left variable">characterEncoding</span><span class="token operator">=</span>utf8<span class="token operator">&</span><span class="token assign-left variable">useSSL</span><span class="token operator">=</span>false <span class="token assign-left variable">JAVA_HOME</span><span class="token operator">=</span>/usr/local/openjdk-8 <span class="token assign-left variable"><span class="token environment constant">LANG</span></span><span class="token operator">=</span>C.UTF-8 <span class="token assign-left variable">JAVA_VERSION</span><span class="token operator">=</span>8u342 <span class="token assign-left variable"><span class="token environment constant">HOME</span></span><span class="token operator">=</span>/rootPS C:\laker\laker\easy-admin> docker exec 0d9f644cdce8 env PATH=/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=0d9f644cdce8 spring.datasource.url=jdbc:mysql://10.140.201.17:3306/laker?serverTimezone=GMT%2B8&characterEncoding=utf8&useSSL=false JAVA_HOME=/usr/local/openjdk-8 LANG=C.UTF-8 JAVA_VERSION=8u342 HOME=/root
原文链接:https://blog.csdn.net/abu935009066/article/details/127668740?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171836840916800197020748%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171836840916800197020748&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-12-127668740-null-null.nonecase&utm_term=docker%E3%80%81%E5%A5%BD%E7%94%A8
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END