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

356
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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