Skip Docker Argument

There is a dynamic field in my docker socket file that I would like to create at runtime. This is actually a string pattern:

environment:
    - SERVER_URL:https://0.0.0.0:${PORT}

And I want to configure this parameter PORTdynamically

docker-compose run <service> PORT=443

The documentation has a set of parameters ARGSI suppose I can use. But there is no information how I can use those that are inside the compose file

+9
source share
4 answers

In docker-compose, arguments are available and only useful in dockerfile. You can indicate what you are doing at the next level:

#dockerfile
ARG PORT
ENV SERVER_URL "https://0.0.0.0:$PORT"

Your port can be set in the docker-compose.yml file:

build:
  context: .
  args:
    - PORT=443

. , :

PORT=443 docker-compose run <service>
#or
docker-compose run <service> -e PORT=443
+5

docker-compose

docker-compose build --build-arg PRODUCTION=VALUE

Dockerfile

# Dockerfile
ARG PRODUCTION
FROM node:latest
+1

stack deploy

:

- MY_VARIABLE_NAME=${MY_VARIABLE_VALUE}

( Gitbash Windows):

MY_VARIABLE_VALUE=some-value docker stack deploy --compose-file compose_file_here stackname


. Github

0

Docker-Compose .

https://docs.docker.com/compose/compose-file/#variable-substitution

docker-compose -e PORT 443 -f docker-compose.yml
0

Source: https://habr.com/ru/post/1675353/


All Articles