Multi container applications
-
Lets add a database to our application.
-
Where should we run the database? Same container?
-
Problems with same container, multiple processes:
- Multiple processes in same container requires extra code to manage it. Scaling up / down, starting & closing. What happens if one process crashes out?
- What happens if only one process changes but other doesn’t? Means we have to redeploy the entire application.
- Your scaling will differ depending on process. Usually you’d have different scaling on a front end compared to a back end.
Database container
Mac
docker run -d \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7
docker ps
docker exec -it ${containerName} mysql -u root -p
Mac M1
docker run -d \
--platform "linux/amd64" \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7
Windows
docker run -d `
--network todo-app --network-alias mysql `
-v todo-mysql-data:/var/lib/mysql `
-e MYSQL_ROOT_PASSWORD=secret `
-e MYSQL_DATABASE=todos `
mysql:5.7
Lets jump into the DB
Note
Keeping in mind the password is secret as we set in the MYSQL_ROOT_PASSWORD
environment variable
SHOW DATABASES;
exit
docker rm -f ${containerName}