English 中文(简体)
MariaDB 当地东道方在健康检查时没有cker子
原标题:MariaDB localhost failure with docker compose while healthcheck

I m 从事基于Debian的虚拟方框工作

我有 do子-comp子:

version:  3  
services:
  mydb:
    build: ./db/
    networks:
      - dockercompose-frontend 
    volumes:
      - server_db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=debian
    healthcheck:
      test: ["CMD", "mariadb-admin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 15s
      retries: 5

  frontend:
    build: .
      ports:
        - "8080:80"
      networks:
        - dockercompose-frontend
      environment:
        PMA_HOST=mydb
        PMA_PORT=3306

volumes:
  server_db:
    driver: local
networks:
  dockercompose-frontend:

两台Dockerfiles供每个部门使用,我刚刚安装必要的图像。

FROM mariabd:latest
RUN apt-get update && apt-get install -y iputils-ping

以及

FROM phpmyadmin:5.2.0-apache
RUN apt-get update && apt-get install -y iputils-ping

当使用<条码>的Im cker 堆肥料成时(无――d方式):

frontend-1 | AH00558: apache2: Could not reliably determine the server s fully qualified domain nam e, using 172.25.0.2. Set the ServerName directive globally to suppress this message

When I m using docker compose up -d 以及 checks Health State for mydb it throws:

{
  "Status":"starting", 
  "FailingStreak": 2, 
  "Log": [{"Start": "2024-02-19T10:05:48.178379963-05:00",
    "End": 2024-02-19T10:05:48.240662846-05:00", 
    "ExitCode": 1, 
    "Output":"u0007mariadb-admin: connect to server a t  localhost failed
error:  Can t connect to local server through socket  /run/mysqld/mysqld.sock (2) 
     Check that mariadbd is running 以及 that the socket:  /run/mysqld/mysqld.sock  exists!"
}

此外,

docker exec dockercompose-mydb-1 service mariadb status

投掷“Mariadb服务被停止”

之后

docker exec dockercompose-mydb-1 service mariadb start

它投掷了第1条(航行)。

问题回答

first, update the syntax in health check part as there s error with quotes to

healthcheck:
  test: ["CMD", "mariadb-admin", "ping", "-h", "localhost"]
  interval: 10s
  timeout: 15s
  retries: 5

second specify the port in mariadb service

version:  3  
services:
  mydb:
    build: ./db/
    networks:
      - dockercompose-frontend 
    volumes:
      - server_db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=debian
    healthcheck:
      test: ["CMD", "mariadb-admin", "ping", "-h", "localhost"]
      interval: 10s 
      timeout: 15s 
      retries: 5
    ports:
      - "3306:3306"  # Map container s port 3306 to host s port 3306

  frontend:
    build: .
    ports:
      - "8080:80"
    networks:
      - dockercompose-frontend
    environment:
      PMA_HOST: mydb
      PMA_PORT: 3306

volumes:
  server_db:
    driver: local
#rest of your docker comopse file

also make sure that the network driver is not equal to none, it s type is equal to bridge for example.

you can add "depends_on" in frontend service so the container is not created unless mariaDB is up successfully.

  frontend:
    build: .
    ports:
      - "8080:80"
    networks:
      - dockercompose-frontend
    environment:
      PMA_HOST: mydb
      PMA_PORT: 3306
    depends_on:
      - mydb  # to prevent docker compose from starting the container until the container of mariaDB is running.




相关问题
Unable to connect to docker container inside windows server

As title. I am developing a system with many docker images with ASP.Net MVC core projects. I am publishing these docker images into a docker engine installed on Windows Server OS, and I found that I ...

Only can see postgreSQL as an admin

After installed Wsl and Docker, can t access PSQL and other things. I was studying Docker, and installed the latest version. So far so good, I received an error about the WSL version, saw some ...

make docker-compose block until healthy without `depends_on`

I am working with a team that uses docker-compose to start a set of helper services, but does not use docker when the code is being developed. Here, docker-compose is just a convenient way to run the ...

change grafana port using docker host network

I am trying to spin up a grafana container in docker, however my setup in docker does not allow ipv4 forwarding and thus I cannot use the default bridge network in docker. All I can use is the host ...

Pip instalation for Python 3.11 in docker

I have Dockerfile to build image for Django project that uses Python 3.11 and runs in poetry environment (see content below). Problem is when I try to donwload get-pip.py file and run it using Python, ...

在 Dockerfile 中运行 composer install

我正在尝试将我的Laravel应用程序进行Docker化。 该应用程序已经构建并在Git中,但我将vendor文件夹添加到了.gitignore中。 我添加了一个Dockerfile,看起来像这样: FROM php:7.1-fpm-alpine RUN apk update ...

热门标签