Visual Studio Docker Compose - stop and remove containers after debug session ends

Viewed 484

I have an ASP.NET Core web app for which I have added logging to ElasticSearch & Kibana.
I am running it on a Windows host and the containers are Linux.

The docker-compose file is set to first start up elastic search, then kibana and then finally the web application - as below:

version: '3.4'

services:
  
  elasticsearch:
    container_name: elasticsearch
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
    ports:
      - 9200:9200
    volumes:
      - elasticsearch-data:/usr/share/elasticsearch/data
    environment:
      - xpack.monitoring.enabled=true
      - xpack.watcher.enabled=false
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.type=single-node
    networks:
      - elastic

  kibana:
    container_name: kibana
    image: docker.elastic.co/kibana/kibana:7.9.2
    ports:
      - 5601:5601
    depends_on:
      - elasticsearch
    environment:
      - ELASTICSEARCH_URL=http://localhost:9200
    networks:
      - elastic

  hyena.webapp:
    image: ${DOCKER_REGISTRY-}hyena_image
    build:
      context: .
      dockerfile: Hyena.WebApp/Dockerfile
    ports:
      - "5001:443"
      - "5000:80"
    container_name: "hyena_container" 
    volumes:
      - type: bind
        source: /c/docker/hyena
        target: /data
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200
    networks:
    - elastic

networks:
  elastic:
    driver: bridge

volumes:
  elasticsearch-data:

When I hit Debug (F5), VS starts everything up and I can see in Docker Desktop that the containers are running and I can see that the apps communicate with each other (i.e. logs from the web app appear in Kibana).

enter image description here

Now, when I stop Visual Studio debugging, my webapp is no longer accessible through the browser, however both ElasticSearch and Kibana keep on working.

Docker desktop and docker container ls command all show that the containers are running.

So, my questions are:

  1. If the containers are running, why cannot I access my web app anymore?
  2. Why is it only happening with my web app and not with Kibana or ElasticSearch?
  3. How can I make VS stop and remove these containers after a debug session?

Kind regards, Bartosz

0 Answers
Related