포스트

도커 이미지 예제

단계1. hello.js 확인

CheckHellojs

1
2
3
4
5
6
7
8
9
10
11
12
13
const http = require('http');
const os = require('os');
console.log("Test server starting...");

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

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

단계2. Dockerfile 확인

CheckDockerfile

단계3. Dockerfile과 hello.js이 있는 폴더로 이동

터미널을 열고 Dockerfile, hello.js 파일 확인

1
ls

단계4. Dockerfile을 이용하여 hellojs 이미지 생성

  • docker build -t <이미지명>:<태그> <기준이 되는="" 폴더="" 위치="">
1
docker build -t hellojs:latest

단계5. 생성된 hellojs 이미지 확인

1
docker image ls

CheckHellojsImage

단계6. hellojs-web 컨테이너 생성

  • 태그가 latest인 경우 생략 가능
1
docker run --name hellojs-web -d -p 8080:8080 hellojs

GenerateHellojsContainer

단계7. 작동중인 hellojs-web 컨테이너 확인

1
docker ps

단계8. hellojs-web에 접속

  • http://localhost:8080/ AccessHellojs

단계9. 실행중인 컨테이너 삭제

1
2
docker rm -f hellojs-web
docker ps -a

RemoveContainer

단계10. 도커허브 -> repositories -> 아이디 확인

  • 도커허브 : https://hub.docker.com/

DockesrHubRepoId

단계11. 도커 로그인

1
docker login

DockerLogin

단계12. 도커허브아아디/ 이미지명

  • docker tag <이미지명>:<태그> <도커허브아이디>/<이미지명>:<태그>
1
2
docker tag hellojs:latest goodwon593/hellojs:latest
docker image ls # 생성된 이미지 확인 

DockerhubIDImgName

도커허브로 이미지 업로드

  • docker push <도커허브아이디>/<이미지명>:<태그>
1
docker push yeongha/hellojs

UploadImgToDockerhub

단계14. 도커허브에서 이미지 업로드 확인

CheckUploadedImg


이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.