DEV Community

Tossapol Ritcharoenwattu
Tossapol Ritcharoenwattu

Posted on

การใช้ docker compose ในการติดตั้ง gitlab ใน rocky linux

สร้างไฟล์ docker-compose.yml

version: '3.6'
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest' # CE คือ Community Edition (ฟรี)
    container_name: gitlab
    restart: always
    hostname: 'gitlab.example.com' # **สำคัญ:** เปลี่ยนเป็น IP หรือ Domain ของคุณ
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.example.com' # **สำคัญ:** เปลี่ยนเป็น IP หรือ Domain ของคุณให้ตรงกับ hostname
        # เพิ่มการตั้งค่าอื่นๆ ที่นี่ได้
    ports:
      - '80:80'       # สำหรับ HTTP
      - '443:443'     # สำหรับ HTTPS
      - '2222:22'     # สำหรับ SSH (ใช้พอร์ต 2222 เพื่อไม่ให้ชนกับ SSH ของเครื่อง Host)
    volumes:
      - './config:/etc/gitlab'
      - './logs:/var/log/gitlab'
      - './data:/var/opt/gitlab'
Enter fullscreen mode Exit fullscreen mode

หมายเหตุ
external_url และ hostname ต้องเปลี่ยนเป็น ip เครื่องที่ใช้นะครับ และ gitlab ต้องใช้ port 80 และ 443 ด้วย ควรเช็คก่อนว่าถูกใช้ไปหรือยัง ถ้าถูกใช้ไปแล้ว ให้แก้เลขด้านหน้าเป็น port ที่ยังไม่ถุกใช้งาน
เราสามารถ เช็ค port ว่าถูกใช้ไแล้วหรือยัง ใน linux รุ่นใหม่ๆ เช่น rocky สามารถ run ด้วยคำสั่งนี้ได้

ss -tuln | grep 80
ss -tuln | grep 443
Enter fullscreen mode Exit fullscreen mode

หลังจากตั้งค่าในไฟล์ docker-compose.yml เสร็จเรียบร้อย ก็จะเริ่มสั่งให้ docker compose ทำงานด้วยคำสั่ง

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

ขั้นตอนนี้จะใช้เวลา ราวๆ 5-15 นาที

ลองเข้า url http://localhost:8080

เราสามารถหา password สำหรับเข้าใช้งานครั้งแรกได้ด้วย command

sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
Enter fullscreen mode Exit fullscreen mode

Top comments (0)