Docker를 이용한 nginx+php https서버 세팅하기

in #docker7 years ago (edited)

사전 점검 사항: docker가 설치되어 있고 데몬이 설정 되어 있어야 한다.

apt install docker-ce
apt install docker-compose

Docker swarm을 초기화한다.

docker swarm init

Local docker registry 서비스를 시작한다. curl 명령어가 {}를 리턴 해 주면 성공

docker service create --name registry --publish published=5000,target=5000 registry:2
curl http://localhost:5000/v2/

Dockerfile을 작성한다. 아래의 etc_letsencrypt, etc_nginx, var_www_html은 미리 준비 해 둔 상태이다.


WORKDIR /workspace
VOLUME ["/etc/letsencrypt", "/etc/nginx" "/var/www/html"]

RUN apt-get update
RUN apt-get install -y --no-install-recommends --no-install-suggests ca-certificates

RUN ln -sf /dev/stdout /var/log/nginx/access.log \
 && ln -sf /dev/stderr /var/log/nginx/error.log
#RUN chown -R www-data /var/www/html

EXPOSE 80
EXPOSE 443
CMD ["nginx", "-g", "daemon off;"]

Image를 생성하고 태그를 작성해 local registry에 올린다.

docker image build . -t my-nginx:latest
docker tag my-nginx localhost:5000/my-nginx
docker push localhost:5000/my-nginx

docker-compose 파일을 생성한다.

version: '3'

services:
  my-nginx:
    #image: nginx:latest
    image: localhost:5000/my-nginx
    build: /root/docker/nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /root/docker/nginx/etc_letsencrypt:/etc/letsencrypt
      - /root/docker/nginx/etc_nginx:/etc/nginx
      - /root/docker/nginx/var_www_html:/var/www/html
    links:
      - php
  php:
    image: php:7-fpm
    #image: 127.0.0.1:5000/php
    volumes:
      - /root/docker/nginx/var_www_html:/var/www/html

docker-compose로 서비스를 테스트한다.

docker-compose up -d

웹 페이지가 열리는지 확인 해 보자. phpinfo 파일을 작성 해 var_www_html 에 넣어 잘 동작하는지 확인.

<?php phpinfo(); ?>

잘 동작하면 서비스를 내리고 정식으로 등록한다. docker service ls로 확인

docker-compose down
docker stack deploy -c docker-compose.yml web
docker service ls

해당 사항을 local registry에 올릴 수 있다.

docker-compose push

리부팅 후에도 잘 동작하는지 확인 해 보자.

참고자료

[1] Local registry생성과 태그 만들기 https://novemberde.github.io/2017/04/09/Docker_Registry_0.html
[2] Docker stack으로 deploy하기 https://docs.docker.com/engine/swarm/stack-deploy/

Sort:  

Congratulations @chronon! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

You made your First Comment

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @chronon! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

The Steem blockchain survived its first virus plague!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.13
TRX 0.34
JST 0.035
BTC 108074.45
ETH 4399.12
USDT 1.00
SBD 0.83