도커 자바 Hello World

Jmnote (토론 | 기여)님의 2019년 3월 28일 (목) 11:43 판 (→‎같이 보기)

1 확인

root@ubuntu:~/hello# docker version
Client:
 Version:           18.09.3
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        774a1f4
 Built:             Thu Feb 28 06:40:58 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.3
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       774a1f4
  Built:            Thu Feb 28 05:59:55 2019
  OS/Arch:          linux/amd64
  Experimental:     false
root@ubuntu:~/hello# ls
Main.class  Main.java

2 실습

root@ubuntu:~/hello# vi Dockerfile
FROM openjdk:8
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac Main.java
CMD ["java", "Main"]
root@ubuntu:~/hello# docker build -t my-java-app .
Sending build context to Docker daemon  4.096kB
Step 1/5 : FROM openjdk:8
8: Pulling from library/openjdk
22dbe790f715: Pull complete 
0250231711a0: Pull complete 
6fba9447437b: Pull complete 
c2b4d327b352: Pull complete 
cddb9bb0d37c: Pull complete 
b535486c968f: Pull complete 
f3e976e6210c: Pull complete 
b2c11b10291d: Pull complete 
Digest: sha256:ecc5e6f4a47bf3b37a7272d2a4ba0ec0f6cad5c21624a51ead16a14b02b051aa
Status: Downloaded newer image for openjdk:8
 ---> 82942d9df443
Step 2/5 : COPY . /usr/src/myapp
 ---> f5aaf2f759de
Step 3/5 : WORKDIR /usr/src/myapp
 ---> Running in 3709fdc8028c
Removing intermediate container 3709fdc8028c
 ---> 2cbc809929d3
Step 4/5 : RUN javac Main.java
 ---> Running in 6d2fa34fc69c
Removing intermediate container 6d2fa34fc69cㅊ
 ---> 77b6d3736c69
Step 5/5 : CMD ["java", "Main"]
 ---> Running in 046a7e1052ec
Removing intermediate container 046a7e1052ec
 ---> c9cabd6040fc
Successfully built c9cabd6040fc
Successfully tagged my-java-app:latest
root@ubuntu:~/hello# docker images my-java-app
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
my-java-app         latest              c9cabd6040fc        4 minutes ago       624MB
root@ubuntu:~/hello# docker run -it --rm my-java-app
My First Java
root@ubuntu:~/hello# docker run -it --rm --name my-running-app my-java-app
My First Java

3 같이 보기

4 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}