Create a new image using REST API by placing the content in the request body

I am following the “Create an image” REST API for docker mentioned at https://docs.docker.com/reference/api/docker_remote_api_v1.21/#create-an-image .

I want to create an image by placing the content in the request body. The explanation on the link does not specify exactly how the request and request body should look like in this scenario.

  • Get docker version from file
  • How to restart the stopped docker/whalesay container?
  • How to run a full laravel on kubernetes?
  • docker compose backup bitnami redmine volume
  • Docker not working on Windows 10
  • TFS workspace with Jenkins Docker container
  • Does anyone know how should I construct the request URL and body for this REST API?

  • How to monitor for Java Exceptions externally?
  • docker-compose got error when bringing up nodejs application docker container
  • docker --insecure-registry flag not working as expected
  • Use docker-compose env variable in Dockerbuild file
  • Docker - nginx with custom conf
  • Getting Mac address from Docker Container
  • One Solution collect form web for “Create a new image using REST API by placing the content in the request body”

    By tracing the behavior of the docker import command, it is apparent that the /images/create endpoint expects data in the form of a tar archive containing the files to populate the image. I after creating a simple archive containing a single file:

    tar -c -f image.tar README
    

    I was able to upload the image like this:

    curl http://localhost:5555/images/create'?fromSrc=-&repo=larstest&tag=latest' \
      -T image.tar -X POST
    

    The response from docker was:

    HTTP/1.1 200 OK
    Content-Type: application/json
    Date: Wed, 26 Aug 2015 15:10:10 GMT
    Transfer-Encoding: chunked
    
    {"status":"2df6c21713e01af0118bbe2810307c2111e1d0168463affffe5c517d4debb7db"}
    

    You can trace the behavior of the docker client by setting up a logging proxy between the client and the server. I did this:

    socat -v tcp-listen:5555,fork,reuseaddr unix-connect:/var/run/docker.sock
    

    And then ran docker like this:

    DOCKER_HOST=tcp://localhost:5555 docker import - larstest < image.tar
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.