1. Multi container apps - quan1997ap/Backend-app-note GitHub Wiki
- There’s a good chance you’d have to scale APIs and front-ends differently than databases.
- Separate containers let you version and update versions in isolation.
- While you may use a container for the database locally, you may want to use a managed service for the database in production. You don’t want to ship your database engine with your app then.
- Running multiple processes will require a process manager (the container only starts one process), which adds complexity to container startup/shutdown.
https://docs.docker.com/compose/install/linux/
After installation, you should be able to run the following and see version information.
docker compose version
Step 1: At the root of the /getting-started/app folder, create a file named docker-compose.yml.
Step 2: Define the app service : https://docs.docker.com/get-started/08_using_compose/
services:
app:
image: node:18-alpine
command: sh -c "yarn install && yarn run dev"
ports:
- 127.0.0.1:3000:3000
working_dir: /app
volumes:
- ./:/app
environment:
MYSQL_HOST: mysql
MYSQL_USER: root
MYSQL_PASSWORD: secret
MYSQL_DB: todos
mysql:
image: mysql:8.0
volumes:
- todo-mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: todos
volumes:
todo-mysql-data:
-
services: Danh sach cac service se dinh nghia (The name will automatically become a network alias, which will be useful when defining our MySQL service )
-
app: Ten service con
-
image + command
-
ports
- Sort + Long synctax : https://docs.docker.com/compose/compose-file/05-services/#long-syntax-3
127.0.0.1:3000:3000
-
volumes
-
3.1 Make sure no other copies of the app/db are running first (docker ps and docker rm -f ).
-
3.2 Start up the application stack We’ll add the -d flag to run everything in the background.
docker compose up -d
- 3.3 View log
docker compose logs -f
or - log of service app
docker compose logs -f app
docker compose down
If you want to remove the volumes ( add the --volumes flag )
docker compose down --volumes