Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda