docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > docker-compose java.net.UnknownHostException

docker-compose java.net.UnknownHostException问题

作者:胖胖胖胖胖虎

这篇文章主要介绍了docker-compose java.net.UnknownHostException问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

docker-compose java.net.UnknownHostException

在这里插入图片描述

historyserver      | Caused by: java.lang.RuntimeException: Could not resolve Kerberos principal name: java.net.UnknownHostException: historyserver: historyserver: Name or service not known
historyserver      |    at org.apache.hadoop.security.AuthenticationFilterInitializer.getFilterConfigMap(AuthenticationFilterInitializer.java:90)
historyserver      |    at org.apache.hadoop.http.HttpServer2.getFilterProperties(HttpServer2.java:454)
historyserver      |    at org.apache.hadoop.http.HttpServer2.constructSecretProvider(HttpServer2.java:445)
historyserver      |    at org.apache.hadoop.http.HttpServer2.<init>(HttpServer2.java:339)
historyserver      |    ... 8 more
historyserver      | Caused by: java.net.UnknownHostException: historyserver: historyserver: Name or service not known
historyserver      |    at java.net.InetAddress.getLocalHost(InetAddress.java:1496)
historyserver      |    at org.apache.hadoop.security.SecurityUtil.getLocalHostName(SecurityUtil.java:190)
historyserver      |    at 
...

注释 network_mode: ‘host’

[root@localhost module]# cat docker-compose-hadoop-cluster.yaml
version: "2.2"
services:
  namenode:
    image: bde2020/hadoop-namenode:1.1.0-hadoop2.7.1-java8
    hostname: namenode
    container_name: namenode
    ports:
      - 9000:9000
      - 50070:50070
    restart: always
    #network_mode: 'host'
    environment:
      - CLUSTER_NAME=test
      - HDFS_CONF_dfs_permissions=false
    env_file:
      - ./hadoop.env

  resourcemanager:
    image: bde2020/hadoop-resourcemanager:1.1.0-hadoop2.7.1-java8
    hostname: resourcemanager
    container_name: resourcemanager
    ports:
      - 8030:8030
      - 8031:8031
      - 8032:8032
      - 8033:8033
      - 8088:8088
    restart: always
    #network_mode: 'host'
    depends_on:
      - namenode
      - datanode1
      - datanode2
      - datanode3
    env_file:
      - ./hadoop.env

  historyserver:
    image: bde2020/hadoop-historyserver:1.1.0-hadoop2.7.1-java8
    hostname: historyserver
    container_name: historyserver
    ports:
      - 8188:8188
    restart: always
    #network_mode: 'host'
    depends_on:
      - namenode
      - datanode1
      - datanode2
      - datanode3
    #volumes:
    #  - ./hadoop/historyserver:/hadoop/yarn/timeline
    env_file:
      - ./hadoop.env

  nodemanager1:
    image: bde2020/hadoop-nodemanager:1.1.0-hadoop2.7.1-java8
    hostname: nodemanager1
    container_name: nodemanager1
    ports:
      - 8040:8040
      - 8041:8041
      - 8042:8042
    restart: always
    #network_mode: 'host'
    depends_on:
      - namenode
      - datanode1
      - datanode2
      - datanode3
    env_file:
      - ./hadoop.env


  datanode1:
    image: bde2020/hadoop-datanode:1.1.0-hadoop2.7.1-java8
    hostname: datanode1
    container_name: datanode1
    restart: always
    #network_mode: 'host'
    environment:
      - HDFS_CONF_dfs_datanode_address=0.0.0.0:50010
      - HDFS_CONF_dfs_datanode_ipc_address=0.0.0.0:50020
      - HDFS_CONF_dfs_datanode_http_address=0.0.0.0:50075
    ports:
      - 50010:50010
      - 50020:50020
      - 50075:50075
    depends_on:
      - namenode
    #volumes:
    #  - ./hadoop/datanode1:/hadoop/dfs/data
    env_file:
      - ./hadoop.env

  datanode2:
    image: bde2020/hadoop-datanode:1.1.0-hadoop2.7.1-java8
    hostname: datanode2
    container_name: datanode2
    restart: always
    #network_mode: 'host'
    environment:
      - HDFS_CONF_dfs_datanode_address=0.0.0.0:50012
      - HDFS_CONF_dfs_datanode_ipc_address=0.0.0.0:50022
      - HDFS_CONF_dfs_datanode_http_address=0.0.0.0:50072
    ports:
      - 50012:50012
      - 50022:50022
      - 50072:50072
    depends_on:
      - namenode
    #volumes:
    #  - ./hadoop/datanode2:/hadoop/dfs/data
    env_file:
      - ./hadoop.env

  datanode3:
    image: bde2020/hadoop-datanode:1.1.0-hadoop2.7.1-java8
    hostname: datanode3
    container_name: datanode3
    restart: always
    #network_mode: 'host'
    environment:
      - HDFS_CONF_dfs_datanode_address=0.0.0.0:50013
      - HDFS_CONF_dfs_datanode_ipc_address=0.0.0.0:50023
      - HDFS_CONF_dfs_datanode_http_address=0.0.0.0:50073
    ports:
      - 50013:50013
      - 50023:50023
      - 50073:50073
    depends_on:
      - namenode
    #volumes:
    #  - ./hadoop/datanode3:/hadoop/dfs/data
    env_file:
      - ./hadoop.env

