먼저 GitLab 데이터를 저장할 디렉토리를 생성하고 환경 변수를 설정합니다:
sudo mkdir -p /srv/gitlab
export GITLAB_HOME=/srv/gitlab
GitLab을 설치하기 위해 docker-compose.yml
파일을 생성하고 아래 내용을 추가합니다:
version: '3.6'
services:
gitlab:
image: gitlab/gitlab-ee:latest
container_name: gitlab
restart: always # 재부팅 시 자동으로 시작되도록 설정
hostname: 'gitlab.local'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.local'
ports:
- '80:80'
- '443:443'
- '22:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
shm_size: '256m'
docker-compose.yml
파일이 있는 디렉토리에서 GitLab을 실행합니다:
docker compose up -d
시스템이 재부팅될 때 GitLab 컨테이너를 자동으로 실행하도록 systemd
서비스를 설정합니다:
서비스 파일 생성
/etc/systemd/system/gitlab.service
파일을 생성하고 아래 내용을 추가합니다:
[Unit]
Description=GitLab Docker Compose Service
After=docker.service
Requires=docker.service
[Service]
Restart=always
WorkingDirectory=/path/to/your/docker-compose/directory # docker-compose.yml 파일이 있는 디렉토리 경로로 변경하세요
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
[Install]
WantedBy=multi-user.target
서비스 활성화
서비스 파일을 활성화하여 재부팅 시 자동으로 실행되도록 설정합니다:
sudo systemctl enable gitlab
GitLab 설치 후 웹 브라우저에서 http://gitlab.local
에 접속하여 초기 설정을 진행합니다. 기본 관리자 계정은 root
이며, 초기 비밀번호는 아래 명령어로 확인할 수 있습니다:
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
해당 비밀번호를 사용해 로그인한 후, 관리자 페이지에서 새로운 사용자 계정을 생성할 수 있습니다.
이제 시스템이 재부팅되더라도 GitLab 컨테이너가 자동으로 시작됩니다! 간단하게 GitLab을 설치하고, 운영 환경에서도 안정적으로 사용할 수 있도록 설정해보세요.