A suggested change would be not to just depend on the db container but only execute if a health check is passed making sure the db container is up and running.
It looks like this is for setting up a database with initial data, but how do you deal with the evolving state of the data over time? i.e. as the application is used by users and simultaneously iterated on by developers.
You are correct, this is a quick way to start a database for local development. In a real-world production environment, changes are typically managed with migration files named sequentially or with timestamps. Each file contains database changes, and the system tracks which migrations have been applied, allowing new updates by running pending files. Sometimes, a single file is used, divided into sections for each update. The main idea is to incrementally update the database rather than recreating it each time.
Hey, i new to docker and i have a few questions, I've learned some docker and i managed to write a more complex project now, it's purely to learn, i run docker compose up and it works fine, however, how would i manage this as an always running application? tecniclly this is a discord bot, i want it to run 24/7, and by adding the -d to the docker-compose i should be able to, but how do i update changes only to the python folder? do i have to docker-compose for every little change? also, is it ok to compose it again i ncase i change something in the dockerfiles ? would it do something weird to the mySQL database?
Using -d is an okay way to keep running your setup for a smaller project. If you make major changes in the Dockerfiles, you need to rebuild your entire docker-compose project. You can restart individual services using "docker-compose restart ", but any major changes will probably require a full restart with "docker-compose up -d --build". In a more proper setup, your services should be stateless, meaning it should not matter if they are being reset or not. You can define a volume for your database setup, allowing the data to be persisted on the server; this enables you to restart any database service (Look into "volumes", it is quite simple). In larger modern software architecture, this would be handled by some cloud provider, but it is basically the same concept. Hope this helps. Otherwise, feel free to ask more questions.
i want to make changes in database, but the database is not accepting changes. how to do it if I want to insert more values? the compose run one time and then it is not allowing any changes in database. why it is so?
It sounds like something is wrong. You should be able to connect to the database if you have an open port. Using a password and user, you should then be able to make changes.
Yes I figured it out what wrong input I was giving. Thank you. Also mysql is not working on localhost:3306 using docker compose. Without docker compose it is running. How to fix it
@geetikapaliwal4041 If you run a service like MySQL locally, its open ports will by default be available on your computer. If it is run inside a container, the ports are only available inside the container, so you need to define in your docker-compose file which ports should be accessible from outside the containers created by docker-compose.
Is there any option to keep the python container running? I tried adding tty: true and stdin_open: true to the yaml file but it still immediately exists..
The simple version is to run something in the container that keeps running like any backend server. If you want to keep any Linux container running you could run a tail "-f /dev/null" command which will keep the process open. A docker-compose setup could then look like this: version: '3' services: python: build: context: . dockerfile: Dockerfile command: tail -f /dev/null
Very nice video, but sharing your code on git would be really helpfull. Then you can just copy-paste instead of typing all of this. PS: I had an issue that my port 3306 was already occupied on localhost. In this case just change the YML to 3307:3306
I agree sharing the code would be easier. But I think you learn way more writing the code yourself when it is smaller projects like this. I always share code with larger projects and I was on the fence regarding this project. I can share the code if you like?
Your python script can not connect to the student database table, because the table has not been created in the given database. Just added a link in the description to all then files if you want to have a closer look at my setup.
@@Randomcode_0 mysql.connector.errors.DatabaseError: 2005 (HY000): Unknown MySQL server host 'mysql' (-3) have you faced this? even if I give 50s sleep
@@frenzydf I got the issue when you map the port , in compose you will be using the container port only not the port mapped to the local machine. By default anything you copy to initd folder does not have execute permissions so give chmod 777 to the .sql file CMD in mysql Dockerfile.
A suggested change would be not to just depend on the db container but only execute if a health check is passed making sure the db container is up and running.
That is a good and interesting and addition which could be added in most use cases. Thanks for sharing!
Cara, você mostrou o que eu precisava. Resolveu dois problemas de uma vez. Parabéns!
Amazing video, helped a lot! keep up the good work!!
Thanks, will do!
This is really helpful and succinct!
Glad it was helpful!
why I am getting empty result ?
pythonapp_1 | DB connected
pythonapp_1 | []
project_pythonapp_1 exited with code 0
It looks like this is for setting up a database with initial data, but how do you deal with the evolving state of the data over time? i.e. as the application is used by users and simultaneously iterated on by developers.
You are correct, this is a quick way to start a database for local development. In a real-world production environment, changes are typically managed with migration files named sequentially or with timestamps. Each file contains database changes, and the system tracks which migrations have been applied, allowing new updates by running pending files. Sometimes, a single file is used, divided into sections for each update. The main idea is to incrementally update the database rather than recreating it each time.
Hey, i new to docker and i have a few questions, I've learned some docker and i managed to write a more complex project now, it's purely to learn, i run docker compose up and it works fine, however, how would i manage this as an always running application? tecniclly this is a discord bot, i want it to run 24/7, and by adding the -d to the docker-compose i should be able to, but how do i update changes only to the python folder? do i have to docker-compose for every little change? also, is it ok to compose it again i ncase i change something in the dockerfiles ? would it do something weird to the mySQL database?
Using -d is an okay way to keep running your setup for a smaller project. If you make major changes in the Dockerfiles, you need to rebuild your entire docker-compose project. You can restart individual services using "docker-compose restart ", but any major changes will probably require a full restart with "docker-compose up -d --build". In a more proper setup, your services should be stateless, meaning it should not matter if they are being reset or not. You can define a volume for your database setup, allowing the data to be persisted on the server; this enables you to restart any database service (Look into "volumes", it is quite simple).
In larger modern software architecture, this would be handled by some cloud provider, but it is basically the same concept. Hope this helps. Otherwise, feel free to ask more questions.
is it possible to connect it to phpmyadmin too?
i want to make changes in database, but the database is not accepting changes. how to do it if I want to insert more values?
the compose run one time and then it is not allowing any changes in database. why it is so?
It sounds like something is wrong. You should be able to connect to the database if you have an open port. Using a password and user, you should then be able to make changes.
Yes I figured it out what wrong input I was giving. Thank you.
Also mysql is not working on localhost:3306 using docker compose. Without docker compose it is running. How to fix it
@geetikapaliwal4041 If you run a service like MySQL locally, its open ports will by default be available on your computer. If it is run inside a container, the ports are only available inside the container, so you need to define in your docker-compose file which ports should be accessible from outside the containers created by docker-compose.
@@Randomcode_0 I did port binding as 3306:3306 in docker compose.yml file like you mentioned in video. Still it is not working
Is there any option to keep the python container running?
I tried adding tty: true and stdin_open: true to the yaml file but it still immediately exists..
The simple version is to run something in the container that keeps running like any backend server. If you want to keep any Linux container running you could run a tail "-f /dev/null" command which will keep the process open.
A docker-compose setup could then look like this:
version: '3'
services:
python:
build:
context: .
dockerfile: Dockerfile
command: tail -f /dev/null
Very nice video, but sharing your code on git would be really helpfull. Then you can just copy-paste instead of typing all of this. PS: I had an issue that my port 3306 was already occupied on localhost. In this case just change the YML to 3307:3306
I agree sharing the code would be easier. But I think you learn way more writing the code yourself when it is smaller projects like this. I always share code with larger projects and I was on the fence regarding this project. I can share the code if you like?
And good to hear you found a solution when you encountered a problem!
It doesnt accept the host 😢
Thank you man
You're welcome!
Nossa, perfeito! Agradeço demais o vídeo. Assistindo do Brasil!
_mysql_connector.MySQLInterfaceError: Table 'db.students' doesn't exist getting the error
Your python script can not connect to the student database table, because the table has not been created in the given database. Just added a link in the description to all then files if you want to have a closer look at my setup.
@@Randomcode_0 mysql.connector.errors.DatabaseError: 2005 (HY000): Unknown MySQL server host 'mysql' (-3) have you faced this? even if I give 50s sleep
I have the same error
@@frenzydf I got the issue when you map the port , in compose you will be using the container port only not the port mapped to the local machine.
By default anything you copy to initd folder does not have execute permissions so give chmod 777 to the .sql file CMD in mysql Dockerfile.
@@paibroadcastingchannel-the579 I got this error ''Can't connect to MySQL server on 'mysql:3306" any ideas on how to solve this
Is it possible to get a script to run indefinitely? I've tried with a while true looping script but it keeps exiting with exit code 0.