본문 바로가기

AWS Cloud School

[06.11] Docker image, 2-tier architecture in docker

 

Dockerfile 작성법

FROM - 베이스이미지 지정
WORKDIR - 디렉토리 지정 (cd 대신 사용하면 좋음)
ADD (호스트 파일명 or 경로) (컨테이너 파일명 or 경로) - 호스트의 파일이나 디렉토리를 컨테이너 이미지에 삽입
COPY - ADD의 하위호환 명령어. COPY에 몇가지 기능이 추가된 게 ADD
(ex. 압축파일 자동으로 압축을 풀어줌)
RUN - 컨테이너 이미지를 빌드할 때 수행되는 명령
RUN <명령어1> && <명령어2> && <명령어3> - 여러개의 명령을 한꺼번에(같은 layer에서) 수행
CMD - 컨테이너 생성 후 실행시 수행할 명령 (docker run을 수행하면서 이미지 뒤에 명령어를 따로 지정하면 무시됨)
ENTRYPOINT - 컨테이너 생성 후 실행시 무조건 수행할 명령. ENTRYPOINT와 CMD를 함께 쓰게 되면 CMD명령을 '인자'로 받아온다
EXPOSE - 포트를 노출 (docker run을 수행할 때 -P라는 옵션을 사용하면 EXPOSE된 포트가 명시. 따라서 -p로 퍼블리싱 할때는 의미가 없다)
ENV - 환경변수 지정

 

 

 

 

#### index.jsp

 

tee index.jsp<<EOF

<%@ page contentType="text/html; charset=UTF-8"%>

<html>

     <head><title>hello world</title></head>

     <body>

     <h2>

             TOMCAT TEST<br><br>

             time : <%= new java.util.Date()%>

             <%@ page import="java.net.InetAddress" %><br>

             <%InetAddress inet= InetAddress.getLocalHost();%>

             WAS ip : <%=inet.getHostAddress()%>

     </h2>

       </body>

</html>

EOF

 

 

 

 

 

tee dbtest.jsp<<EOF

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ page import="java.sql.*"%>

<h1>DB</h2>

<%

        Connection conn=null;

        try{

                String Url="jdbc:mysql://<DB주소>/<DB이름>";

                String Id="<DB유저>";

                String Pass="<유저암호>";

 

                Class.forName("com.mysql.jdbc.Driver");

                conn=DriverManager.getConnection(Url,Id,Pass);

                out.println("was-db Connection Success!");

        }catch(Exception e) {

                e.printStackTrace(); 

}

%>

EOF