dockware / dockware

Managed Shopware 6 Docker setups with dockware. Run any Shopware 6 version within minutes (locally) in Docker
https://dockware.io
MIT License
153 stars 52 forks source link

Include external Database (MYSQL) #213

Open Praktikant1981 opened 8 months ago

Praktikant1981 commented 8 months ago

Hi, I would like to take up this topic too. So far all attempts have failed.

https://docs.dockware.io/faq/dockware-and-other-images

It is described here that it is possible to use an “external” MYSQL server. I don't know what I'm doing wrong but the container simply doesn't take over the data from the .env but the internal server is always used. What can I do or what am I doing wrong?

Maybe someone has managed it and can tell you how to do it?!

Thank you in advance!

boxblinkracer commented 8 months ago

Hi

what do you mean by "taking over the data"? or what is still used from the internal server?

if you have a different MySQL container, then you just need to change the .env connection string to that host and then the dockware or Shopware container connects to a remote DB on another container

all database data is then on that container and not in dockware anymore

Praktikant1981 commented 8 months ago

thanks for the quick reply.


version: "3"

services:

     shopware:
       image: dockware/play:latest
       container_name: shopware
       ports:
          - "80:80"
       networks:
          - web

     db:
       image: mysql:5.7
       container_name: mysql
       networks:
         - web
       environment:
         - MYSQL_ROOT_PASSWORD=hidden
         - MYSQL_USER=shopuser
         - MYSQL_PASSWORD=secret
         - MYSQL_DATABASE=shopware

networks:
   web:
     external: false

with the .env with the content

DATABASE_URL=mysql://shopuser:secret@db:3306/shopware

unfortunately the data is written to the "internal" database.

I've also

 env_file:
         - .env

still integrated into the docker-compose.yml. The “internal” database was also used here.

I would also be happy to post the logs here, maybe you can then say more about what the problem is?!

Praktikant1981 commented 8 months ago

sorry, pressed wrong, shouldn't be closed yet

boxblinkracer commented 8 months ago
Screenshot 2024-02-27 at 18 54 39

hi just tried it and after switching .env I immediately get this error

Warning: Failed to load plugins. Message: An exception occurred while executing a query: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shopware.plugin' doesn't exist

which is OK, because it points to the new database which is currently empty of course

docker exec -it shopware bash vi .env

then scroll down and change the DATABASE_URL host

then

php bin/console cache:clear

can you try this

Praktikant1981 commented 8 months ago

Thanks for the support.

I create the .env in the same directory as the docker-compose.yml Actually, the entries should be taken over from the local .env when starting. If I change the .env in docker, the changes are only available until the docker is restarted.

how do I get the local .env to overwrite the necessary parts in docker?

martinweinmayr commented 8 months ago

Simply mount yor local .env to the container as .env.local and you are fine ?

volumes:
  - .env:/var/www/html/env.local
martinweinmayr commented 8 months ago

did you solved it?

Praktikant1981 commented 8 months ago

I already thought something like that. But I actually know that such parameters are actually passed to the container using docker-compose. Above all, the entire .env on the Docker is then overwritten. But if there's no way to simply pass the values, I'll probably have to do it that way. Thanks again for the super quick help

m4djack commented 5 months ago

We also have the issue to get the database to run on RDS on AWS, we managed to solve it with this hack:


            "entryPoint": [
                "sh",
                "-c"
            ],
            "command": [
                "sed 's/^DATABASE_URL=.*$/DATABASE_URL=mysql:\\/\\/USER:PASSWORD@URL:3306\\/shopware/' -i /var/www/html/.env && /entrypoint.sh ||echo failed"
            ],