컨테이너(linux의 cgroup, namespace)는 이미지를 통해 배포된다.
생성된 컨테이너는 이미지의 내용을 그대로 '풀어놓는 것'과 같으므로 read 할 수 있다. write는 안된다.
생성된 컨테이너는 이미지로부터 읽을 수 있는 부분과 추가적으로 자체 작성(write)할 수 있는 레이어로 구성된다.
Docker build [옵션]
일반적으로는 두 개 이상의 이미지를 생성하고자 한다면 별도의 디렉토리를 만들고 각 디렉토리에서 별도의 Dockerfile을 생성하는 형식으로 이미지를 만들게 된다.
ex)
LABEL author=hoon
LABEL email=hoon@test.com
LABEL version=2.0
Question) Ubuntu 18.04 이미지를 베이스이미지로하여 nginx를 설치하고 해당 nginx 에서는 개발자가 작성한 index.html 파일이 보이도록 설정한다. 외부에서 접속시 해당 컨테이너의 웹페이지가 보여야 하며 포트번호는 8882를 이용하여 접속할 수 있어야 한다. 단, 위의 실습전 각 ubuntu의 IP 주소는 192.168.1.101~126 으로 설정해야 한다.
이미지 웹 서비스 경로 httpd /usr/local/apache2/htdocs nignx /usr/share/nginx/html centos+httpd /var/www/html ubuntu+nginx /var/www/html ubuntu+httpd /var/www/html
Answer)
###네트워크 구성
sudo vi /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
ethernets:
ens32:
addresses: [192.168.1.126/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 168.126.63.1]
dhcp4: no
version: 2
# renderer: NetworkManager
sudo netplan apply # ip 변경 된다.
ping www.google.com # 인터넷 되는지 확인
mkdir nginx_test ; cd nginx_test
echo "nginx clear" > index.html # 보여줄 index 파일
vi Dockerfile
docker build -t nginx_test:1.0 .
docker container run -d -p 8881:80 nginx_test:1.0
결과
Process
Answer)
mkdir xpress_maker; cd xpress_maker
vi Dockerfile
#Dockerfile
FROM centos:7
RUN yum clean all
RUN yum update -y
RUN yum -y install wget git httpd
RUN wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
RUN yum -y localinstall remi-release-7.rpm
RUN yum -y install epel-release yum-utils
RUN yum-config-manager --enable remi-php74 #php7.4버전을 설치하겠다
RUN yum -y install php php-fpm php-gd php-mysql php-xml
RUN git clone https://github.com/xpressengine/xe-core.git /var/www/html/xe # /var/www/html/xe 에 xpressengine 클론
WORKDIR /var/www/html/xe
RUN mkdir files
WORKDIR /var/www/html
RUN chmod -R 707 xe
RUN chown -R apache:apache xe #루트가 아닌 apache에 권한 부여
EXPOSE 80
CMD httpd -D FOREGROUND # 컨테이너에서 아파치가 실행되도록 함
docker built -t xe:1.0 .
docker container run -d --name db1 -e MYSQL_ROOT_PASSWORD=test123 -e MYSQL_DATABASE=xe mysql:5.7
docker container run -d --name xe1 --link db1:mysql -p 8888:80 xe:1.0