본문 바로가기

카테고리 없음

Docker : Dockerfile을 이용

Dockerfile을 이용하여 Docker 이미지를 만들고 Docker 컨테이너를 실행합니다.

Dockerfile에는 Docker 컨테이너의 구성 내용을 정리해 설명하는 구성 관리에도 도움이됩니다.

 

1.예를 들어, httpd 설치 및 index.html 추가 및 httpd를 80로 시작하는 Dockerfile을 만듭니다.

[root @ dlp ~] # vi Dockerfile

# 새로 만들기

FROM centos

MAINTAINER ServerWorld <admin@srv.world>

 

RUN yum -y install httpd

RUN echo "Hello DockerFile"> /var/www/html/index.html

EXPOSE 80

CMD [ "-D", "FOREGROUND"]

ENTRYPOINT [ " / usr / sbin / httpd "]

 

# 이미지 빌드 ⇒ docker build -t [이미지 이름] : [태그].

[root @ dlp ~] # docker build -t web_server : latest.

Sending build context to Docker daemon 10.24 kB

Step 0 : FROM centos

 ---> 7322fbe74aa5

Step 1 : MAINTAINER ServerWorld <admin@srv.world>

 ---> Running in fa5364b3d41f

 ---> 57d8fd36b7f7

.....

... ..

Removing intermediate container 3efa8e1dcae9

Successfully built 7c39aaa338b4

 

[root @ dlp ~] # docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

web_server latest 7c39aaa338b4 24 seconds ago 283.9 MB

docker.io/centos latest ce20c473cd8a 8 weeks ago 172.3 MB

 

# 백그라운드에서 컨테이너를 시작

[root @ dlp ~] # docker run -d -p 80:80 web_server

[root @ dlp ~] # docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

eda2b1482272 web_server "/ usr / sbin / httpd -D F"35 seconds ago Up 34 seconds 0.0.0.0:80->80/tcp mad_bhabha

 

[root @ node02 ~] # curl http : // localhost /

Hello DockerFile