英文:
How can I sync my Flutter Serverpod project on multiple Mac's remotely?
问题
我在MacBook Air M1上创建了一个Flutter Serverpod项目。然后我将它上传到GitHub。现在我的问题是,每当我从GitHub下载项目到我的iMac(不是同一台主机Mac)时,我在docker上找不到我的项目容器,即使我在docker桌面应用程序上使用相同的登录信息。请帮助我了解如何以这样的方式同步项目,以便我可以在多台远程的Mac上使用它。非常感谢任何帮助。
首先,我在MacBook Air M1上创建了该项目并上传到GitHub。现在,当我在另一台Mac(iMac)上使用相同的docker桌面应用程序ID登录时,我在docker中找不到相同的容器。我还尝试在iMac上运行我的服务器,它为我创建了一个全新的容器,但它根本不参考主容器。我还检查了Postico用于Postgres数据库,但它也不包含我在MacBAir上早先创建的任何表格或查询。
英文:
I have created a Flutter Serverpod project on MacBook Air M1.
Then i uploaded it to GitHub,
now my question is whenever I download the project from GitHub to my iMac(not the same host mac).
I don't find my project's container in docker on that Mac with same login on docker desktop app,
please help me on how to sync the project in such a way so that I can use it on multiple mac's remotely.
Any help is highly appreciated.
Firstly I made the project on MacBook Air M1 and uploaded to GitHub.
now when I log in with the same id for docker desktop app on another Mac(iMac), I don't find the same container inside docker.
I also tried running my server on iMac and it created a new container for me altogether but it doesn't refer to the main container at all.
Also I checked Postico for Postgres DB but it also doesn't contain any tables or query I have made earlier on MacBAir.
答案1
得分: 1
这是Docker的工作原理,每台机器都有自己的Docker镜像实例。它们不会在主机之间共享,并且数据永远不会同步。容器通常被设计为可移植且无状态,因此它们将加载存储在主机机器上的持久数据卷。
在我看来,更明智的做法是在不同的环境中重新创建表和数据。我通常保持我的开发环境灵活且易于重置/恢复。因此,我宁愿编写一些脚本来填充一些所需的基础数据,您可以运行它们以获得一个起点。
数据库表定义已经存在于您的serverpod项目中,您只需在数据库上运行pgsql文件即可。您将在服务器项目的“生成”文件夹下找到pgsql文件。
有了这个说法,可以通过创建卷的备份来在机器之间复制数据,然后将其发送到其他计算机并加载备份到Docker中。查看这个答案这里。官方文档在此。
您感兴趣的Serverpod卷通常以这种方式命名:<project_name>_server_<project_name>_data
,其中**<project_name>**是您项目的名称。您可以通过运行docker volume ls
来列出所有的Docker卷。
英文:
This is how docker works, each machine has its own instances of the docker images. They are not shared between hosts and data is never synced. Containers are generally intended to be portable and stateless hence they will load the volumes where you store persistent data from the host machine you are running them on.
In my opinion, it is most likely a smarter idea to simply recreate the tables and data in your different environments. I generally keep my dev environments flexible and easy to reset/restore. So instead I would rather build some script to populate some needed base data that you can run to get a starting point from.
The database table definitions lives in your serverpod project already, all you have to do there is to run the pgsql files on your database. You will find the pgsql files under the generated
folder in the server project.
With that said it is possible to copy the data between machines by creating a backup of the volume and then send it to the other computer and load the backup into docker. Take a look at this answer here. Official documentation here.
The volume you are interested in from Serverpod is normally named like this: <project_name>_server_<project_name>_data
, where <project_name> is the name of your project. You can list all your docker volumes by running docker volume ls
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论