gitea image with rootless user built on alpine linux : postgres 16.3
98
This Dockerfile sets up a Docker image for running Gitea, a self-hosted Git service. It uses Alpine Linux as the base image for a lightweight and efficient deployment.
# Use the Alpine base image
FROM alpine:latest
# Install necessary packages
RUN apk update && \
apk add --no-cache bash shadow git postgresql-client
Base Image: This Dockerfile starts with alpine:latest, the latest stable version of Alpine Linux, known for its small size and security features.
Package Installation:
bash: Provides a more feature-rich shell environment.shadow: Necessary for user management utilities.git: Required for version control functionalities.postgresql-client: Includes PostgreSQL client tools for database connectivity.# Create a non-root user and necessary directories
RUN addgroup -S gitea && \
adduser -S -G gitea -h /gitea gitea && \
mkdir -p /gitea/data/ && \
mkdir -p /gitea/install && \
chown -R gitea:gitea /gitea/install/
gitea and assigns it to the gitea group.-h /gitea) for the user./gitea/data/: Directory for storing Gitea application data./gitea/install: Directory for installing Gitea binaries and configuration files./gitea/install and its contents are owned by the gitea user.# Download gitea binary (version:1.22.0) in install folder
ADD https://dl.gitea.com/gitea/1.22.0/gitea-1.22.0-linux-amd64 /gitea/install/gitea
# app.ini into install directory
ADD app.ini /gitea/install/
Gitea Binary:
gitea-1.22.0-linux-amd64) from the official Gitea download link and places it in /gitea/install/gitea.app.ini Configuration:
app.ini configuration file into /gitea/install/, which contains settings for Gitea including database configuration.RUN chown -R gitea:gitea /gitea/ && \
cd /gitea && \
mkdir -p gitea/data && \
mkdir -p gitea/log && \
cd install && \
chmod -R 755 gitea && \
chmod 777 app.ini
/gitea/data, /gitea/log) and files under /gitea/ are owned by gitea user.gitea binary (gitea) to be executable (755) and for app.ini to be readable and writable by all (777).USER gitea
WORKDIR /gitea/install
User Switch:
gitea for running subsequent commands and the application.Working Directory:
/gitea/install, where the Gitea binary and configuration files reside.EXPOSE 3000
# Start Gitea server
CMD ["./gitea", "web", "--config", "./app.ini"]
Port Exposure:
3000 on the Docker container for accessing the Gitea web interface.Command Execution:
CMD) to start the Gitea server (./gitea web --config ./app.ini) when the Docker container is launched.To deploy Gitea using Docker, follow these steps:
Network Creation:
Create a Docker network named gitea-network to facilitate communication between containers:
docker network create gitea-network
Run PostgreSQL Database Container:
Start a PostgreSQL database container (gitea_db) connected to gitea-network, exposing port 5432 and using a volume (pgdb_data) for persistent storage:
docker run -d --name="gitea_db" --restart=on-failure:2 --hostname=postgres --network gitea-network -p 5432:5432 -v pgdb_data:/postgres/Database pgdb_img:v1.1
Build Gitea Docker Image:
Build the Gitea Docker image (gitea_image:v1.0) from the Dockerfile:
docker build -t gitea_image:v1.0 .
Run Gitea Container:
Launch the Gitea container (gitea_c1) connected to gitea-network, exposing port 3000, and using a volume (gitea_data) for Gitea data:
docker run -d --name="gitea_c1" --restart=on-failure:2 --network gitea-network -p 3000:3000 -v gitea_data:/gitea gitea_image:v1.0
Access Gitea:
http://localhost:3000 in your web browser.[Unit]
Description=Gitea (Git with a cup of tea along with DevOps Brathaa)
[server]
APP_DATA_PATH = /gitea/data
LOG_ROOT_PATH = /gitea/log
[database]
DB_TYPE = postgres
HOST = postgres:5432
NAME = gitea
USER = postgres
PASSWD = postgres
SSL_MODE = disable
PATH = /gitea/data/gitea.db
app.ini) for Gitea, specifying paths for data storage (APP_DATA_PATH and LOG_ROOT_PATH) and PostgreSQL database settings (DB_TYPE, HOST, NAME, USER, PASSWD, SSL_MODE, PATH).This README.md provides an overview of setting up and deploying Gitea using Docker, including Dockerfile explanations, setup instructions, and a sample app.ini configuration. Adjust paths, versions, and configurations as per your environment and requirements.
To disconnect a container from a Docker network, you can use the docker network disconnect command followed by the network name and the container ID or name. Here's how you can do it:
Find the Container ID or Name:
First, you need to find the ID or name of the container you want to disconnect. You can list all running containers with:
docker ps
This command will list all running containers along with their IDs and names.
Disconnect the Container:
Once you have the container ID or name and the network name, use the docker network disconnect command:
docker network disconnect <network_name> <container_id_or_name>
Replace <network_name> with the name of the Docker network and <container_id_or_name> with the ID or name of the container you want to disconnect.
Let's say you have a container named my-container connected to a network named my-network:
docker network disconnect my-network my-container
This command will disconnect my-container from my-network.
my-network.This process allows you to manage network connectivity for Docker containers, helping you control how containers communicate and interact within your Docker environment.
Content type
Image
Digest
sha256:434217a62…
Size
147.7 MB
Last updated
about 2 years ago
docker pull pritamchk98/gitea_image:v1.0