Windows下如何将MariaDB容器端口暴露到Docker网络外部?
问题描述
环境与问题概述
- 容器环境:
MariaDB、Redis及其他容器处于同一Docker网络,基于frappe_docker项目 - 操作差异:在Ubuntu系统中可通过
docker inspect <MARIADB_ID>获取容器IP,再用ping -a <MARIADB_IP_ADDRESS>连通;但Windows 10 Pro下无法实现,容器IP无法暴露 - 连接错误:PyCharm连接MariaDB时超时,错误信息如下:
DBMS: MariaDB (no ver.) Case sensitivity: plain=mixed, delimited=exact Socket fail to connect to host:address=(host=172.19.0.2)(port=3306)(type=primary). Connection timed out: no further information.

容器详情
执行docker ps的结果:
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c06f68db4a25 frappe/bench:latest "/bin/sh -c 'echo Co…" 7 days ago Up 20 hours 0.0.0.0:8000-8005->8000-8005/tcp, 6787/tcp, 0.0.0.0:9000-9005->9000-9005/tcp frappe_docker_14_1_devcontainer-frappe-1 d32f05b3d895 redis:alpine "docker-entrypoint.s…" 7 days ago Up 20 hours 6379/tcp frappe_docker_14_1_devcontainer-redis-cache-1 aa63a9b1713a redis:alpine "docker-entrypoint.s…" 7 days ago Up 20 hours 6379/tcp frappe_docker_14_1_devcontainer-redis-queue-1 47c5a3fc0f91 mariadb:10.6 "docker-entrypoint.s…" 7 days ago Up 20 hours 3306/tcp frappe_docker_14_1_devcontainer-mariadb-1
Ping容器IP结果
$ ping -a 172.19.0.2 Pinging mariadb-container [172.19.0.2] with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out. Ping statistics for 172.19.0.2: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
docker-compose.yml配置
version: "3.7" services: mariadb: image: docker.io/mariadb:10.6 command: - --character-set-server=utf8mb4 - --collation-server=utf8mb4_unicode_ci - --skip-character-set-client-handshake - --skip-innodb-read-only-compressed # Temporary fix for MariaDB 10.6 environment: MYSQL_ROOT_PASSWORD: 123 volumes: - mariadb-data:/var/lib/mysql # Enable PostgreSQL only if you use it, see development/README.md for more information. # postgresql: # image: postgres:11.8 # environment: # POSTGRES_PASSWORD: 123 # volumes: # - postgresql-data:/var/lib/postgresql/data # Enable Mailpit if you need to test outgoing mail services # See https://mailpit.axllent.org/ # mailpit: # image: axllent/mailpit # volumes: # - mailpit-data:/data # ports: # - 8025:8025 # - 1025:1025 # environment: # MP_MAX_MESSAGES: 5000 # MP_DATA_FILE: /data/mailpit.db # MP_SMTP_AUTH_ACCEPT_ANY: 1 # MP_SMTP_AUTH_ALLOW_INSECURE: 1 redis-cache: image: docker.io/redis:alpine redis-queue: image: docker.io/redis:alpine frappe: image: docker.io/frappe/bench:latest command: sleep infinity environment: - SHELL=/bin/bash volumes: - ..:/workspace:cached # Enable if you require git cloning # - ${HOME}/.ssh:/home/frappe/.ssh working_dir: /workspace/development ports: - 8000-8005:8000-8005 - 9000-9005:9000-9005 # enable the below service if you need Cypress UI Tests to be executed # Before enabling ensure install_x11_deps.sh has been executed and display variable is exported. # Run install_x11_deps.sh again if DISPLAY is not set # ui-tester: # # pass custom command to start Cypress otherwise it will use the entrypoint # # specified in the Cypress Docker image. # # also pass "--project <folder>" so that when Cypress opens # # it can find file "cypress.json" and show integration specs # # https://on.cypress.io/command-line#cypress-open # entrypoint: 'sleep infinity' # image: "docker.io/cypress/included:latest" # environment: # - SHELL=/bin/bash # # get the IP address of the host machine and allow X11 to accept # # incoming connections from that IP address # # IP=$(ipconfig getifaddr en0) or mac or \ # # IP=$($(hostname -I | awk '{print $1}') ) for Ubuntu # # /usr/X11/bin/xhost + $IP # # then pass the environment variable DISPLAY to show Cypress GUI on the host system # # DISPLAY=$IP:0 # - DISPLAY # volumes: # # for Cypress to communicate with the X11 server pass this socket file # # in addition to any other mapped volumes # - /tmp/.X11-unix:/tmp/.X11-unix # - ..:/workspace:z,cached # network_mode: "host" volumes: mariadb-data: #postgresql-data: #mailpit-data:
内容的提问来源于stack exchange,提问作者L O C O
相关产品推荐
相关产品推荐

