Nginx in Gitlab with docker

Date:     Updated:

Categories:

Tags: , , ,

Gitlab

ํ—ˆ๋ธŒ๋ž‘์€ ๋‹ค๋ฅด๊ฒŒ ์„ค์น˜ํ˜• git ์ €์žฅ์†Œ์ด๋‹ค.

๋งˆ์Œ๋งž๋Š” ์‚ฌ๋žŒ๋“ค๊ณผ ํŒ€ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋Š”๋ฐ, ์ธํ”„๋ผ ๊ตฌ์„ฑ๊ณผ ์„œ๋ฒ„์‚ฌ์ด๋“œ๋ฅผ ๋งก๊ฒŒ ๋˜์–ด์„œ ๊ทผ๋ž˜ ๋„์ปค๋ฅผ ์—ด์‹ฌํžˆ ํ–ˆ๋˜ ๊ฒƒ์ด๋‹ค :)

Gitlab์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  1. ํŒ€ ๋งŒ์˜ ์ €์žฅ์†Œ๊ฐ€ ์žˆ์—ˆ์œผ๋ฉด ํ–ˆ๋‹ค.
  2. gitlab์—์„œ ์ œ๊ณตํ•˜๋Š” CI/CD๋ฅผ ์‚ฌ์šฉ ํ•ด ๋ณด๊ธฐ ์œ„ํ•จ.
  3. ๋„์ปค ์นœํ™”์ ์ด๊ธฐ ๋•Œ๋ฌธ!

How to ?

  1. dockerhub์—์„œ gitlab image๋ฅผ ๋Œ์–ด์˜จ๋‹ค.

    docker pull gitlab:latest
    
  2. Gitlab Container์„ ์œ„ํ•œ ์„ค์ •ํŒŒ์ผ์ด ํฌํ•จ๋œ docker_compose.gitlab.yml์„ ์ž‘์„ฑํ•œ๋‹ค.

    #docker-compose.gitlab.yml
    gitlab:
        image: 'gitlab/gitlab-ce:latest'
        restart: always
        hostname: {your_domain}
        environment:
            GITLAB_OMNIBUS_CONFIG: |
                external_url 'http://{your_domain}'
        ports:
            - '10080:80'
            - '10443:443'
            - '10022:22'
        volumes:
            - '/{your_work_directory}/gitlab_storage/config:/etc/gitlab'
            - '/{your_work_directory}/gitlab_storage/logs:/var/log/gitlab'
            - '/{your_work_directory}/gitlab_storage/data:/var/opt/gitlab'
    

    image๋Š” ๋Œ์–ด์˜จ gitlab ์ด๋ฏธ์ง€
    restart๋Š” ์žฌ์‹œ์ž‘ ๋˜์—ˆ์„๋•Œ ๋‹ค์‹œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ ํ•  ๊ฒƒ์ธ์ง€ ์—ฌ๋ถ€
    environment์—์„œ external์€ domain์— ๋Œ€ํ•œ ์š”์ฒญ์„ ๋ฐ›๊ธฐ ์œ„ํ•จ์ด๋ฉฐ
    ํฌํŠธ๋Š” ์ด ์ „ ๊ฒŒ์‹œ๋ฌผ์—์„œ nginx๋กœ reverse proxy๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ํ–ˆ๊ธฐ์— ๋‹ค๋ฅธ ํฌํŠธ์—์„œ ๋‹ค์‹œ 80, 443, 22๋กœ ์ด์–ด์ฃผ์—ˆ๋‹ค.
    volume์€ ์ถ”ํ›„ ์ €์žฅ์†Œ ํ™•์žฅ์— ๋Œ€๋น„ํ•˜์—ฌ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ์— ๋ฐ”์ธ๋“œ ๋งˆ์šดํŠธ๋กœ ํ•˜์˜€๋‹ค.

  3. ์œ„์™€ ๊ฐ™์ด ์ƒ์„ฑ์ด ๋œ๋‹ค๋ฉด, ๋‘ ๊ฐ€์ง€์˜ ๋ฐฉ๋ฒ•์ด ์ƒ๊ธด๋‹ค.

    1. nginx์™€ gitlab์„ ๊ฐ™์ด docker_compose -> ๊ฐ™์€ network๋กœ ํฌํŠธํฌ์›Œ๋”ฉ
    2. docker network๋ฅผ ์ด์šฉํ•œ internal network

    1๋ฒˆ ๋ฐฉ๋ฒ•์€ ์ถ”ํ›„ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋กœ ํ™•์žฅํ•˜๊ธฐ ์œ„ํ•จ๊ณผ ์•ž๋‹จ์—์„œ nginx container์œผ๋กœ reverse proxy๋ฅผ ํ•œ๋‹ค๋Š” ๋ชฉ์ ์— ๋งž์ง€ ์•Š์•„ 2๋ฒˆ์„ ํƒํ•˜์˜€๋‹ค.

  4. docker network ํ™•์ธ

    docker network ls
    

    ๊ฒฐ๊ณผ๋ฌผ ์ค‘ bridge๊ฐ€ default์ด๋ฉฐ nginx์™€ ์œ„ gitlab์€ default network๋กœ ๋ฌผ๋ ค์žˆ๋‹ค. default network id๋ฅผ ์ด์šฉํ•ด ์ถ”์ ํ•œ๋‹ค.

    docker network inspect {network_id}
    

    ๊ฐ ์ปจํ…Œ์ด๋„ˆ์— ํ• ๋‹น๋œ ๋‚ด๋ถ€ ip๊ฐ€ ๋ณด์ธ๋‹ค. ๊ทธ์— ๋”ฐ๋ผ nginx์—์„œ ์„œ๋ธŒ๋„๋ฉ”์ธ์„ ์ด์šฉํ•ด reverse_proxy๋ฅผ ์„ค์ • ํ•ด ์ค€๋‹ค.

    #gitlab.conf
    server{
            listen 80;
            server_name {git.your_domain};
            location / {
                proxy_pass http://{your_git_container_internal_ip};
                proxy_set_header Host $host;
                ...
                proxy_set_header ~~
            }
    }
    

    service nginx restart

  5. git.your_domain ์ ‘์† ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‚˜์˜ค๋ฉด ์„ฑ๊ณต! image

Leave a comment