docker db service등록하고 실행하기 (service 등록, 실행, 재실행, 중지)

1. 개요
 - 서버 재실행 시 컨테이너가 자동 실행할 수 있도록 서비스 등록.

2. 예제
 - 컨테이너 목록 확인
 $ sudo docker ps -a

 - /etc/systemd/system에 서비스 작성 (각 DB 모두 만듬)
 $ vi docker_postgres.service

 - 에디터 작성
[Unit]
Wants=docker_postgres.service
After=docker_postgres.service

[Service]
RemainAfterExit=yes
ExecStart=/usr/bin/docker start postgres
ExecStop=/usr/bin/docker stop postgres

[Install]
WantedBy=multi-user.target

 - 데몬 재시작 (수정 후 재시작)
 $ systemctl daemon-reload

 - 서비스 등록
 $ systemctl enable docker_postgres.service

 - 서비스 확인
 $ systemctl status docker_postgres.service

 - 모든 서비스 상태 표시
 $ systemctl list-units --type=service

 - 현재 실행중인 서비스 확인
 $ service --status-all|grep +

 - 부팅 시 서비스가 아닌 명령어로 서비스 자동실행 하는 법
 $ sudo docker update --restart=always <container-id>
 --ex)
 $ sudo docker update --restart=always postgres



댓글