skip to Main Content

I want to write a script which going to use docker API. It will communicate with the docker engine which runs on the host machine.
I don’t wanna install the entire docker to my image just CLI and later use the host network to communicate with the docker engine.

My script under the hood gonna run commands like docker image inspect someiamge

2

Answers


  1. Chosen as BEST ANSWER

    I thinking about using docker image to extract the CLI client.

    COPY --from=docker:latest /usr/local/bin/docker  /usr/local/bin/
    

    Example of dockerfile

    FROM php:8-cli-alpine
    
    COPY --from=docker:latest /usr/local/bin/docker  /usr/local/bin/
    

    And later you could use this image with following command

    docker run -it --rm --entrypoint docker -v docker run -it --rm --entrypoint docker -v /var/run/docker.sock:/var/run/docker.sock yourimage:tag image ls
    

    This has a significant downside. The docker image does not support linux/arm/v7 architecture.

     => ERROR [linux/arm/v7 internal] load metadata for docker.io/library/docker:latest                                                                                                                        4.5s
     => ERROR [linux/arm/v7 internal] load metadata for docker.io/library/composer:2  
    

    Better to use SDK.


  2. You can use binary distribution of docker, which can be downloaded from here, you can get docker client binaries there.

    Here is the documentation of installation of a docker from binaries. Just skip part of starting docker engine and make sure that your docker client points to a correct remote engine (mounting /var/run/docker.sock)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search