[docker] docker compose2

HyunDong Lee·2021년 4월 14일
1

docker

목록 보기
7/8
post-thumbnail

Docker compose - php, apache2

dockercompose.yamldocker-compose.yaml파일을 작성한다.

version: '3'

services:
        class-offering:
                image: php:7.2-apache
                volumes:
                        - ./classes:/var/www/html
                ports:
                        - 5001:80

        website:
                image: php:7.2-apache
                volumes:
                        - ./website:/var/www/html
                ports:
                        - 5000:80
                depends_on:
                        - class-offering

//ubuntu docker compose install
$sudo docker rm -f $(sudo docker ps -a -q) //모든 docker container 제거
$sudo curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$sudo chmod +x /usr/bin/docker-compose
$sudo docker-compose up -d

docker-compose install

docker-compose install

sudo docker-compose up -d

website 폴더 내에 index.php

<html>
	<head>
		<title>Class Offered in 2020</title>
	</head>
	
	<body>
		<h1>These are classes offered by easttwave</h1>
		<ul>
			<?php
				$json = file_get_contents('http://class-offering');
				$obj = json_decode($json);

				foreach ($obj as $class) {
					echo "<li>$class</li>";
				}
			?>
		</ul>
	</body>
</html>

classes 내의 index.php

<?php
        $myclasses[] = 'Software Engineering';
        $myclasses[] = 'Digital logic';
        $myclasses[] = 'Internet programming';
        $myclasses[] = 'Network Programming';

        $myJson = json_encode($myclasses);

        echo $myJson;
?>

port에 연결하여 instance 확인

docker-compose - wordpress

version: '3.3'

services:
        db:
                image: mysql:5.7
                volumes:
                        - db_data:/var/lib/mysql
                restart: always
                environment:
                        MYSQL_ROOT_PASSWORD: somewordpress
                        MYSQL_DATABASE: wordpress
                        MYSQL_USER: wordpress
                        MYSQL_PASSWORD: wordpress

        wordpress:
                depends_on:
                        - db
                image: wordpress:latest
                ports:
                        - "8000:80"
                restart: always
                environment:
                        WORDPRESS_DB_HOST: db:3306
                        WORDPRESS_DB_USER: wordpress
                        WORDPRESS_DB_PASSWORD: wordpress
                        WORDPRESS_DB_NAME: wordpress
volumes:
        db_data: {}

명령어 sequence

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo mv /usr/local/bin/docker-compose /usr/bin/docker-compose
$ sudo chmod +x /usr/bin/docker-compose
$ sudo docker-compose up -d

Welcome to wordpress

인바운드 규칙 설정

0개의 댓글