How do I add a table in MySQL using docker-compose

独自空忆成欢 提交于 2021-02-10 15:07:11

问题


I am using docker-compose to create a web application using PHP and MySQL.The container that runs MySQL has the database installed however, I am not able to find the table in there. I have made use of a volume that contains the table .sql extension).

Below is my docker-compose.yml file

 `version: '3'
  services:
  web_1:
  container_name: web1_2
  build: .
  ports:
  - "8081:80"
  networks:
  test:
    ipv4_address: 172.28.0.2
   web_2:
   container_name: web2_2
   build: . 
  ports: 
  - "8082:80" 
 networks:
  test:
    ipv4_address: 172.28.0.3
 lb_2:
  container_name: lb_2
  build: ./lb 
  ports:
   - "8080:80"
networks:
  test:
    ipv4_address: 172.28.0.4

db_2:
   container_name: db_2
   image: mysql:latest
   restart: always
   volumes:
  - dbdata:/var/lib/mysql
   environment: 
    MYSQL_ROOT_PASSWORD: password
    MYSQL_DATABASE: cloud
    MYSQL_USER: root 
    MYSQL_PASSWORD: password
  ports:
  - "3306:3306"
  networks: 
  test:
    ipv4_address: 172.28.0.5

networks:
  test:
     ipam:
         driver: default
         config: 
             - subnet: 172.28.0.0/16

 volumes:
     dbdata: 
    `

This is the sql file present on the hostmachine which I am mountig on /var/lib/sql on the docker container.

`CREATE TABLE cloud.basic (name VARCHAR(20), age INT, location VARCHAR(20));
  INSERT INTO TABLE cloud.basic VALUES ("Sampy", 23, "Boulder");
  INSERT INTO TABLE cloud.basic VALUES ("Gian", 27, "Raton");`

Where doyou think I am going wrong? Is my approach wrong? Any help will be greatly appreciated

来源:https://stackoverflow.com/questions/49828134/how-do-i-add-a-table-in-mysql-using-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!