Dockerfile 작성
아래 내용은 테스트 예제 이며 실제 Web-server 운영시는 docker-compose 를 많이 사용합니다.
단독 서비스를 운영하지 않는다면 Service 를 apache + mariadb 로 컨테이너를 나눠서 관리하는게
좀더 편하게 관리 할수 있습니다.
Github
test@docker-test:~$ git clone https://github.com/visualwork/Docker-test.git
/Docker-test/test01 에 Dockerfile 이 있습니다. 🙂
Dockerfile 을 작성 nginx Dockerfile 예제
nginx 디렉토리 생성후 Dockerfile 을 작성 합니다.
test@ubuntu1604:~$ mkdir nginx test@ubuntu1604:~$ cd nginx/ test@ubuntu1604:~$ mkdir data test@ubuntu1604:~/nginx$ vi Dockerfile FROM ubuntu:16.04 MAINTAINER sanjuk <test@anonymouse.com> RUN apt-get update RUN apt-get install -y nginx RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf RUN chown -R www-data:www-data /var/lib/nginx VOLUME /data WORKDIR /etc/nginx CMD ["nginx"] EXPOSE 80 EXPOSE 443
FROM: 배포판 이미지
MAINTAINER : 메인테이너 정보
RUN : 스크립트 실행 또는 명령어 실행
VOLUME : 호스트와 공유할 디렉토리 정보 (컨테이너의 볼륨과 호스트 디렉토리 연결로 보시면 됩니다.)
CMD : 컨테이너 시작시 실행할 스크립트 또는 명령어
EXPOSE 호스트와 연결할 포트
build 명령으로 이미지 생성
test@ubuntu1604:~/nginx$ docker build --tag nginx-web01 . Sending build context to Docker daemon 2.048kB Step 1/11 : FROM ubuntu:16.04 16.04: Pulling from library/ubuntu 3b37166ec614: Already exists 504facff238f: Already exists ebbcacd28e10: Already exists c7fb3351ecad: Already exists 2e3debadcbf7: Already exists Digest: sha256:45ddfa61744947b0b8f7f20b8de70cbcdd441a6a0532f791fd4c09f5e491a8eb Status: Downloaded newer image for ubuntu:16.04 ---> b9e15a5d1e1a Step 2/11 : MAINTAINER sanjuk <test@anonymouse.com> ---> Running in d1dc8cb42cec Removing intermediate container d1dc8cb42cec ---> 31d7669ef650 Step 3/11 : RUN apt-get update ---> Running in 058f47b0073a Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB] Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB] Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [95.4 kB] ~중략
image 확인
test@ubuntu1604:~/nginx$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx-web01 latest fae98fcdce37 2 minutes ago 212MB ubuntu 16.04 b9e15a5d1e1a 3 weeks ago 115MB test@ubuntu1604:~/nginx$
docker 실행
test@ubuntu1604:~/nginx$ docker run --name web-service -d -p 80:80 -v /root/nginx/data:/data nginx-web01 a56208a8b4e04b800ee523353f2a31b7c1be79ac19689410214070df9fbea6e8 test@ubuntu1604:~/nginx$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a56208a8b4e0 nginx-web01 "nginx" 3 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp, 443/tcp web-service test@ubuntu1604:~/nginx$
webbrowser 확인
nginx 컨테이너 접속
test@ubuntu1604:~/nginx$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f03a5bb4f756 nginx:latest "nginx" 12 minutes ago Up 12 minutes 0.0.0.0:80->80/tcp, 443/tcp hello-nginx test@ubuntu1604:~/nginx$ test@ubuntu1604:~/nginx$ docker exec -it f03a5bb4f756 /bin/bash root@f03a5bb4f756:/etc/nginx#