[Docs] Migrate to docker #3779

Closed
opened 2025-11-02 05:25:00 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @lonix1 on GitHub (Aug 14, 2019).

Environment: gitea 1.7.5, linux, sqlite.

I want to migrate to docker.

I couldn't find instructions, so I just copied all the files to the relevant places. The container starts, but won't serve data. Something about a "corrupted content error". So obviously I made some mistakes.

I'm sure many people like me started using gogs/gitea the normal way, and then want to "dockerise". Are there instructions for this anywhere, or any tips to follow?

Originally created by @lonix1 on GitHub (Aug 14, 2019). Environment: gitea 1.7.5, linux, sqlite. I want to migrate to docker. I couldn't find instructions, so I just copied all the files to the relevant places. The container starts, but won't serve data. Something about a "corrupted content error". So obviously I made some mistakes. I'm sure many people like me started using gogs/gitea the normal way, and then want to "dockerise". Are there instructions for this anywhere, or any tips to follow?
GiteaMirror added the type/docsissue/workaround labels 2025-11-02 05:25:00 -06:00
Author
Owner

@stale[bot] commented on GitHub (Oct 13, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Oct 13, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@NHellFire commented on GitHub (Sep 6, 2020):

This script is the procedure I used for converting from the debian package to docker (you should run it as root):

#!/bin/sh
set -e -x

USER_UID=${USER_UID:-1000}
USER_GID=${USER_GID:-1000}


# Build initool for automatically updating config
# You need `mlton` installed (package mlton in Debian/Fedora variants)
if [ ! -x initool-0.10.0/initool ]; then
	if ! command -v mlton >/dev/null 2>&1; then
		echo "Missing dependency: mlton" >&2
		echo "Available on Debian and Fedora as the mlton package" >&2
		exit 1
	fi
	wget -O- https://github.com/dbohdan/initool/archive/v0.10.0.tar.gz | tar -zxf - && make -C initool-0.10.0
fi
initool=$(realpath initool-0.10.0/initool)

# Helpers for modifying app.ini
iniset() {
	section=${1%.*}; key=${1##*.}
	"$initool" s gitea/conf/app.ini "$section" "$key" "$2" > app.ini && \
		mv app.ini gitea/conf/app.ini
}

iniunset() {
	section=${1%.*}; key=${1##*.}
	"$initool" d gitea/conf/app.ini "$section" "$key" > app.ini && \
		mv app.ini gitea/conf/app.ini
}

# Copy existing gitea config
# conf, templates, and public are symlinks to the default data (already handled by the docker container)
# indexers can be excluded, they'll be regenerated at first run
rsync -aL --no-l --progress --exclude /gitea/conf --exclude /gitea/public --exclude /gitea/templates --exclude /gitea/indexers --exclude /gitea/data/indexers /var/lib/gitea gitea/

# Restructure to match docker's default layout
cd gitea

mv gitea/repositories git
mv gitea/.ssh git
mv gitea/data/* gitea/custom/* gitea
rmdir gitea/data gitea/custom

# These settings need updating to the correct paths
iniset repository.ROOT /data/git
iniset repository.local.LOCAL_COPY_PATH /data/gitea/tmp/local-repo
iniset repository.upload.TEMP_PATH /data/gitea/uploads
iniset server.APP_DATA_PATH /data/gitea
iniset server.LFS_CONTENT_PATH /data/git/lfs
iniset indexer.ISSUE_INDEXER_PATH /data/gitea/indexers/issues.bleve
iniset database.PATH /data/gitea/gitea.db
iniset session.PROVIDER_CONFIG /data/gitea/sessions
iniset picture.AVATAR_UPLOAD_PATH /data/gitea/avatars
iniset picture.REPOSITORY_AVATAR_UPLOAD_PATH /data/gitea/repo-avatars
iniset attachment.PATH /data/gitea/attachments
iniset log.ROOT_PATH /data/gitea/log

# These settings need to be removed
iniunset server.STATIC_ROOT_PATH


# Fix permissions
chown -R "${USER_UID}:${USER_GID}" .

# If you're using a named volume instead of a host folder
# You'll need to copy the data into the volume
#docker run --rm -v "gitea:/gitea-new" -v "$PWD:/gitea-old" alpine:latest cp -a --progress /gitea-old/* /gitea-new/

The resulting restructured data will be in located in the current working directory, named "gitea"
If you're using sqlite, you should be able to just run using the docker-compose.yml in the install docs
If you're using an external database, you'll likely need to modify the database settings in gitea/gitea/conf/app.ini

@NHellFire commented on GitHub (Sep 6, 2020): This script is the procedure I used for converting from the debian package to docker (you should run it as root): ```shell #!/bin/sh set -e -x USER_UID=${USER_UID:-1000} USER_GID=${USER_GID:-1000} # Build initool for automatically updating config # You need `mlton` installed (package mlton in Debian/Fedora variants) if [ ! -x initool-0.10.0/initool ]; then if ! command -v mlton >/dev/null 2>&1; then echo "Missing dependency: mlton" >&2 echo "Available on Debian and Fedora as the mlton package" >&2 exit 1 fi wget -O- https://github.com/dbohdan/initool/archive/v0.10.0.tar.gz | tar -zxf - && make -C initool-0.10.0 fi initool=$(realpath initool-0.10.0/initool) # Helpers for modifying app.ini iniset() { section=${1%.*}; key=${1##*.} "$initool" s gitea/conf/app.ini "$section" "$key" "$2" > app.ini && \ mv app.ini gitea/conf/app.ini } iniunset() { section=${1%.*}; key=${1##*.} "$initool" d gitea/conf/app.ini "$section" "$key" > app.ini && \ mv app.ini gitea/conf/app.ini } # Copy existing gitea config # conf, templates, and public are symlinks to the default data (already handled by the docker container) # indexers can be excluded, they'll be regenerated at first run rsync -aL --no-l --progress --exclude /gitea/conf --exclude /gitea/public --exclude /gitea/templates --exclude /gitea/indexers --exclude /gitea/data/indexers /var/lib/gitea gitea/ # Restructure to match docker's default layout cd gitea mv gitea/repositories git mv gitea/.ssh git mv gitea/data/* gitea/custom/* gitea rmdir gitea/data gitea/custom # These settings need updating to the correct paths iniset repository.ROOT /data/git iniset repository.local.LOCAL_COPY_PATH /data/gitea/tmp/local-repo iniset repository.upload.TEMP_PATH /data/gitea/uploads iniset server.APP_DATA_PATH /data/gitea iniset server.LFS_CONTENT_PATH /data/git/lfs iniset indexer.ISSUE_INDEXER_PATH /data/gitea/indexers/issues.bleve iniset database.PATH /data/gitea/gitea.db iniset session.PROVIDER_CONFIG /data/gitea/sessions iniset picture.AVATAR_UPLOAD_PATH /data/gitea/avatars iniset picture.REPOSITORY_AVATAR_UPLOAD_PATH /data/gitea/repo-avatars iniset attachment.PATH /data/gitea/attachments iniset log.ROOT_PATH /data/gitea/log # These settings need to be removed iniunset server.STATIC_ROOT_PATH # Fix permissions chown -R "${USER_UID}:${USER_GID}" . # If you're using a named volume instead of a host folder # You'll need to copy the data into the volume #docker run --rm -v "gitea:/gitea-new" -v "$PWD:/gitea-old" alpine:latest cp -a --progress /gitea-old/* /gitea-new/ ``` The resulting restructured data will be in located in the current working directory, named "gitea" If you're using sqlite, you should be able to just run using the docker-compose.yml in the [install docs](https://docs.gitea.io/en-us/install-with-docker/) If you're using an external database, you'll likely need to modify the database settings in `gitea/gitea/conf/app.ini`
Author
Owner

@lonix1 commented on GitHub (Sep 7, 2020):

@NHellFire Thanks. I've since moved to docker the hard way (recreating everything from scratch).
So I didn't test your script, but hope it will help others. And it should be in the docs.

@lonix1 commented on GitHub (Sep 7, 2020): @NHellFire Thanks. I've since moved to docker the hard way (recreating everything from scratch). So I didn't test your script, but hope it will help others. And it should be in the docs.
Author
Owner

@6543 commented on GitHub (Oct 13, 2020):

@NHellFire do you like to create a pull to add this into the docs?

@6543 commented on GitHub (Oct 13, 2020): @NHellFire do you like to create a pull to add this into the docs?
Author
Owner

@wxiaoguang commented on GitHub (Apr 13, 2022):

It differs a lot for different package systems. The general method is copying database, copying data directory, copying and editing app.ini.

@wxiaoguang commented on GitHub (Apr 13, 2022): It differs a lot for different package systems. The general method is copying database, copying data directory, copying and editing app.ini.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#3779