在docker compose中更改容器端口

des4xlb0  于 2021-05-19  发布在  Spark
关注(0)|答案(1)|浏览(1225)

我试图得到一个docker撰写文件与气流和Spark工作。气流通常在 8080:8080 这也是spark所需要的。我有以下docker compose文件:

  1. version: '3.7'
  2. services:
  3. master:
  4. image: gettyimages/spark
  5. command: bin/spark-class org.apache.spark.deploy.master.Master -h master
  6. hostname: master
  7. environment:
  8. MASTER: spark://master:7077
  9. SPARK_CONF_DIR: /conf
  10. SPARK_PUBLIC_DNS: localhost
  11. expose:
  12. - 7001
  13. - 7002
  14. - 7003
  15. - 7004
  16. - 7005
  17. - 7077
  18. - 6066
  19. ports:
  20. - 4040:4040
  21. - 6066:6066
  22. - 7077:7077
  23. - 8080:8080
  24. volumes:
  25. - ./conf/master:/conf
  26. - ./data:/tmp/data
  27. worker:
  28. image: gettyimages/spark
  29. command: bin/spark-class org.apache.spark.deploy.worker.Worker spark://master:7077
  30. hostname: worker
  31. environment:
  32. SPARK_CONF_DIR: /conf
  33. SPARK_WORKER_CORES: 2
  34. SPARK_WORKER_MEMORY: 1g
  35. SPARK_WORKER_PORT: 8881
  36. SPARK_WORKER_WEBUI_PORT: 8081
  37. SPARK_PUBLIC_DNS: localhost
  38. links:
  39. - master
  40. expose:
  41. - 7012
  42. - 7013
  43. - 7014
  44. - 7015
  45. - 8881
  46. ports:
  47. - 8081:8081
  48. volumes:
  49. - ./conf/worker:/conf
  50. - ./data:/tmp/data
  51. postgres:
  52. image: postgres:9.6
  53. environment:
  54. - POSTGRES_USER=airflow
  55. - POSTGRES_PASSWORD=airflow
  56. - POSTGRES_DB=airflow
  57. logging:
  58. options:
  59. max-size: 10m
  60. max-file: "3"
  61. webserver:
  62. image: puckel/docker-airflow:1.10.9
  63. restart: always
  64. depends_on:
  65. - postgres
  66. environment:
  67. - LOAD_EX=y
  68. - EXECUTOR=Local
  69. logging:
  70. options:
  71. max-size: 10m
  72. max-file: "3"
  73. volumes:
  74. - ./dags:/usr/local/airflow/dags
  75. # Add this to have third party packages
  76. - ./requirements.txt:/requirements.txt
  77. # - ./plugins:/usr/local/airflow/plugins
  78. ports:
  79. - "8082:8080" # NEED TO CHANGE THIS LINE
  80. command: webserver
  81. healthcheck:
  82. test: ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
  83. interval: 30s
  84. timeout: 30s
  85. retries: 3

但特别需要改变路线:

  1. ports:
  2. - "8082:8080" # NEED TO CHANGE THIS LINE

在web服务器下,所以没有端口冲突。但是当我把集装箱港口改成其他港口时 8080:8080 它不工作(无法连接/找到服务器)。如何成功更改集装箱港口?

llmtgqce

llmtgqce1#

在docker中指定端口Map时,将提供2个端口,例如: 8082:8080 . 正确的端口是在容器中侦听的端口。可以有多个容器在内部侦听同一端口。它们在您的localhost中仍然不可用-这就是为什么我们使用 ports 的节。
现在,在localhost中不能多次绑定同一端口。这就是为什么当你试图在左边设置时docker失败了 8080 不止一次。在当前的撰写文件中 spark 服务端口Map到8080(端口左侧 8080:8080 )以及 webserver 服务Map到 8082 (左侧) 8082:8080 ).
如果要访问spark,请转到:http://localhost:8080对于web服务器,转到http://localhost:8082

相关问题