<aside> 💡 docker logs -f CONTAINER ID (컨테이너 에러 확인하기)

</aside>

1. nodejs 애플리케이션 컨테이너 만들기 : hellojs

mkdir hellojs
cat > hello.js

const http = require('http');
const os = require('os');
console.log("Test server starting...");

var handle = function(request, response) {
  console.log("Received request from " + request.connection.remoteAddress);
  response.writeHead(200);
  response.end("Container Hostname: " + os.hostname() + "\\n");
};

var www = http.createServer(handler);
www.listen(8080);

dockerfile만들기

vi dockerfile

FROM node:12 -> node:12 라는 컨테이너를 베이스로 둠
COPY hello.js /  -> hello.js를 컨테이너의 최상위 경로에 복사
CMD ["node", "/hello.js"]  -> node hello.js 라는 명령어 실행
-> 라인 하나당 레이어 하나 만들어진다 생각하면됨

docker build -t hellojs:latest .

컨테이너 만들기 성공

Untitled

2. 우분투 기반의 웹 서버 컨테이너 만들기

mkdir webserver

docerfile만들기

FROM ubuntu:18.04
LABEL maintainer="Seongme Lee <[email protected]>"
# install apache
RUN apt-get update \\
    && apt-get install -y apache2
RUN echo "TEST WEB" > /var/www/html/index.html
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-DFOREGROUND"]

docker build -t webserver:v1 .

Untitled

실행시켜보자

docker run -d -p 80:80 --name web webserver:v1

Untitled

3 .만들어놓은 컨테이너 배포하기

docker login (docker.hub 계정 아이디와 비번 입력해야함)