Docker 설치하기
https://www.docker.com/get-started/
Developers - Docker
Docker Hub The world’s leading service for finding and sharing container images with your team and the Docker community. For developers and those experimenting with Docker, Docker Hub is your starting point into Docker containers. Create an account and s
www.docker.com
시스템에 맞게 설치
윈도우인 경우 WSL(Windows Subsystem for Linux)을 설치해야 진행이 가능하다. WSL을 통해 윈도우에서 리눅스 커널을 사용할 수 있음
![](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
npm init -y project init
npm i express
![](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
ex. Layer 0 (Base Image) -> Layer 1 (line 6) -> Layer 2 (line 10) -> Layer 3 (ex. build)
Docker는 Layer 0 ~ N 순으로 실행되는데, 변경된 내용이 없으면 업데이트하지 않는다고 함.
package*.json 파일은 npm install * 과 같이 의존성 목록을 추가해야 파일이 수정되는거에 비해, 프로젝트를 하면서 index.js 파일은 자주 업데이트가 되기 때문에. line 6보다 10을 아래쪽에 설정하여 docker container 구축 속도를 단축시킴
docker build -f Dockerfile -t fun-docker .
-f : 어떤 Dockerfile을 사용할지 명시
-t : Docker Image 별칭을 부여
docker images
로컬에 만들어진 이미지를 확인
docker run -d -p 8080:8080 fun-docker
-d stands for detached: to run a container in a background. 백그라운드에서 실행
-p is port publishing: maps a port on the container to a port on the host. 포트를 지정
8080:8080 -> localhost port : docker container port . 포트를 연결시켜준다
docker ps
현재 실행중인 컨테이너들의 리스트를 확인할 수 있음
docker logs 'CONTAINER ID'
컨테이너의 로그를 확인할 수 있음.
![](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
Docker Image -> Docker Hub Push
docker images - REPOSITORY(fun-docker), TAG(latest) 확인
docker tag fun-docker:latest user/docker-example:latest
docker login - docker 계정 정보를 입력하여 로그인
docker push user/docker-example:latest
![](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
docker run -dp 8080:8080 'tpwls8122/gocker-example'
참고 사이트
https://www.youtube.com/watch?v=LXJhA3VWXFA&list=LL&index=1
https://docs.docker.com/get-started/
Orientation and setup
docs.docker.com
'Docker & k8s' 카테고리의 다른 글
Docker-Compose를 통한 Node, Redis 환경 구성하기 (0) | 2023.09.03 |
---|