Docker-compose 更新正在运行的容器的端口映射

Docker-compose 更新正在运行的容器的端口映射

运行 Docker Compose 文件,其中端口指令使 Elasticsearch 在所有接口上侦听端口 9200。

version: "3.7"
services:
  elasticsearch:
    container_name: elasticsearch_1
    image: elasticsearch:7.1.1
    ports:
      - "9200:9200"
    networks:
      - elastic_network
    environment:
      - discovery.type=single-node
    deploy:
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
    volumes:
      - /usr/share/elasticsearch/

更新了 Docker 文件,使 elasticsearch 仅侦听 localhost:9200。

version: "3.7"
services:
  elasticsearch:
    container_name: elasticsearch_1
    image: elasticsearch:7.1.1
    ports:
      - "127.0.0.1:9200:9200"
    networks:
      - elastic_network
    environment:
      - discovery.type=single-node
    deploy:
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
    volumes:
      - /usr/share/elasticsearch/

我怎样才能为已经运行的elasticsearch服务执行更新的docker-compose文件。

CONTAINER ID        IMAGE                                    COMMAND                  CREATED             STATUS              PORTS                              NAMES
4832a2df50e1        elasticsearch:7.1.1                      "/usr/local/bin/dock…"   6 days ago          Up 10 minutes       0.0.0.0:9200->9200/tcp, 9300/tcp   elasticsearch_1

相关内容