-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbtc-lab5
More file actions
108 lines (71 loc) · 2.5 KB
/
btc-lab5
File metadata and controls
108 lines (71 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
간단하게 컨테이너 빌드하기
Ubuntu 이미지 base에 apache, PHP를 연동하여 컨테이너를 빌드하시오.
$ cat Dockerfile
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y apache2 \
&& apt-get install -y software-properties-common \
&& add-apt-repository ppa:ondrej/php \
&& apt-get update \
&& apt-get install -y php5.6
EXPOSE 80
CMD ["apachectl", "-DFOREGROUND"]
1. webserver 컨테이너 빌드하기
$ mkdir webserver
$ cd webserver
2. Dockerfile 생성
$ vim Dockerfile
FROM centos:7
RUN touch /etc/yum.repos.d/nginx.repo \
&& echo -e '[nginx]\nname=nage repo\nbaseurl=http://nginx.org/packages/centos/7/$basearch/\ngpgcheck=0\nenabled=1' > /etc/yum.repos.d/nginx.repo
RUN yum -y install nginx curl
CMD ["nginx", "-g", "daemon off;"]
3. 컨테이너 이미지 빌드
$ docker build -t myweb:20210622 .
...
Successfully tagged myweb:20210622
4. 빌드 된 컨테이너 이미지 확인
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myweb 20210622 0bffae5d2f31 38 seconds ago 335MB
5. 생성된 컨테이너 이미지를 이용해 웹서버 동작 시키기
$ docker run -d --name webserver myweb:20210622
$ curl 172.17.0.2
6. 컨테이너 삭제하기
$ docker ps
ce0a4f2504bf myweb:20210622 "nginx -g 'daemon of…" About a minute ago Up About a minute webserver
$ docker rm -f webserver
webserver
1. nodejs 애플리케이션 컨테이너 빌드하기
$ mkdir appjs
$ cd appjs/
$ cat > app.js
const http = require('http');
const os = require('os');
console.log("Test server starting…");
var handler = function(req, res) {
res.writeHead(200);
res.end("Container Hostname: " + os.hostname() + "\n");
};
var www = http.createServer(handler);
www.listen(8080);
$ cat > Dockerfile
FROM node:12
COPY app.js /app.js
ENTRYPOINT ["node", "app.js"]
2. 컨테이너 빌드
$ docker build -t appjs .
3. 빌드 된 컨테이너 확인
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
appjs latest 12cfd448b8eb 21 seconds ago 918MB
4. 빌드한 컨테이너 실행해보기
$ docker run -d --name appjs appjs
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be999811a5d6 appjs "node app.js" 5 seconds ago Up 4 seconds appjs
$ curl 172.17.0.2:8080
Container Hostname: be999811a5d6
5. 실행되었던 컨테이너를 종료하자.
$ docker rm -f appjs