WebSocket connection between two containers in Docker can not be established

100 views Asked by At

I have some problem with websocket connection between two containers in Docker. In generally I have a kurento server which runs in Docker container, and I developed a demo application that communicates with kurento server via provided Java SDK which under the hood uses websocket connection for it. So when I try to run them in Docker using container name as a host for websocket connection URL it fails with exception:

Unknown host name: kms.

Please can you help with solving this problem.

Here is my Docker compose file:

version: '3.3'

services:
  kms:
    image: kurento/kurento-media-server:latest
    ports:
    - "8888:8888"
    container_name: kms
    volumes:
      - type: bind
        source: ./docker/kurento/
        target: /etc/kurento
    networks:
      - main-net

  kurento-demo-server:
    container_name: kurento_demo_server
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - kms
    ports:
    - "8443:8443"
    networks:
      - main-net

networks:
  main-net:
    name: main-net
    driver: bridge

Docker File for demo-app:

FROM maven:3.8.4-openjdk-17 AS build

WORKDIR /app/

COPY pom.xml .
COPY src ./src

RUN mvn clean package

FROM openjdk:17

WORKDIR /app/

COPY --from=build /app/target/demo-kurento-0.0.1-SNAPSHOT.jar ./app.jar

EXPOSE 8443

CMD ["java", "-jar", "app.jar"]

And there is how I create KurentoClient for communication with the server:

@Configuration
public class KurentoConfig {

    private static final String KURENTO_URL = "ws://kms:8888";

    @Bean
    public KurentoClient createKurentoClientBean() {

        return KurentoClient.create(KURENTO_URL);
    }
}
0

There are 0 answers