簡體   English   中英

使用Docker Compose連接到另一個容器中運行的mysql

[英]Using Docker Compose to connect to mysql running in another container

我是docker和docker-compose的新手。

我有一個在docker容器中運行的mysql,初始化了兩個數據庫。

我可以使用以下方式連接到它:

mysql --port=3306 -h192.0.0.1 -uroot -ppassword

當我跑:

docker ps

04bc1d308484        container-mysql   "docker-entrypoint.sh"   2 hours ago         Up 2 hours          3306/tcp            container-mysql

我的查詢是,現在我想使用另一個容器連接到它

docker-compose up.

another-image:
  image: another-image
  command: /opt/start.sh
  ports:
    - "8080:8080"
  environment:
    DB_URL: container-mysql
    DB_USER: root
    DB_PASSWORD: password
  external_links:
    - container-mysql

有人可以指導我失蹤什么,還有什么需要。

我的container-mysql有兩個數據庫模式。

示例:firstdb seconddb

好的,找到了答案。 萬一其他人遇到同樣的問題,就這樣做

docker network ls

此命令列出所有docker網絡。

| 網絡ID | NAME | DRIVER | 范圍|
| ------------- | --------------- | -------- | -------- |
| c24bee6b5b8e | network-mysql | 橋| 當地的|

因此,演示此文件的撰寫文件可能如下所示:

another-image:
  image: another-image
  command: /opt/start.sh
  ports:
    - "8080:8080"
  environment:
    DB_URL: container-mysql
    DB_USER: root
    DB_PASSWORD: password
  external_links:
    - container-mysql
  network_mode: network-mysql

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM