1

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

Dee_wab
  • 1,171
  • 1
  • 10
  • 23
Sam
  • 53
  • 9
  • That .sql file does not get executed automatically when the container starts. You must for one time only execute the mysqlimport command inside the container using `docker exec CONTAINER_ID mysqlimport /var/lib/sql/table.sql`. After that you will have the table and data available. – Constantin Galbenu Apr 14 '18 at 08:17

0 Answers0