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

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

incorrect database displayed in docker container

问题

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

英文:

My database is defined as blue:-

docker-compose.yaml

  1. version: '3'
  2. services:
  3. #PHP Service
  4. ngxapp:
  5. build:
  6. context: .
  7. dockerfile: Dockerfile
  8. image: andys
  9. container_name: ngxapp
  10. restart: unless-stopped
  11. tty: true
  12. environment:
  13. SERVICE_NAME: ngxapp
  14. SERVICE_TAGS: dev
  15. working_dir: /var/www
  16. volumes:
  17. - ./:/var/www
  18. - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
  19. networks:
  20. - app-network
  21. #Nginx Service
  22. ngxwebserver:
  23. image: nginx:alpine
  24. container_name: ngxwebserver
  25. restart: unless-stopped
  26. tty: true
  27. ports:
  28. - "8097:80"
  29. - "4431:443"
  30. volumes:
  31. - ./:/var/www
  32. - ./nginx/conf.d/:/etc/nginx/conf.d/
  33. networks:
  34. - app-network
  35. #MySQL Service
  36. ngxdb:
  37. image: mysql:5.7.22
  38. container_name: ngxdb
  39. restart: unless-stopped
  40. tty: true
  41. ports:
  42. - "3418:3306"
  43. environment:
  44. MYSQL_USER: root
  45. MYSQL_DATABASE: blue
  46. MYSQL_ROOT_PASSWORD: password
  47. SERVICE_TAGS: dev
  48. SERVICE_NAME: mysql
  49. volumes:
  50. - dbdata:/var/lib/mysql/
  51. - ./mysql/my.cnf:/etc/mysql/my.cnf
  52. networks:
  53. - app-network
  54. #Docker Networks
  55. networks:
  56. app-network:
  57. driver: bridge
  58. #Volumes
  59. volumes:
  60. dbdata:
  61. 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:

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

尝试:

  1. docker volume rm dbdata

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

英文:

You should probably reset your dbdata DB Docker volume:

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

Try:

  1. 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:

确定