본문 바로가기

⭐ AWS/AWS | Docker (도커)

로컬에서 Docker 이미지 생성 및 웹 페이지 띄우기(Dockerfile 추가)

2022.03.17 - [AWS/AWS | Docker (도커)] - 로컬에서 docker 실행하기 (windows 10 환경)

 

로컬에서 docker 실행하기 (windows 10 환경)

1. docker 프로그램 다운로드 https://docs.docker.com/desktop/windows/install/ Install Docker Desktop on Windows docs.docker.com 사이트로 접속하고 Docker Desktop for windows 를 클릭하여 프로그램을 다..

may9noy.tistory.com

도커를 설치하지 않았다면 위에 링크로 이동하여 도커를 설치

 

1. 도커 설치 후 파워쉘에서 도커 정보를 입력하고 확인한다.

PS C:\Windows\system32> docker -v
Docker version 20.10.13, build a224086

도커 이미지 검색, 현재는 아무런 이미지가 없으므로 리스트가 조회되지 않는다.

PS C:\Windows\system32> docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE

도커 이미지 생성, 샘플 이미지인 hello-word 를 다운 받는다.

PS C:\Windows\system32> docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:4c5f3db4f8a54eb1e017c385f683a2de6e06f75be442dc32698c9bbe6c861edd
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

2. 다운받은 docker 이미지 정보 확인

docker 이미지 리스트 조회, 방금 다운받은 hello-world 이미지를 확인 할 수 있다.

PS C:\Windows\system32> docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   5 months ago   13.3kB

docker 컨테이너 확인

PS C:\Windows\system32> docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
74c65b584fb8   hello-world   "/hello"   9 minutes ago   Exited (0) 9 minutes ago             mystifying_shirley

docker 컨테이너 삭제, container 삭제 후 조회하면 리스트에서 사라진것을 볼 수 있다.

PS C:\Windows\system32> docker container rm mystifying_shirley
mystifying_shirley
PS C:\Windows\system32> docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
PS C:\Windows\system32>

docker 이미지 삭제, 이전에 다운받은 이미지가 삭제 된것을 확인 할 수 있다.

PS C:\Windows\system32> docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   5 months ago   13.3kB
PS C:\Windows\system32> docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:4c5f3db4f8a54eb1e017c385f683a2de6e06f75be442dc32698c9bbe6c861edd
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359
PS C:\Windows\system32> docker image ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

3. docker 이미지를 활용한 웹서버 테스트

docker-compose.yaml 파일을 아래와 같이 생성한다.

volumes의 경우 로컬 경로 ./php → 도커 컨테이너 경로 /var/www/html/ 로 바인딩 하도록 설정
ports의 경우 로컬 포트 8000 → 도커 컨테이너 80 포트로 바인딩 되도록 설정

version: '3.3'
services:
 web:
  image: php:7.3-apache
  container_name: php73
  volumes:
   - ./php:/var/www/html/
  ports:
   - 8000:80

작성된 파일을 D: 드라이브의 docker 라는 폴더를 만들고 저장한다. (경로는 자유롭게 설정)

docker-compose.yaml 파일을 작성한 경로에서 아래와 같이 입력하여 실행, 작성한 yaml 파일의 내용을 참조하여 파일을 다운로드 하는 모습이다.

실행이 완료되면 아래와 같이 다운받은 docker 이미지가 자동적으로 실행된다.

4. 실행한 docker 이미지를 웹에서 실행

localhost:8000 을 브라우저에서 입력하여 정상적으로 접속이 되는지 확인

접속은 되나 현재 리소스가 없으므로 아래와 같이 나온다.

index.php 파일을 root 경로에 생성하여 화면에 띄워보자.

브라우저에서 실행하면 아래와 같이 화면에 내용이 표시된것을 불 수 있다.

# Dockerfile 을 활용한 Docker 이미지 생성하기

2021.06.10 - [혼자하는 프로젝트/AWS + 도커 구현] - 5.도커 컨테이너 생성 및 아파치 웹서버 생성

 

5.도커 컨테이너 생성 및 아파치 웹서버 생성

sudo apt update를 입력하여 최신버전으로 유지한다. sudo apt install apt-transport-https 를 입력하여 설치한다. sudo apt install ca-certificates 를 입력하여 설치한다. sudo apt install curl 을 입력..

may9noy.tistory.com