一个Docker容器如何调用另一个Docker容器 [英] How can one Docker container call another Docker container

查看:503
本文介绍了一个Docker容器如何调用另一个Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Docker容器

I have two Docker containers


  1. 一个Web API

  2. 一个调用Web的控制台应用程序API

现在,在我的本地Web api上是本地主机,控制台应用程序调用该API没问题。但是,我不知道当这两个东西都经过Dockerized处理后,我如何才能使Dockerized API网址可用于Dockerized Console应用程序?

Now, on my local web api is local host and Console application has no problem calling the API.However, I have no idea when these two things are Dockerized, how can I possibly make the Url of Dockerized API available to Dockerized Console application?

我不认为我需要Docker Compose是因为正在将API的Url作为API的参数传递,因此仅需确保 Dockerized Console Dockerized API的 url即可访问/ code>

i don't think i need a Docker Compose because I am passing the Url of API as an argument of the API so its just the matter of making sure that the Dockerized API's url is accessible by Dockerized Console

有什么想法吗?

推荐答案

使用撰写功能可以轻松解决问题。使用compose,您只需创建一个配置文件( docker-compose.yml ),如下所示:

The problem can be solved easily if using compose feature. With compose, you just create one configuration file (docker-compose.yml) like this :

version: '3'
services:
  db:
    image: postgres
  web:
    build: .
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

要使其运行,只需调用 up 像这样:

To make it run, just call up like this :

docker-compose up 

这是运行所有堆栈的最佳方法,因此,请检查此引用:
https://docs.docker.com/compose/

This is the best way to run all your stack, so, check this reference : https://docs.docker.com/compose/

成功!

这篇关于一个Docker容器如何调用另一个Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