question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docker inspect output parsing fails on Windows

See original GitHub issue

Environment:

  • Jib version: 2.0.0
  • Build tool: Gradle 5.6.2
  • OS: Windows 10

Description of the issue: Output from docker inspect is not valid JSON on Windows and so the parsing fails on following error:

Execution failed for task ':jibDockerBuild'.
> com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: Unexpected character ('s' (code 115)): was expecting double-quote to start field name
   at [Source: (String)"{size:11421955405,imageId:sha256:68204dc2fc12499d321ef43f00c439bbf2300b280d14737a92841d4b22ddd58c,diffIds:["sha256:f358be10862ccbc329638b9e10b3d497dd7cd28b0e8c7931b4a545c88d7f7cd6","sha256:ffce47ae4ffd0b88677730d9949223ae0f4de9c7b14fd7f23112a1724381dac8","sha256:9fb133e2afa1efc256864786d3fe44c896e171aebb52255e44bc5a6e38024ece","sha256:54f1b480fa3dca5845816d23b22bdb748d0fa22217ae9387121683dfe403da5a","sha256:e2e665092bb91d64c1fab2d3e6b5a80f3a52388badd5df17704f57405c81ad03","sha256:f47af1187470c38"[truncated 422 chars]; line: 1, column: 3]

See also this report

The docker inspect is issued when using base Docker image from daemon (instead of from registry), see the docker:// prefix below. It’s possible that docker inspect is used also in different use-cases.

Expected behavior: jib doesn’t fail on invalid JSON parsing, when running on Windows and using base image from Docker daemon.

Steps to reproduce:

  1. Use build.gradle as shown below.
  2. Execute jibDockerBuild.

jib-gradle-plugin Configuration:

jib {
  from {
        image = 'docker://my-image:1.0.0'
  }
}

Log output:

Execution failed for task ':server:jibDockerBuild'.
> com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: Unexpected character ('s' (code 115)): was expecting double-quote to start field name
   at [Source: (String)"{size:513050736,imageId:sha256:6bf020e553c504672ab41c4ee45c008d331aba465ad0f8d99752d75aa830b7c4,diffIds:["sha256:d69483a6face4499acb974449d1303591fcbb5cdce5420f36f8a6607bda11854","sha256:fa546c09dbca96caa9a87ce37518b215364492deeb58dc8f4e5884ed65ae67ad","sha256:fab7516865bc195a22c493e9a7222c8e42ebf21c0d78f443c0d0bd53a0abae84","sha256:8741a416c3f1340e9cd95c049332b5c7dbbee05d8c3cbe52dd67dd48ab760d4f","sha256:7fef8cf5257ba113bf651c0acfec5f5a03ea5c872b1f31f8ca7b968bc6d20f81"]}"; line: 1, column: 3]

Additional Information: The problem is in this method. If I tried to execute the command manually then I really got invalid JSON:

D:\Work>docker inspect -f "{"size":{{.Size}},"imageId":"{{.Id}}","diffIds":{{json .RootFS.Layers}}}" --type image openjdk:11.0.1-windowsservercore-ltsc2016
{size:11421955405,imageId:sha256:68204dc2fc12499d321ef43f00c439bbf2300b280d14737a92841d4b22ddd58c,diffIds:["sha256:f358be10862ccbc329638b9e10b3d497dd7cd28b0e8c7931b4a545c88d7f7cd6","sha256:ffce47ae4ffd0b88677730d9949223ae0f4de9c7b14fd7f23112a1724381dac8","sha256:9fb133e2afa1efc256864786d3fe44c896e171aebb52255e44bc5a6e38024ece","sha256:54f1b480fa3dca5845816d23b22bdb748d0fa22217ae9387121683dfe403da5a","sha256:e2e665092bb91d64c1fab2d3e6b5a80f3a52388badd5df17704f57405c81ad03","sha256:f47af1187470c38d468414f8ff92ac928930386da466c0d6b27bb8f5b37c7442","sha256:a89f3bd646ef45a00237d10e870b50b16d0f203ea970be8f07588e071dd2020d","sha256:3951066b4972f280ccdbaa3fd59ae91e295e1cc38b138a14d7d377e16ee992bd","sha256:cfd212e34afa290dc5c780eb684c56477f21f1803af3341fbef59a38a18048a7","sha256:68d52bc69bc5310bb9d442ac1a828355146e698a72ff3639bb192ba14579eaf4","sha256:8baf500f12aeb8dadde42b0aa8bf444e201001170145952838a1e84c74802bfa"]}

The solution is to use triple-doublequotes to ensure doublequotes are present in the output:

D:\Work>docker inspect -f "{"""size""":{{.Size}},"""imageId""":"""{{.Id}}""","""diffIds""":{{json .RootFS.Layers}}}" --type image openjdk:11.0.1-windowsservercore-ltsc2016
{"size":11421955405,"imageId":"sha256:68204dc2fc12499d321ef43f00c439bbf2300b280d14737a92841d4b22ddd58c","diffIds":["sha256:f358be10862ccbc329638b9e10b3d497dd7cd28b0e8c7931b4a545c88d7f7cd6","sha256:ffce47ae4ffd0b88677730d9949223ae0f4de9c7b14fd7f23112a1724381dac8","sha256:9fb133e2afa1efc256864786d3fe44c896e171aebb52255e44bc5a6e38024ece","sha256:54f1b480fa3dca5845816d23b22bdb748d0fa22217ae9387121683dfe403da5a","sha256:e2e665092bb91d64c1fab2d3e6b5a80f3a52388badd5df17704f57405c81ad03","sha256:f47af1187470c38d468414f8ff92ac928930386da466c0d6b27bb8f5b37c7442","sha256:a89f3bd646ef45a00237d10e870b50b16d0f203ea970be8f07588e071dd2020d","sha256:3951066b4972f280ccdbaa3fd59ae91e295e1cc38b138a14d7d377e16ee992bd","sha256:cfd212e34afa290dc5c780eb684c56477f21f1803af3341fbef59a38a18048a7","sha256:68d52bc69bc5310bb9d442ac1a828355146e698a72ff3639bb192ba14579eaf4","sha256:8baf500f12aeb8dadde42b0aa8bf444e201001170145952838a1e84c74802bfa"]}

So IMHO the solution is to use slightly different command, based on current OS.

I’m willing to prepare a PR for this. It would be great if you suggested me the preferred way how to detect Windows OS.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
augicommented, Feb 12, 2020

@chanseokoh Please see #2288 - this is another issue with Windows Containers. Maybe the fix will be part of #1568

If I can help, just let me know.

1reaction
chanseokohcommented, Feb 12, 2020

@augi it’s easy to build it yourself.

$ git clone https://github.com/GoogleContainerTools/jib.git
$ cd jib
$ ./gradlew :jib-gradle-plugin:install

This will build 2.0.1-SNAPSHOT and install it into your local Maven repo (~/.m2/repository). Then configure your build script at the beginning like

buildscript {
  repositories {
    mavenLocal() // resolve in ~/.m2/repository
    mavenCentral()
  }
  dependencies {
    classpath 'com.google.cloud.tools:jib-gradle-plugin:2.0.1-SNAPSHOT'
  }
}

// instead of using the `plugins` block, use `apply plugin`:
//plugins {
//  id 'com.google.cloud.tools.jib' version '2.0.0'
//}
apply plugin: 'com.google.cloud.tools.jib'
...

Thanks for testing this out! I’m curious too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docker Inspect - Template parsing error for .State.Health.Status
Hey everyone, I've been trying to inspect the health of every docker container that is currently running and I am having some issues...
Read more >
Template parsing error: template: :1: unclosed action
I'm running the commands on Windows 10 and the strings must be enclosed with double quotes. ... docker inspect --format="{{json .
Read more >
Troubleshooting Windows Containers | Microsoft Learn
Troubleshooting tips, automated scripts, and log information for Windows containers and Docker.
Read more >
Use kaniko to build Docker images - GitLab Docs
If you receive this error, it might be due to an outside proxy. Setting the http_proxy and https_proxy environment variables can fix the...
Read more >
Docker CLI Formatting
In this tutorial we will learn about the Docker command line and how to format output. This tutorial is language agnostic, applying to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found