How to deploy an Angular application and a REST Api in individual docker containers?

前端 未结 2 1997
时光取名叫无心
时光取名叫无心 2021-01-15 20:33

I have a very similar question as this one.

I do have an Angular application that collects data which are then processed via a REST Api. I can happily dockerize both

2条回答
  •  庸人自扰
    2021-01-15 21:23

    When you use localhost in a container, it means the container itself, not the host running the container. So if you're pointing to "localhost" from a second container (the UI in your case), that new container will look at itself, and doesn't find the API.

    One of the option to solve your problem is to make your containers reachable by name.

    The easiest way to do it, in your case, is using docker-compose: eg:

    version: '3'
      services:
        angular:
          image: "form_angular:v1"
          container_name: "form_angular"
          ports:
            - "8088:80"
          external_links:
            - restapi
    
        restapi:
          image: "form_rest:latest"
          container_name: "form_rest"
          ports:
            - "3000:3000"
          external_links:
            - angular
    

    And with that, from the angular you can reach the restapi using the name (as a DNS) restapi, and angular from the restapi.

    I suggest you to read more about docker-compose at https://docs.docker.com/compose/

    It is very versatile and easy, and you can live with it for a long time, until you decide to build your own cloud ;)

提交回复
热议问题