skip to Main Content

There is NET CORE wrapper around docker (https://github.com/dotnet/Docker.DotNet)
It use strange abstraction to connection to docker

 var client = new DockerClientConfiguration(new Uri("http://ubuntu-docker.cloudapp.net:4243")).CreateClient();

My docker is accessible from remote machine as

sudo curl --unix-socket /var/run/docker.sock http://157.XX.XX.84/v1.41/containers/json

What connection string I need to use with Docker.DotNet library and how to create needed authentication?

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    My question was about how exactly connect to remote socket and how to use basic AU to connect to remote socket. Documentation said nothing about this. So, this is my finally solution.

    Remote socket is simple port 80. And without any AU. Therefore firstly I have created proxy server to protect remote socket by login-password. This is nginx config (in proxy mode).

    upstream docker {
      server unix:/var/run/docker.sock;
    }
    server {
      listen 4444 default_server;
      location / {
         proxy_pass http://docker;
        auth_basic_user_file /etc/nginx/.htpasswd;
        auth_basic "Access restricted";
      }
    }
    

    Connection to remote docker is possible by this way

        Dim PassStr = ReadPassword()
        Dim Credential = New BasicAuthCredentials(My.Resources.Login, PassStr)
        Dim DockerHub = New DockerClientConfiguration(New Uri(My.Resources.Url), Credential).CreateClient()
    

    Docker.DotNet is not a high quality package and directly it not working (not only in my computer, I see a lot of issues from other programmers), so directly BasicAuthCredentials don't working. I assembly my program from source code of this package - NET CORE 5. How to fix "The located assembly's manifest definition does not match the assembly reference"?

    And finally my program working fine. This is test of control docker by remote socket through proxy server with basic AU.

    enter image description here


  2. Docker Engine API

    Docker provides an API for interacting with the Docker daemon , called the Docker Engine API which is a classic http rest api, with a lot of endpoints ready to use to for example: create container, images, start, delete, etc, This feature is used for all the docker clients in the world.

    How to enable the Docker Engine http API

    Basically the steps are: modify some docker internal configuration and restart the daemon. If you do that in a host 10.10.10.10 (remote docker host) you can invoke the api from any other host in the same network or with the respective permissions with something like this:

    curl http://10.10.10.10:2375/images/json
    

    2375 is just for development. The optimum and secure is to configure the 4243 port

    Sources:

    .NET Client for Docker Remote API

    This client as any other docker clients needs the docker http api url(as the most easy way), explained in the previous section

    DockerClient client = new DockerClientConfiguration(
        new Uri("http://ubuntu-docker.cloudapp.net:4243"))
         .CreateClient();
    

    Also in the readme show that is possible to connect it using sockets intead http:

    DockerClient client = new DockerClientConfiguration(
        new Uri("unix:///var/run/docker.sock"))
         .CreateClient();
    

    I don’t find if it allow us to use the insecure port 2375. SO you will have to enable the 4243 port on your remote docker host.

    Anyway if you need a quickly test, you coul try with the 2375 port. Some issues show that port, so its possible that is allowed.

    Advice

    • Choose if you will use socket or http for remote docker api
    • configure it
    • test it with some tool like curl or postman
    • if it works, use properly the .NET Client
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search