Today I ran into an issue trying to make custom hooks in Docker Cloud work. I first tried the default post-push hook to add another tag to the built image, straight from the documentation:
#!/bin/bash docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_COMMIT docker push $DOCKER_REPO:$SOURCE_COMMIT
But the logs in Docker Cloud had the following error:
Could not execute hook at 'hooks/post_push'. Is it missing a #! line?
It was not missing that line, and I got the same error whether I used Windows or Unix end-of-line characters.
After a while I remembered an issue I’ve had with Visual Studio at other times which is that it will save files with encoding “UTF-8 with signature”. The “with signature” part is why sometimes other consumers of the file (in this case Docker Cloud) cannot read it correctly.
What “UTF-8 with signature” does is add an invisible sequence of bytes called a BOM (Byte Order Mark) to the beginning of the file.
However, let’s look at this answer in Stack Overflow:
The UTF-8 BOM is a sequence of bytes (EF BB BF) that allows the reader to identify a file as being encoded in UTF-8.
Normally, the BOM is used to signal the endianness of an encoding, but since endianness is irrelevant to UTF-8, the BOM is unnecessary.
According to the Unicode standard, the BOM for UTF-8 files is not recommended:
Even if it was recommended, I was almost certain that the BOM was the culprit of my issue. I needed the file to be saved as “UTF-8 without signature” (without that invisible sequence of bytes at the beginning of the file). The way to do that is to open your file in Visual Studio and go to
File -> Save As. When the dialog comes up, first make sure Visual Studio didn’t add
.* to the end of your filename (it probably does this for files that have no extension), otherwise nothing will happen when you try the next step. Now click on the arrow on the right side of the “Save” button, select “Save with Encoding…” (if you didn’t remove
.* from the end of your filename, nothing will happen here) and set the Encoding option to “Unicode (UTF-8 without signature) – Codepage 65001”.
Save your file, and retry whatever it is you were doing, it should work this time. At least the Docker Cloud build did :).