Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda