본문 바로가기
[따베도]

4-2. 도커 컨테이너 만들어보기: 실습

by SAMSUNG Metaverse-Cloud 2023. 1. 12.
728x90

 

 

 

 

## hello.js 생성

 

const http = require('http');
const os = require('os');

console.log("Test server starting...");

var handler = 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);

 

 

 

 

## vi dockerfile 생성

 

## 도커 빌드
- docker build -t hellojs:latest . 

 

- 컨테이너 완성

 

 

 

 

 

 

 


## 신규 폴더 생성
- mkdir webserver

 

FROM ubuntu:18.04
LABEL maintainer="OKY<oky@gmail.com>"
# 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 .

 


## 도커 실행
- docker run -d -p 80:80 --name web webserver:v1
- docker rm -f web

 

 

 

 

 

 

## 컨테이너 배포 
## docker login
## docker images   (REPOSITORY 앞에 도커허브 계정 삽입 필요)
- docker tag webserver:v1 smlinux/webserver:v1
- docker tag hellojs:latest smlinux/hellojs:latest

 

## 도커 푸시
## docker push smlinux/webserver:v1

 

 

 

 

 

- webpage.sh 생성
-----------------------------------------------------------
#!/bin/bash
mkdir /htdocs
while :
do
 /usr/games/fortune > /htdocs/index.html
 sleep 10
done
-----------------------------------------------------------

 

 

 

1) 도커파일 생성
guru@docker-ubuntu:~/fortune$ cat Dockerfile 
FROM debian:bullseye
COPY webpage.sh /
RUN apt-get update \
    && apt-get install -y fortune
CMD ["bash", "/webpage.sh"]

1-1) 도커 빌드
docker build -t fortune:20.02 .


2) 컨테이너 구동 
guru@docker-ubuntu:~/fortune$ docker run -d --name fortune fortune:20.02
563ae382db7e4d8097445717194b511955547fbfe5d6648c0d9d35d23a575dad


3) 테스트    (도커 들어가기)
- docker exec -it 6a28cc081078  /bin/bash

root@563ae382db7e:/htdocs# cat index.html
You have had a long-term stimulation relative to business.
root@563ae382db7e:/htdocs# cat index.html
Q: What do they call the alphabet in Arkansas?

 

 

 

 

 

 

 

 

https://github.com/237summit/lab-test/blob/master/app.js

 

GitHub - 237summit/lab-test

Contribute to 237summit/lab-test development by creating an account on GitHub.

github.com

 

728x90