Chapters
23 Chapters
|
2:22:24
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.4.1
Subscribe to download the code!Compatible PHP versions: ^7.4.1
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
03.
docker-compose & Exposed Ports
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
This tutorial also works great for Symfony 6!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.4.1",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^2.1", // 2.1.1
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.7", // 2.8.2
"knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
"knplabs/knp-time-bundle": "^1.11", // v1.16.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.1
"sentry/sentry-symfony": "^4.0", // 4.0.3
"stof/doctrine-extensions-bundle": "^1.4", // v1.5.0
"symfony/asset": "5.1.*", // v5.1.2
"symfony/console": "5.1.*", // v5.1.2
"symfony/dotenv": "5.1.*", // v5.1.2
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/framework-bundle": "5.1.*", // v5.1.2
"symfony/monolog-bundle": "^3.0", // v3.5.0
"symfony/stopwatch": "5.1.*", // v5.1.2
"symfony/twig-bundle": "5.1.*", // v5.1.2
"symfony/webpack-encore-bundle": "^1.7", // v1.8.0
"symfony/yaml": "5.1.*", // v5.1.2
"twig/extra-bundle": "^2.12|^3.0", // v3.0.4
"twig/twig": "^2.12|^3.0" // v3.0.4
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.0
"symfony/debug-bundle": "5.1.*", // v5.1.2
"symfony/maker-bundle": "^1.15", // v1.23.0
"symfony/var-dumper": "5.1.*", // v5.1.2
"symfony/web-profiler-bundle": "5.1.*", // v5.1.2
"zenstruck/foundry": "^1.1" // v1.5.0
}
}
28 Comments
Hi there,
I'm trying to change the variable MYSQL_ROOT_PASSWORD
MYSQL_ROOT_PASSWORD: passwordUnfortunately i can't access the database when i set to another value.
I have create the docker-compose.yml via <blockquote>bin/console make:docker:database</blockquote>
here is my docker-compose.yml
and my .env
Any ideas why setting a new root password doesn't work?
Hey Rooarii,
Looks like you're trying to set DATABASE_NAME and DATABASE_ROOT_USER_PWD while you have DATABASE_URL. They are incompatible with each others IIRC, so I'd recommend you to change password in the DATABASE_URL and drop all other "DATABASE_*" env vars you add below. Basically, if you need to change password to "test", do this:
DATABASE_URL="mysql://db_user:test@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4"
I.e. please, change the DATABASE_URL instead. Also, use symfony CLI command to boot the website, i.e. call: "symfony console" instead of "bin/console" - Symfony CLI will set up Docker env vars for you.
I hope this helps!
Cheers!
so docker deletes the image each time? This doesn't sound ideal. Is there a way to keep the docker database image so we can continue working on the data? Introducing volumes would have been a good idea as it's not great to rebuild the DB everytime - you'd probably need to use a bash command right to load fixtures and build the DB?
Hey Cameron,
The "down" command is useful when you want to re-create new containers from scratch, i.e. literally destroy old containers and its data and start new ones. If that's not what you want - just don't use it, use the "stop" command instead to stop the containers but do not delete them. :)
Cheers!
Hello,
I'm working on a mac, using Docker Desktop.
I downloaded the "finish" project.
I run :
$ docker-compose up -dThe composer image build correctly. I can see the logs on my terminal, and even the containers buing built on the Docker Desktop.
I can even do
$ docker-compose psand see my container running :I start the symfony server
$ symfony server:start -dwithout any issue.Now let's run
$ symfony var:export --multiline --vv(I add the "vv" to have see any issue), and then ... surprise :Symfony CLI seems to not to be able to get the Docker API & extract the VARS as it supposed to do ... So can't run the project.
Can you help me find a solution ?
Thank you.
Hi,
Are you using native macos terminal? or bundled in PHPStorrm to run docker? Have you tried to run the container from Docker desktop, and after few minutes check Symfony CLI?
Cheers!
Hello. I used the PHPStorm terminal. But I tried with the native terminal, and it doesn't change anything.
I just used the native terminal to start again the Symfony server. Waited for 5 minutes, then run the
symfony var:export, still the same error.ok and does
/var/run/docker.sockfile exists? probably a permission issue for example if your docker is running under another user. or maybedocker.sockis located somewhere in another folderActually, StackOverflow found the solution for me.
When you install Docker Desktop for Mac, it will install an old version of docker-machine, that is not exposing any API.
You have to uninstall docker desktop manually, also docker-image, and they, you should resintall docker via brew (as a cask).
It will reinstall docker, docker-machine & even docker desktop with the new version of docker-machine that is exposing its API.
Working fine now :)
Thank you !
That's pretty interesting because I have docker installed on mac and it was installed via installer not brew
Hello, my cli generates hashtags instead of asterisks in annotations, is there a way to change/configure that somewhere?
Hi, I'm having issues connecting to mysql :
<br />mysql -u symfony --password=ChangeMe --host=127.0.0.1 --port=52883<br />mysql: [Warning] Using a password on the command line interface can be insecure.<br />ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0<br />docker-compose ps
start_database_1 docker-entrypoint.sh postgres Up 0.0.0.0:52883->5432/tcp<br />my .env
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"<br />docker-compose.yml von recipes
`version: '3'
services:
###> doctrine/doctrine-bundle ###
database:
###< doctrine/doctrine-bundle ###
volumes:
###> doctrine/doctrine-bundle ###
db-data:
###< doctrine/doctrine-bundle ###
`
how can i fix them
For those not using Docker
In terminal set your mysql path to your installation of mysql
set path=%PATH%;C:\xampp\mysql\bin;
And then you can continue with the course
The standard port for xampp or mamp = 3306
mysql -u root --password=root--host=127.0.0.1 --port=3306
Hey ZoeF,
Thank you for sharing this information with others!
Cheers!
Is it possible to skip docker or docktrine completely using Symfony? I like the Symfony structure and Twig, but for now I'd like to just connect with my MySQL Database and use PDO.
Hey Farry7,
Yes, sure! Docker and Doctrine are completely different things. You can avoid using Docker and connect to your local MySQL DB directly from your application. About Doctrine - yes, some websites even don't have a DB and works great too :) Just configure the PDO connection and use it directly instead.
Though I suppose, about Doctrine you mean Doctrine ORM, but Doctrine also has their own abstraction layer around PDO called Doctrine DBAL. I'd still recommend you look at it instead of working with PDO directly. Doctrine DBAL works almost the same way, it's a low level interface, but it's more flexible and has some nice features, you can check it out here: https://www.doctrine-projec...
Cheers!
Hi everybody, I have problem. I dont get name of database after I wrote:SHOW DATABASES. I get just arrows..... Do you have idea where is problem?
Hey Vojtěch,
Ah, haha, I know this problem :p You just need to add semicolon after *every* command :) So, literally, try "SHOW DATABASES;"
Cheers!
Hi
I'm having issues connecting to mysql
any help ?
macbookpro@Leonardo cauldron_overflow % docker-compose exec database mysql -u root -password=password
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
i run
docker-composer down -v
docker-composer up -d
and now i'm getting this error
macbookpro@Leonardo cauldron_overflow % docker-compose exec database mysql -u root -password=password
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Hey Karim B.!
Hmm. What changes did you make to go from the "Access Denied" to the "Can't connect" error? The first one (access denied) actually seems a bit better :). It means that there was simply some problem with the password or credentials.
Also, to be sure, what does your docker-compose.yaml file look like?
Cheers!
hi there
here is the docker-compose.yaml file
Hey Karim B. !
Hmmm. Yea, there are no surprises with the docker-compose.yaml file - it looks simple and correct. Which error do you currently have - the "Access Denied" error or "Can't connect"? And what changes did you make to go from one error to the other?
Also, one other thing you can try is to "bash" into the container and then execute mysql from there. This won't make any difference (it won't suddenly work) but it may help debugging:
After running this, your terminal will be inside the container. You can then try the mysql commands directly. For example, for me (since I don't have the same problem as you), I can run:
And this will connect me to the database. As I mentioned, you'll probably still get an error, but you can then mess around with different options:
Let me know what you find out!
Cheers!
Hi,
I can't talk with mysql, where I have installed mysql locally. But app shows error I have added below:-
$ mysql -u root --password=123456 --host=127.0.0.1 --port=32768
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (10061)
I have changed mysql root password to 123456 because of my #mysql root password is 123456.
Jewel F.
hmm, that's interesting, is the service up and running? run
service mysql status(the command depends on your OS). Also, double-check that the port is correct, and, just in case, try withlocalhostinstead of127.0.0.1thanks
MolloKhan
service mysql status -> shows bash: service command not found
and the using of localhost instead of 127.0.0.1 it creates a still situation, which is not Hang but not doing anything. And when I write "exit" command on terminal it can exit from this situation.
Here is a screenshot link: https://snipboard.io/Xr124x...
"Houston: no signs of life"
Start the conversation!