[英]Change container port in docker compose
I am trying to get a docker-compose file working with both airflow and spark.我正在尝试让 docker-compose 文件同时使用气流和火花。 Airflow typically runs on 8080:8080
which is needed by spark as well.气流通常在8080:8080
上运行,这也是火花所需要的。 I have the following docker-compose file:我有以下 docker-compose 文件:
version: '3.7'
services:
master:
image: gettyimages/spark
command: bin/spark-class org.apache.spark.deploy.master.Master -h master
hostname: master
environment:
MASTER: spark://master:7077
SPARK_CONF_DIR: /conf
SPARK_PUBLIC_DNS: localhost
expose:
- 7001
- 7002
- 7003
- 7004
- 7005
- 7077
- 6066
ports:
- 4040:4040
- 6066:6066
- 7077:7077
- 8080:8080
volumes:
- ./conf/master:/conf
- ./data:/tmp/data
worker:
image: gettyimages/spark
command: bin/spark-class org.apache.spark.deploy.worker.Worker spark://master:7077
hostname: worker
environment:
SPARK_CONF_DIR: /conf
SPARK_WORKER_CORES: 2
SPARK_WORKER_MEMORY: 1g
SPARK_WORKER_PORT: 8881
SPARK_WORKER_WEBUI_PORT: 8081
SPARK_PUBLIC_DNS: localhost
links:
- master
expose:
- 7012
- 7013
- 7014
- 7015
- 8881
ports:
- 8081:8081
volumes:
- ./conf/worker:/conf
- ./data:/tmp/data
postgres:
image: postgres:9.6
environment:
- POSTGRES_USER=airflow
- POSTGRES_PASSWORD=airflow
- POSTGRES_DB=airflow
logging:
options:
max-size: 10m
max-file: "3"
webserver:
image: puckel/docker-airflow:1.10.9
restart: always
depends_on:
- postgres
environment:
- LOAD_EX=y
- EXECUTOR=Local
logging:
options:
max-size: 10m
max-file: "3"
volumes:
- ./dags:/usr/local/airflow/dags
# Add this to have third party packages
- ./requirements.txt:/requirements.txt
# - ./plugins:/usr/local/airflow/plugins
ports:
- "8082:8080" # NEED TO CHANGE THIS LINE
command: webserver
healthcheck:
test: ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
interval: 30s
timeout: 30s
retries: 3
but specifically need to change the line:但特别需要更改行:
ports:
- "8082:8080" # NEED TO CHANGE THIS LINE
under web server so there's no port conflict.在网络服务器下,所以没有端口冲突。 However when I change the container port to something other than 8080:8080
it doesnt work (cannot connect/find server).但是,当我将容器端口更改为8080:8080
以外的其他端口时,它不起作用(无法连接/查找服务器)。 How do I change the container port successfully?如何成功更改容器端口?
When you specified port mapping in docker you are giving 2 ports, for instance: 8082:8080
.当您在 docker 中指定端口映射时,您将提供 2 个端口,例如: 8082:8080
。 The right port is the one that is listening within the container.正确的端口是在容器内侦听的端口。 You can have several containers that listening internally to the same port.您可以有多个容器在内部侦听同一个端口。 They are still not available in your localhost - that's why we use the ports
section for.它们在您的本地主机中仍然不可用 - 这就是我们使用ports
部分的原因。
Now, in your localhost you cannot bind the same port more than once.现在,在您的本地主机中,您不能多次绑定同一个端口。 That's why docker failed when you try to set on the left side 8080
more than one time.这就是为什么当您尝试在左侧设置8080
多次时 docker 失败的原因。 In your current compose file, the spark
service port is mapped to 8080 (left side of 8080:8080
) and the webserver
service is mapped to 8082
(left side of 8082:8080
).在您当前的撰写文件中, spark
服务端口映射到 8080( 8080:8080
左侧),而webserver
服务映射到8082
( 8082:8080
左侧)。
if you want to access spark, goto: http://localhost:8080 and for the web server, go to http://localhost:8082如果要访问 spark,请转到:http://localhost:8080,对于 Web 服务器,请转到 http://localhost:8082
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.