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

357
Visualizações
Why do I lose data if docker restarts?

I am new to docker and would need some advice. I am about to set up my own personal git repository with Gitea. The docker compose file can be seen below. When I first run the file everything is fine. The problem occurs when I restart my computer or Docker then the page loads but it is empty no repos, nothing. Also it is not possible to log in with the credential that were set after first installation. It looks like the connection to the database is lost after restarting.

docker compose file:

version: "2"

networks:
  gitea:
    external: false

volumes:
  gitea:
    driver: local

services:
  server:
    image: gitea/gitea:latest
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - DB_TYPE=mysql
      - DB_HOST=db:3306
      - DB_NAME=gitea
      - DB_USER=gitea
      - DB_PASSWD=gitea
    restart: always
    networks:
      - gitea
    volumes:
      #- ./gitea:/data
       - gitea:/data
    ports:
       - "3000:3000"
       - "222:22"
    depends_on:
      - db

  db:
    image: mysql:5.7
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=gitea
      - MYSQL_USER=gitea
      - MYSQL_PASSWORD=gitea
      - MYSQL_DATABASE=gitea
    networks:
      - gitea
    volumes:
      - ./mysql:/var/lib/mysql
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You should declare one of your local folder as a volume in order to get persistent data. As in here for instance:

docker run -v /host/directory:/container/directory -other -options image_name command_to_run

Otherwise, any data written on top of an existing image layer is discarded by default when the container is removed.
This is using a union filesystem: (see "Digging into Docker layers")

https://cdn-images-1.medium.com/max/1091/1*st_fZmKOMykQGF8kZKglvA.png

In the case of gitea (docker), make sure you have a local data and mysql folder, to be mounted by the Docker images.

volumes:
 - ./data:/data
volumes:
 - ./mysql:/var/lib/mysql

You have used

volumes:
      #- ./gitea:/data
       - gitea:/data

That would declare a volume (instead of a bind mount), named "gitea", stored into your Docker installation.

You could try the same for the db part:

volumes:
 - mysql:/var/lib/mysql
over 4 years ago · Santiago Trujillo Relatório
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