Docker Community Forums

Share and learn in the Docker community.

Docker Compose Link (Alias)

docker

(Jadozr) #1

I have an Angularjs frontend and a Spring-Boot Rest API in backend. I have create two Docker

DockerFile Front:

FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/

DockerFile Back:

FROM tomcat:8.0
EXPOSE 8080
COPY rest-api.war /usr/local/tomcat/webapps/rest-api.war

I have a Docker-Compose file, i have define Alias

Docker-Compose:

rest:
 image: restapi
 container_name: restapi
 ports:
  - "8080:8080"


frontend:
 image: frontend
 container_name: frontend
 ports:
  - "80:80"

I have redifine the baseURL in my AngularJs controller

app.controller('MainCtrl', function ($scope, $location, $http, MainService) {
    var that = this;
    var baseUrl = 'http://rest:8080';

when i lauchn my app in the console i have this

Error:

GET http://rest:8080/category net::ERR_NAME_NOT_RESOLVED
What is wrong ?

(Nathan Le Claire) #2

I don’t see any links keyword in your Docker Compose file (it’s deprecated anyway, so I recommend using libnetwork).

I’d recommend to use the V2 Compose format and define a network for both containers to live on. Then you can use Docker built-in DNS server to talk back and forth.

Something like this should work:

version: '2'

networks:
    name: mynet

services:
    rest:
      image: restapi
      container_name: restapi
      networks:
        - mynet
      ports:
        - "8080:8080"

    frontend:
      image: frontend
      networks:
        - mynet
      ports:
        - "80:80"

You don’t even need the ports definition in backend if you’re not exposing it to the outside world (i.e. if it’s only accessed by the frontend container).


(Jadozr) #3

why i have this error when i use your docker-compose

←[31mERROR←[0m: In file ‘.\docker-compose.yml’ service ‘version’ doesn’t have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.


(Nathan Le Claire) #4

In order to use the Compose V2 format you need a recent version. Please install the latest Docker Toolbox to get it.