0

Has anyone ever successfully build an image using following command?

curl -v -X POST \
-H "Content-Type:application/tar" \
http://52.212.221.156:2375/build?t=samplerepo&dockerfile="C:\Dockerfile.tar.gz"

Even though file is on specified location, I'm getting following error

{"message":"Cannot locate specified Dockerfile: Dockerfile"}

Or if at all anyone has done it using remote parameter, please help

Abhaya Ghatkar
  • 322
  • 1
  • 5
  • 22

2 Answers2

1

The query parameter dockerfile shall point to the Dockerfile within the build context i.e, with in the tar archive that you are posting along with request.

Assume the below structure in the archive

    payload.tar.gz
    -- config
       -- Dockerfile
    -- src
    -- temp

Then your query parameter "dockerfile" shall hold config/Dockerfile.

Ensure you are sending tar payload along with the request.

Following command creates an image on the local environment via Docker Remote API

curl -v POST -H "Content-Type: application/tar" --data-binary @Dockerfile.tar.gz --unix-socket /var/run/docker.sock http:/build?t=sample
YYY
  • 6,107
  • 1
  • 12
  • 14
  • In *Usage: docker build [OPTIONS] PATH*, PATH refers to the build context. When we use *docker build -t .*, current directory is the build context. In case of Remote API, we are sending that build context as a tar archive as it is run remotely. So, your docker file has to be at root of that archive and that tar archive needs to be sent as part of that request. In case if Dockerfile is not at root of the archive and placed under a directory in the archive, then it can be specified via the query parameter "dockerfile". – YYY Dec 06 '16 at 14:17
  • ok, so this the curl command I have tried `curl -v -X POST -H "Content-Type:applictaion/tar" http://52.210.66.125:2375/build?t=samplerepo&dockerfile="C:/payload.tar"` And the folder structure is `payload>Dockerfile`. Still not able to make it work. – Abhaya Ghatkar Dec 06 '16 at 14:55
  • `curl -v POST -H "Content-Type: application/tar" --data-binary @archive.tar.gz http://52.210.66.125:2375/build?t=samplerepo` – YYY Dec 06 '16 at 15:25
  • I'am aware of this curl command, and cannot use this parameter `--data-binary` in my case. – Abhaya Ghatkar Dec 07 '16 at 05:32
  • if at all we pass `config/Dockerfile` in dockerfile parameter , how to pass the payload tar file in the post request. – Abhaya Ghatkar Dec 23 '16 at 11:28
1

Firstly, refer Docker API documentation and go through all the query parameters https://docs.docker.com/engine/api/v1.25/#operation/ImageBuild.

There are three way to build an image using dockerfile

  1. Using a remote url, which has your dockerfile in tar format

    curl -X POST "http://localhost:5000/build?remote=https://raw.githubusercontent.com/abha10/FirstGitProj/master/Dockerfile.tar"

  2. Using remote url as well as dockerfile context path

    curl -X POST "http://localhost:5000/build?dockerfile=Tomcat/config/Dockerfile&remote=https://raw.githubusercontent.com/abha10/FirstGitProj/master/Tomcat.tar"

  3. Following is not available in their official document but works fine, if in case you have your dockerfile present locally.

    curl -X POST -H "Content-Type:application/tar" --data-binary '@Dockerfile.tar.gz' "http://localhost:5000/build?tag=tomcat"

Abhaya Ghatkar
  • 322
  • 1
  • 5
  • 22