Build image using dockerfile

2019-09-06 13:58发布

问题:

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

回答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


回答2:

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"



标签: curl docker