Nginx를 이용한 정적 페이지 서버 만들기

<html>

<head>

<title>영광스러운 도커 이미지 예제</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

</head>

<body>

<h1>Nginx 서버를 도커 이미지로 만들어서 공개합니다.</h1>

</body>

</html>
FROM nginx

COPY index.html /usr/share/nginx/html/index.html
$ docker build -t lab02/exam1 .

$ docker run -d --rm \\

-p 50001:80 \\

lab02/exam1
(base) glory@Gloryui-MacBookPro ~ % cd Desktop 
(base) glory@Gloryui-MacBookPro Desktop % cd nginx
(base) glory@Gloryui-MacBookPro nginx % docker build -t lab02/exam1 .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM nginx
 ---> 298ec0e28760
Step 2/2 : COPY index.html /usr/share/nginx/html/index.html
 ---> Using cache
 ---> bbb2e07507fb
Successfully built bbb2e07507fb
Successfully tagged lab02/exam1:latest
(base) glory@Gloryui-MacBookPro nginx % docker run -d --rm \\
  -p 50000:80 \\
  lab02/exam1
c6e8e42d59efb70c6fd1bef9fd99
docker: Error response from daemon: driver failed programming external connectivity on endpoint nifty_shockley (65c8cc331cd6ddaf4de4b642b0c3af248ac4de86e9fd5bc4db52c4c443764231): Bind for 0.0.0.0:50000 failed: port is already allocated.
(base) glory@Gloryui-MacBookPro nginx % docker run -d --rm \\
  -p 50001:80 \\
  lab02/exam1
05f5e7d86fa63221b0d9
(base) glory@Gloryui-MacBookPro nginx %

nginx - Docker Hub


Node.js 기반의 웹서비스를 빌드하기

const http = require('http');

const os = require('os');

const port = process.env.PORT || 8080;

process.on('SIGINT', function() {

console.log('shutting down...');

process.exit(1);

});

var handleRequest = function(request, response) {

console.log(`Received request for URL: ${request.url}`);

response.writeHead(200);

response.end(`Hello, World!\\nHostname: ${os.hostname()}\\n`);

};

var www = http.createServer(handleRequest);

www.listen(port, () => {

console.log(`server listening on port ${port}`);

});