[클라우드/Docker 기본(14) - Docker-compose(6) : Dockerfile,Compose]

SooYeon Yeon·2022년 8월 30일
0

클라우드 Docker

목록 보기
15/24

Dockerfile + docker-compose.yml 실습

mkdir test1 test2
touch test1/Dockerfile
touch test2/docker-compose.yml

웹서비스 데몬의 위치

이미지 웹서비스경로

httpd /usr/local/apache2/htdocs

nginx /usr/share/nginx/html

centos+httpd /var/www/html

ubuntu+nginx 동일

ubuntu+apache2(httpd) 동일

  • Dockerfile
FROM ubuntu:18.04

RUN apt update
RUN apt -y install apache2
ADD index.html /var/www/html/main.html
EXPOSE 80 8080

CMD apache2ctl -DFOREGROUND
  • index 파일 만들기
rapa@rapa:~/0823/test1$ echo "hello" > index.html
  • 이미지 배포
docker build -t myweb:1.0 .
# 만약 도커파일 이름이 다르다면 .대신 -f [도커파일이름] 으로 작성
  • 정보 확인
docker image inspect myweb:1.0
  • 컨테이너 배포
rapa@rapa:~/0823/test1$ docker run -d -p 8008:80 --name myweb01 myweb:1.0
72079468dfe80db34d199b8dbf6590a66349441f64c55af95d9612eb214dff57
  • 네트워크 / 볼륨 생성
rapa@rapa:~/0823/test2$ docker network create testnetwork1

rapa@rapa:~/0823/test2$ docker volume create testvolume1
  • docker-compose.yml

rapa@rapa:~/0823/test2$ cat docker-compose.yml 
version: '3.8'
services: 
  wordpress: 
    image: wordpress 
    networks: 
      - testnetwork1 
    volumes: 
      - /home/rapa/0823/test2/html:/var/www/html # MOUNT USING NFS 
    ports: 
      - "8881-8882:80" 
    links: 
      - db:mysql 
    depends_on: 
      - db 
    environment: 
      - WORDPRESS_DB_PASSWORD=test123 
      - WORDPRESS_DB_USER=root 
      - WORDPRESS_DB_NAME=testdb

  db: 
    image: mysql:5.7 
    networks: 
      - testnetwork1 
    volumes: 
      - testvolume1:/var/lib/mysql # VOLUME USING ISCSI 
    environment: 
      - MYSQL_ROOT_PASSWORD=test123 
      - MYSQL_DATABASE=testdb

networks: 
  testnetwork1: 
    external: true
volumes: 
  testvolume1: 
    external: true
  • 배포하기
rapa@rapa:~/0823/test2$ docker-compose up --scale wordpress=2 --scale db=2 -d
Creating test2_db_1 ... done
Creating test2_db_2 ... done
WARNING: The "wordpress" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Creating test2_wordpress_1 ... done
Creating test2_wordpress_2 ... done
  • docker-compose로 생성된 컨테이너 확인
rapa@rapa:~/0823/test2$ docker-compose ps
      Name                  Command            State             Ports         
-------------------------------------------------------------------------------
test2_db_1          docker-entrypoint.sh       Up       3306/tcp, 33060/tcp    
                    mysqld                                                     
test2_db_2          docker-entrypoint.sh       Exit 1                          
                    mysqld                                                     
test2_wordpress_1   docker-entrypoint.sh       Up       0.0.0.0:8881->80/tcp,::
                    apach ...                           :8881->80/tcp          
test2_wordpress_2   docker-entrypoint.sh       Up       0.0.0.0:8882->80/tcp,::
                    apach ...                           :8882->80/tcp

db2가 문제가 있기 때문에 wordpress2도 db1으로 링크될것임

0개의 댓글