在Docker容器中显示了错误的数据库。

huangapple go评论63阅读模式
英文:

incorrect database displayed in docker container

问题

我的数据库被定义为blue,但是当我在终端中查找时,显示为red。我之前启动了一个定义为red的数据库容器,但是已经删除并完全移除了它。我尝试过使用--build标志重新启动容器,但没有成功。发生了什么事?

英文:

My database is defined as blue:-

docker-compose.yaml

version: '3'
services:

  #PHP Service
  ngxapp:
    build:
      context: .
      dockerfile: Dockerfile
    image: andys
    container_name: ngxapp
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: ngxapp
      SERVICE_TAGS: dev
    working_dir: /var/www
    volumes:
      - ./:/var/www
      - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - app-network

  #Nginx Service
  ngxwebserver:
    image: nginx:alpine
    container_name: ngxwebserver
    restart: unless-stopped
    tty: true
    ports:
      - "8097:80"
      - "4431:443"
    volumes:
      - ./:/var/www
      - ./nginx/conf.d/:/etc/nginx/conf.d/
    networks:
      - app-network

  #MySQL Service
  ngxdb:
    image: mysql:5.7.22
    container_name: ngxdb
    restart: unless-stopped
    tty: true
    ports:
      - "3418:3306"
    environment:
      MYSQL_USER: root
      MYSQL_DATABASE: blue
      MYSQL_ROOT_PASSWORD: password
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    volumes:
      - dbdata:/var/lib/mysql/
      - ./mysql/my.cnf:/etc/mysql/my.cnf
    networks:
      - app-network

#Docker Networks
networks:
  app-network:
    driver: bridge
#Volumes
volumes:
  dbdata:
    driver: local

seen here;-

在Docker容器中显示了错误的数据库。

however, when i go to the terminal and look for it there, it's displaying as red:-

在Docker容器中显示了错误的数据库。

what's happening? I have span up another container with a db defined as red previously, but have since deleted and removed it entirely.

I've tried restarting the container with the --build flag also, no success.

答案1

得分: 0

你应该重置你的 dbdata 数据库 Docker volume:

volumes:
  - dbdata:/var/lib/mysql/
  - ./mysql/my.cnf:/etc/mysql/my.cnf

尝试:

docker volume rm dbdata

这将删除所有的 MySQL 数据。下次你运行 docker-compose up 时,MySQL 将从头开始初始化,blue 数据库应该会被创建。

英文:

You should probably reset your dbdata DB Docker volume:

volumes:
  - dbdata:/var/lib/mysql/
  - ./mysql/my.cnf:/etc/mysql/my.cnf

Try:

docker volume rm dbdata

This will erase all MySQL data. Next time you do docker-compose up MySQL will be initialized from scratch and blue DB should be created.

huangapple
  • 本文由 发表于 2023年3月7日 22:50:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75663502.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定