Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Docker-compose won't start MySQL if I define a volume

I'm trying to create a volume for my MySQL container so the data can persist. So in my docker-compose, I created a volume in which the data will be stored.

Here's my docker-compose :

version: '3'
services:
  app:
    build:
      context: .
      dockerfile: .docker/Dockerfile
    image: portfolio
    ports:
      - 80:80
    volumes:
      - .:/var/www/html
    links:
      - mysql
    environment:
      DB_HOST: mysql
      DB_DATABASE: blog
      DB_USERNAME: blog
      DB_PASSWORD: ...
  mysql:
    image: mysql:5.7
    ports:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: blog
      MYSQL_USER: blog
      MYSQL_PASSWORD: ...
      MYSQL_ROOT_PASSWORD: ...
    volumes:
      - "./db:/var/lib/mysql"

The volume is defined at the end of the file. Unfortunately, that's not working. If I do a docker container ls it only shows the portfolio container, and if I do a docker container ls -a it does show my the container for MySQL, but it says it has "exited" right after I did the docker-compose up -d, so apparently it was started but then immediately crashed or something.

If I remove the last 2 lines related to the MySQL volume, it works fine. My containers are both up and the app works normally. So basically what causes the container to crash is the volume, so maybe I didn't define it correctly. What do you think ?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!