Scenario: Deploying a Multi-Container Application with Docker Compose

Scenario: Deploying a Multi-Container Application with Docker Compose

  1. Create the docker-compose.yml

cat docker-compose.yml

version: '3.8'

services:

web:

image: nginx:latest

container_name: nginx-server

ports:

- "8080:80"

volumes:

- ./html:/usr/share/nginx/html

depends_on:

- db

restart: always

db:

image: mysql:5.7

container_name: mysql-db

environment:

MYSQL_ROOT_PASSWORD: rootpassword

MYSQL_DATABASE: mydb

MYSQL_USER: user

MYSQL_PASSWORD: password

ports:

- "3306:3306"

volumes:

- db_data:/var/lib/mysql

restart: always

volumes:

db_data:


2. You can place custom file under ./html.

3. Run --> docker-compose up -d

[+] Running 3/3

? Network root_default Created 0.2s

? Container mysql-db Started 0.1s

? Container nginx-server Started

4. Run docker ps

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

85760292a061 nginx:latest "/docker-entrypoint.…" 4 minutes ago Up 4 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp nginx-server

1eae77ba8695 mysql:5.7 "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql-db


5. Go to Browser and paste PublicIP:8080


Server was deployed on top of AWS .



要查看或添加评论,请登录

社区洞察

其他会员也浏览了