shipping-docker / vessel
简单的Docker开发环境
README
使用小巧的Docker开发环境快速启动。
文档
完整文档可以在https://vessel.shippingdocker.com找到。
安装
Vessel只是一组设置本地Docker开发环境的文件,除了Docker本身外,无需全局安装任何东西!
这就是使用它的全部
composer require shipping-docker/vessel php artisan vendor:publish --provider="Vessel\VesselServiceProvider" # Run this once to initialize project # Must run with "bash" until initialized bash vessel init ./vessel start
在浏览器中转到http://localhost
并查看您的Laravel网站!
Lumen
如果您正在使用Lumen,则需要手动复制Vessel文件而不是使用php artisan vendor:publish
。您可以使用以下命令来完成此操作
cp -R vendor/shipping-docker/vessel/docker-files/{vessel,docker-compose.yml,docker} .
然后您就可以像平常一样安装并继续使用了。
多环境
Vessel会尝试在您的机器上绑定端口80和3306,因此您只需在浏览器中访问http://localhost
即可。
但是,如果您运行了多个Vessel实例,启动时会出现错误;每个端口只能使用一次。为了解决这个问题,您可以通过设置以下两种方式中的任意一种,为每个项目使用不同的端口
在.env
文件中
APP_PORT=8080
MYSQL_PORT=33060
或启动Vessel时
APP_PORT=8080 MYSQL_PORT=33060 ./vessel start
然后您可以在http://localhost:8080
查看您的项目,并从端口33060
本地访问您的数据库;
Sequel Pro
由于我们将MySQL绑定到端口3306
,SequelPro可以直接访问数据库。
用户root
的密码由.env
文件中的环境变量DB_PASSWORD
设置。
端口设置必须与
MYSQL_PORT
环境变量匹配,默认为3306
。
常用命令
这里有一些内置的辅助工具您可以使用。任何未在vessel
脚本中定义的命令都将默认传递给docker-compose
命令。如果不使用任何命令,它将运行docker-compose ps
来列出此环境正在运行的容器。
显示Vessel版本或帮助
# shows vessel current version $ vessel --version # or [ -v | version ] # shows vessel help $ vessel --help # or [ -H | help ]
启动和停止Vessel
# Start the environment ./vessel start ## This is equivalent to ./vessel up -d # Stop the environment ./vessel stop ## This is equivalent to ./vessel down
开发
# Use composer ./vessel composer <cmd> ./vessel comp <cmd> # "comp" is a shortcut to "composer" # Use artisan ./vessel artisan <cmd> ./vessel art <cmd> # "art" is a shortcut to "artisan" # Run tinker REPL ./vessel tinker # "tinker" is a shortcut for "artisan tinker" # Run phpunit tests ./vessel test ## Example: You can pass anything you would to phpunit to this as well ./vessel test --filter=some.phpunit.filter ./vessel test tests/Unit/SpecificTest.php # Run npm ./vessel npm <cmd> ## Example: install deps ./vessel npm install # Run yarn ./vessel yarn <cmd> ## Example: install deps ./vessel yarn install # Run gulp ./vessel gulp <cmd>
Docker命令
如前所述,任何未识别为内置命令的内容都将作为docker-compose
命令的参数。这里有一些有用的技巧
# Both will list currently running containers and their status ./vessel ./vessel ps # Check log output of a container service ./vessel logs # all container logs ./vessel logs app # nginx | php logs ./vessel logs mysql # mysql logs ./vessel logs redis # redis logs ## Tail the logs to see output as it's generated ./vessel logs -f # all logs ./vessel logs -f app # nginx | php logs ## Tail Laravel Logs ./vessel exec app tail -f /var/www/html/storage/logs/laravel.log # Start a bash shell inside of a container # This is just like SSH'ing into a server # Note that changes to a container made this way will **NOT** # survive through stopping and starting the vessel environment # To install software or change server configuration, you'll need to # edit the Dockerfile and run: ./vessel build ./vessel exec app bash # Example: mysqldump database "homestead" to local file system # We must add the password in the command line this way # This creates files "homestead.sql" on your local file system, not # inside of the container # @link https://serversforhackers.com/c/mysql-in-dev-docker ./vessel exec mysql mysqldump -u root -psecret homestead > homestead.sql
包含什么?
这个项目的目标是简洁。它包括
这是如何工作的?
如果您对Docker不熟悉,请尝试这个Docker在开发中课程,该课程解释了如何构建此项目的关键主题。
如果您想了解此工作流程是如何开发的,请查看Shipping Docker并注册免费课程模块,该模块解释了构建此Docker工作流程的过程。
支持的系统
Vessel需要Docker,目前仅在Windows、Mac和Linux上工作。
Windows需要运行Hyper-V。使用Git Bash(MINGW64)和WSL受到支持。原生Windows仍在开发中。