1. docker 설치 - Redhat 8
- 테스트 목적상 docker ce 버전 설치
Docker Enterprise Edition (Docker EE) is designed for enterprise development and IT teams who build, ship,
and run business-critical applications in production and at scale. Docker EE is integrated, certified, and supported
to provide enterprises with the most secure container platform in the industry.
# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
>> redhat repository가 유효하지 않아 CentOS repository 사용
# dfn clean all
# dnf repolist
# dnf install docker-ce
# systemctl enable docker --now
# systemctl status docker
# docker version
# docker run hello-world
2. docker-compose 설치
https://github.com/docker/compose/releases/
# curl -L "https://github.com/docker/compose/releases/download/v2.5.1/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
3. 이미지 검색 및 다운로드
# docker search httpd
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
httpd The Apache HTTP Server Project 4015 [OK]
centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or bui… 44
centos/httpd 35 [OK]
hypoport/httpd-cgi httpd-cgi 2 [OK]
# docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
214ca5fb9032: Pull complete
7cf31a2eeec6: Pull complete
bf666e57b9f2: Pull complete
c15a4e94ae6b: Pull complete
dc25474c7f97: Pull complete
Digest: sha256:2d1f8839d6127e400ac5f65481d8a0f17ac46a3b91de40b01e649c9a0324dea0
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest c58ef9bfbb57 12 days ago 144MB
4. Container 생성 (이미지 실행)
- foreground 실행
# docker run httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Tue May 24 05:49:28.251468 2022] [mpm_event:notice] [pid 1:tid 139627169013056] AH00489: Apache/2.4.53 (Unix) configured -- resuming normal operations
[Tue May 24 05:49:28.251619 2022] [core:notice] [pid 1:tid 139627169013056] AH00094: Command line: 'httpd -D FOREGROUND'
[Tue May 24 05:49:48.558142 2022] [mpm_event:notice] [pid 1:tid 139627169013056] AH00491: caught SIGTERM, shutting down
- background 실행
# docker run -d --name httpd24 httpd
fc2db775b2c661c4834c517289d127a715c77e8ca3e14a7d9f7690246e106db9
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc2db775b2c6 httpd "httpd-foreground" 35 seconds ago Up 34 seconds 80/tcp httpd24
5. 컨테이너 설정 확인 : 내부 IP 확인
# docker inspect httpd24
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
# curl http://172.17.0.2
<html><body><h1>It works!</h1></body></html>
6. 컨테이너 내부 shell 실행으로 진입 및 index.html 파일 확인
# docker exec -ti http24 /bin/bash >> http24 컨테이너의 /bin/bash 실행
root@fc2db775b2c6:/usr/local/apache2# ls
bin build cgi-bin conf error htdocs icons include logs modules
root@fc2db775b2c6:/usr/local/apache2# cd htdocs
root@fc2db775b2c6:/usr/local/apache2/htdocs# ls
index.html
root@fc2db775b2c6:/usr/local/apache2/htdocs# exit
exit
7. 컨테이너 내부의 index.html 복사 및 내용 갱신 후 업로드
# docker cp httpd24:/usr/local/apache2/htdocs/index.html ./
# cat index.html
<html><body><h1>It works!</h1></body></html>
# echo '<html><body><h1>It works very nicely!</h1></body></html>' > index.html
# cat index.html
<html><body><h1>It works very nicely!</h1></body></html>
# docker cp index.html httpd24:/usr/local/apache2/htdocs/index.html
8. 컨테이너 재시작 및 변경 사항 확인
# docker stop httpd24
httpd24
# docker start httpd24
httpd24
# curl http://172.17.0.2
<html><body><h1>It works very nicely!</h1></body></html>
9. 변경된 컨테이너 이미지 저장 및 기존 이미지 삭제
# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest c58ef9bfbb57 12 days ago 144MB
# docker commit httpd24 httpd:2.4.53-20220524
sha256:ebf03184ef6abea9f3d0ea8e308dd1b3aede120e96f7383700a53ecb2656a756
# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd 2.4.53-20220524 ebf03184ef6a 4 seconds ago 144MB
httpd latest c58ef9bfbb57 12 days ago 144MB
# docker stop httpd24
httpd24
# docker rm httpd24
httpd24
# docker image rm httpd:latest
Untagged: httpd:latest
Untagged: httpd@sha256:2d1f8839d6127e400ac5f65481d8a0f17ac46a3b91de40b01e649c9a0324dea0
10. 컨테이너 재가동 및 OS reboot 후 자동 시작되도록 설정
# docker run -d --restart unless-stopped --name httpd24 httpd:2.4.53-20220524
5929c219307c04a51fcbd641c228962660a2e64ae427e96be3fde86b8bcaabe2
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5929c219307c httpd:2.4.53-20220524 "httpd-foreground" 9 seconds ago Up 8 seconds 80/tcp httpd24
11. OS reboot 후 가동 확인
# reboot
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5929c219307c httpd:2.4.53-20220524 "httpd-foreground" 52 seconds ago Up 6 seconds 80/tcp httpd24
# curl http://172.17.0.2
<html><body><h1>It works very nicely!</h1></body></html>
12. 호스트의 포트와 바인딩
# docker run -d --name httpd-ext -p 80:80 httpd:2.4.53-20220524
>> 80포트를 호스트의 80 포트와 바인딩
'IT > Kubernetes, Docker' 카테고리의 다른 글
Kubenernetes 1.20 이후 docker 사용 : cri-dockerd (0) | 2022.06.14 |
---|---|
docker - network (0) | 2022.06.14 |
Kubernetes 설치 (Redhat8, Single Master) (0) | 2022.06.14 |