How to expose mariadb container port outside of the docker networking?

68 Views Asked by At

I have mariaDB and redis and someother containers is connected in one network the project name is frappe_docker.

Ideally what im doing is im inspect the mariaDB container ID and get the IP Address using this command

docker inspect <MARIADB_ID>

After that I try to ping the IP using this command

ping -a <MARIADB_IP_ADDRESS>

It's working fine in Ubuntu OS but not in Windows.

I'm using the Windows 10 Pro the IP is not exposing. I don't know why when I'm Trying to connect in the PyCharm I'm getting this error

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.

enter image description here

Container Details

$ 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

While Ping The MariaDB Container

$ 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),

Here my docker docker-compose.yml file

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:


1

There are 1 best solutions below

1
L O C O On BEST ANSWER

I did expose the port. I did some small changes in the .yml file

Here the new docker-compose.yml file

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
    ports:
      - "3306:3306"


  # 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:

I just added this line under the mariadb service

ports:
      - "3306:3306"

After that I used the localhost its worked for me

enter image description here