ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Ubuntu - 재부팅시 Docker를 이용한 Jenkins 자동으로 ON
    우아한 테크코스/이것저것 2020. 7. 31. 09:34
    반응형

    Docker 컨테이너 확인 후 제거

    $ sudo docker ps
    CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES
    4bb24e16a109        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   6 seconds ago       Up 5 seconds        0.0.0.0:50000->50000/tcp, 0.0.0.0:8080->8080/tcp   jenkins-blueocean
    b9754d7f715e        docker:dind           "dockerd-entrypoint.…"   2 minutes ago       Up 2 minutes        2375/tcp, 0.0.0.0:2376->2376/tcp                   jenkins-docker
    
    $ sudo docker stop jenkins-blueocean
    $ sudo docker stop jenkins-docker
    
    $ sudo docker rm jenkins-blueocean
    $ sudo docker rm jenkins-docker
    
    // 안 될경우 강제 삭제
    $ sudo docker rm -f jenkins-blueocean
    $ sudo docker rm -f jenkins-docker

    Docker 컨테이너 다시 띄우기

     다시 띄우는 이유 : --rm 옵션을 사용했었는데, 그렇게 되면 재부팅시 컨테이너 정보를 상실하여 Systemctl로 등록을 해도 정상 동작을 하지 않기 때문에 해당 옵션 제외하여 띄움

    $ sudo docker container run \
      --name jenkins-docker \
      --detach \
      --privileged \
      --network jenkins \
      --network-alias docker \
      --env DOCKER_TLS_CERTDIR=/certs \
      --volume jenkins-docker-certs:/certs/client \
      --volume jenkins-data:/var/jenkins_home \
      --publish 2376:2376 \
      --restart=always \
      docker:dind
    $ sudo docker container run \
      --name jenkins-blueocean \
      --detach \
      --network jenkins \
      --env DOCKER_HOST=tcp://docker:2376 \
      --env DOCKER_CERT_PATH=/certs/client \
      --env DOCKER_TLS_VERIFY=1 \
      --publish 8080:8080 \
      --publish 50000:50000 \
      --volume jenkins-data:/var/jenkins_home \
      --volume jenkins-docker-certs:/certs/client:ro \
      jenkinsci/blueocean
    

    jenkins-blueocean.service 생성

    $ sudo vi /etc/systemd/system/jenkins-blueocean.service 
    
    [Unit]
    Description=docker jenkins-blueocean Service
    After=docker.service
    Requires=docker.service
    
    [Service]
    Restart=always
    ExecStart=/usr/bin/docker start -a jenkins-blueocean
    ExecStop=/usr/bin/docker stop -t 2 jenkins-blueocean
    
    [Install]
    WantedBy=multi-user.target

    jenkins-docker.service 생성

    $ sudo vi /etc/systemd/system/jenkins-docker.service
    [Unit]
    Description=docker jenkins-docker Service
    After=docker.service
    Requires=docker.service
    
    [Service]
    Restart=always
    ExecStart=/usr/bin/docker start -a jenkins-docker
    ExecStop=/usr/bin/docker stop -t 2 jenkins-docker
    
    [Install]
    WantedBy=multi-user.target

     

    jenkins 컨테이너들 데몬 등록

    데몬 : 쉽게 이해하자면 서버 시작시 실행되는 프로그램

    $ sudo systemctl enable jenkins-blueocean.service
    Created symlink /etc/systemd/system/multi-user.target.wants/jenkins-blueocean.service → /etc/systemd/system/jenkins-blueocean.service.
    $ sudo systemctl enable jenkins-docker.service
    Created symlink /etc/systemd/system/multi-user.target.wants/jenkins-docker.service → /etc/systemd/system/jenkins-docker.service.

    서버 재부팅 - 확인 완료

    $ sudo docker ps
    CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES
    bc433d480fa7        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   18 minutes ago      Up 4 seconds        0.0.0.0:50000->50000/tcp, 0.0.0.0:8888->8080/tcp   jenkins-blueocean
    9fee1c2f7b77        docker:dind           "dockerd-entrypoint.…"   18 minutes ago      Up 5 seconds        2375/tcp, 0.0.0.0:2376->2376/tcp                   jenkins-docker
    반응형

    댓글

Designed by Tistory.