Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use variables in docker-compose in docker Swarm

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to use variables in docker-compose in docker Swarm". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use variables in docker-compose in docker Swarm.

First take a look at a yml file of docker-comose

Version: "3.2" services: docker-test: hostname: docker-test image:'${DOCKER_REGISTRY_URL} / dockerteam/docker-test:1.0' ports:-"9118" env_file: .env deploy: replicas: 1 restart_policy: condition: on-failure placement: constraints: [node.role== worker] resources: limits:# Cpus:'1' memory: 1GB reservations:# cpus: '0.2' memory: 512m

As in the file above, env_file is supported in the docker-comose command, just provide the corresponding .env file and set the ${DOCKER_REGISTRY_URL} variable in the .env file.

But what if it is invalid for docker-comose to use env_file online in a docker swarm cluster environment? Instead of using the .env file at this time, I tried to add the variable to the host environment variable:

Export DOCKER_REGISTRY_URL=docker.sifu.cn:12135

Run the docker stack command again and the service is deployed successfully.

Note: the above added environment variables are only for testing. If the situation is real, please add the corresponding environment variables in the / etc/profile file.

At this point, I believe you have a deeper understanding of "how to use variables in docker-compose in docker Swarm". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report