10

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
jerry_k
  • 363
  • 1
  • 5
  • 20

1 Answers1

13

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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Now when the computer starts I have to restart docker and then also docker-compose to get it up and running. If I only try to restart docker-compose it fails to restart one of the containers. And accessing the site without running docker-compose restart is as it would be the first install. Only when I restart both all the content comes back. Any idea why? – jerry_k Jun 18 '19 at 13:25
  • @jerry_K7 I don't think docker-compose can work if docker is not restarted (ie: the docker daemon): Docker Compose (https://docs.docker.com/compose/overview/) will run multiple Docker container, but it needs a Docker runtime environment. More on that with https://medium.com/faun/docker-containerd-standalone-runtimes-heres-what-you-should-know-b834ef155426 – VonC Jun 18 '19 at 16:27