linux上weblogic bilud,如何在docker-compose中定义build-args?

隆钊
2023-12-01

您可以使用docker-compose的构建命令定义args.

Dockerfile:

FROM nginx:1.13

RUN apt-get -y update && apt-get install -y \n apache2-utils && \n rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ARG username

ARG password

RUN htpasswd -bc /etc/nginx/.htpasswd $username $password

docker-compose文件:

version: '3'

services:

node1:

build: ./dir

./dir包含Dockerfile,我用这个命令构建:

docker-compose build --build-arg username="my-user" --build-arg password="my-pass"

我已经看到了:

Step 5/5 : RUN htpasswd -bc /etc/nginx/.htpasswd $username $password

---> Running in 80735195e35d

Adding password for user my-user

---> c52c92556825

我带了我的筹码:

docker-compose up -d

现在我可以在nginx容器内查看,我的用户名和(加密)密码在那里:

docker@default:~/test$docker exec -it test_node1_1 bash

root@208e4d75e2bd:/# cat /etc/nginx/.htpasswd

my-user:$apr1$qg4I/5RO$KMaOPvjbnKdZH37z2WYfe1

使用此方法,您可以将构建args传递给docker-compose堆栈.

 类似资料: