



제약
docker pull centos:centos7.9.2009
docker images
docker create --name test-container centos:centos7.9.2009

# 캘린더
apt install ncal
cal
which cal

# CentOS : 꺼지지 않게 /bin/bash 실행
docker create -it --name test-cont centos:centos7.9.2009 /bin/bash
# 컨테이너 시작
docker container start test-cont
# 컨테이너로 접근
docker container attach test-cont
# 컨테이너 안에서도 캘린더
cal
# CentOS
yum install -y net-tools
# 컨테이너 IP 확인 방법
hostname -I
# 작동 시작 컨테이너
docker container start test-cont
docker container ps # 작동중인 컨테이너
# 실행 중간에 나오기 (켜져 있음)
Ctrl + pq
# 종료하고 나오기(컨테이너가 종료됨)
exit
# 테스트한 것 1.txt존재 확인하기
ls -l



docker container create -it --name test01 centos:centos7.9.2009 /bin/bash
docker container create -it --name test02 centos:centos7.9.2009 /bin/bash
docker start test01
docker start test02
hostname -I
ping 172.17.0.2 # 핑이 된다.

# 네트워크 사용하기
docker network ls
# 새로운 컨테이너 2개 생성
docker container create -it --name test03 centos:centos7.9.2009 /bin/bash
docker container create -it --name test04 centos:centos7.9.2009 /bin/bash
# 네트워크 생성
docker network my-network
# 네트워크 연결
docker network connect my-network test03
docker network connect my-network test04
# 컨테이너 시작
docker container start test03
docker container start test04


ping -c 1 test03
ping -c 172.17.0.2
ping -c 172.18.0.2

docker network inspect bridge
# 새롭게 생성한 네트워크
docker network inspect my-network


# 실행 > 접속까지
docker container run -it --name attach_cont centos:centos7.9.2009 /bin/bash
# 컨테이너 > 백그라운드 실행 > 밖에 있음
docker container run -itd --name exec_cont centos:centos7.9.2009 /bin/bash


# 따로 옵션을 쓸필요 없다.
docker container attach attach_cont
docker container attach exec_cont
# 어떤 명령어를 쓰면서 들어가는지 알아야한다.
docker container exec -it exec_cont /bin/bash

docker container stop $(docker container ps -q)
docker container rm $(docker container ps -aq)
# 컨테이너 실행과 동시에 접속
docker container run -it --name nginx_01 nginx
# 백그라운드로 실행
docker container run -itd --name nginx_02 nginx
# 실행상태 유지하면서 나오기
Ctrl + p + q
# 컨테이너 종료하면서 나오기
exit

# 그냥 현재 프로세스에 들어가는 경우
docker container attach nginx_02
> 작동중인 nginx 상태를 본다.
# 명령어를 삽입하면서 접속하는 방법
docker container exec -it nginx_02 /bin/bash
> 새로운 터미널을 열면서 들어간다.

