验证docker-compose yml文件

时间:2015-03-24 06:00:38

标签: docker docker-compose

有没有简单的方法来验证docker-compose文件(docker-compose.yml又名fig.yml)的语法等,而无需正确运行docker?

我正在尝试向我的构建/测试管道添加快速检查以验证我的撰写文件。

2 个答案:

答案 0 :(得分:70)

与此同时,这已添加到docker-compose为here。现在验证您的文件就像这样简单 docker-compose -f docker-compose.yml config。与往常一样,您可以在与文件本身相同的文件夹中运行此-f docker-compose.yml部分或docker-compose config时省略public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); if (env.IsDevelopment()) { // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. builder.AddApplicationInsightsSettings(developerMode: true); } Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddApplicationInsightsTelemetry(Configuration); services.AddDbContext<ltgwarehouseContext>(options => options.UseSqlServer(Configuration["DefaultConnection:ConnectionString"])); services.AddMvc(); services.AddSingleton<ICommodityRepository, CommodityRepository> (); } } 部分。

答案 1 :(得分:0)

使用预提交框架 https://pre-commit.com/#usage 和这个钩子 https://github.com/IamTheFij/docker-pre-commit

安装 pre-commit 并将这些行添加到 .pre-commit-config.yaml

repos:
  # Docker hooks
  - repo: https://github.com/IamTheFij/docker-pre-commit
    rev: v2.0.0
    hooks:
      - id: docker-compose-check

然后运行 ​​precommit run --all-files