docker compose各参数配置介绍

Docker Compose 是一个用于定义和运行多个 Docker 容器的工具,通过使用简单的 YAML 文件来配置应用程序的服务、网络和卷等。

使用 Docker Compose 可以方便地定义和管理容器化应用程序的服务栈。在配置文件中,你可以指定各个服务所需的镜像、环境变量、端口映射、数据卷挂载等信息。通过一次性执行 docker-compose up 命令,Docker Compose 将会自动下载所需的镜像,并启动所有服务。此外,还可以使用 docker-compose down 命令停止服务并清理容器。

使用 Docker Compose 的好处是,它使得部署和管理多个容器变得简单而高效。你可以将整个应用程序的服务定义放在一个文件中,便于版本控制和共享。同时,通过 Docker Compose,你可以轻松部署一致性的开发、测试和生产环境,减少因环境差异而造成的问题。

docker compose 各项参数

这些只是 Docker Compose 配置文件中一些常用的参数。建议查阅 Docker Compose 官方文档,了解更多参数和配置选项的详细介绍。

代码演示

services:
    client:
    build:
    context: ./client
    dockerfile: ./Dockerfile
    restart: always
    ports:
 
        - 9540:9540
 
    volumes:
 
        - upload:/usr/share/nginx/html/static
 
    depends_on:
 
        - servers
 
 
servers:
 
    build:
    context: ./servers
    dockerfile: ./Dockerfile
    command: npm run start:docker
    restart: always
 
    ports:
 
        - 8080:8080
 
    volumes:
 
        - upload:/upload
 
    depends_on:
 
        - mysql
        - redis
    
 
 
mysql:
 
    image: mysql
 
    command: mysqld --character-set-server=utf8mb4 --collation-                            
    server=utf8mb4_unicode_ci
 
    restart: always
    
    ports:
 
        - 20003:3306
 
    environment:
 
    MYSQL_ROOT_PASSWORD: 'root'
    MYSQL_DATABASE: 'BASE_DB'
 
    volumes:
 
        - mysql:/var/lib/mysql
        - ./db/kapok.sql:/docker-entrypoint-initdb.d/kapok.sql
 
adminer:
 
    image: adminer
    restart: always
    ports:
    8088:8080
  
redis:
 
    image: redis
    restart: always
 
    ports:
 
        - 20004:6379
 
    volumes:
 
        - redis:/data

最后,还定义了三个数据卷 mysql、redis 和 upload,用于持久化存储数据库数据、Redis 数据和前端上传的文件。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文