다음의 Qwiklabs 과정을 거치면서 모르던 내용들 그리고 배웠던 내용들에 대해 써보았다:
- Introduction to Docker
우선, 저 과정을 거치면서 모르거나 새로 배운 내용들에 대한 정의를 써보도록 하겠다. 나름 나의 해석?도 들어가 있는 것이라 정확하지는 않을 수도 있으나, 최대한 찾아본 내용을 토대로 썼다.
※ Dockerfile: Docker can build images automatically by reading the instruction from the file. It is a text document that contains all the commands a user could call on the command line to assemble an image
Building a Docker image - Create a Dockerfile
먼저 Dockerfile 부터 만들어준다.
cat > Dockerfile <<EOF From node:6 WORKDIT /app ADD . /app EXPOSE 80 CMD ["node", "app.js] EOF
이 Dockerfile이 image를 어떻게 build 해야되는지 Docker daemon한테 지시한다.
- Initial line specifices the base parent image → In this case, the official Docker image for node version 6
- We set the working (current) directory of the container
- Add the current directory's contents (indicated by the " . ") into the container
- Expose the container's port so it can accept connections on that port
- Run the app.js using the node when the container launches
이제는 node application을 만들 것이다:
cat > app.js <<EOF const http = require('http'); const hostname = '0.0.0.0'; const port = 80; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World\n'); }); server.listen(port, hostname, () => { console.log('Server running at http://%s:%s/', hostname, port); }); process.on('SIGINT', function() { console.log('Caught interrupt signal and will exit'); process.exit(); }); EOF
이 부분은 port 80을 듣고 "Hello World"를 출력하는 간단한 HTTP server이다. (하지만 무슨 뜻인지는 잘 모르겠다.)
마지막으로 image를 build할 것이다
docker build -t node-app:0.1 .