`docker run` on a remote host

前端 未结 4 1816
自闭症患者
自闭症患者 2020-12-30 01:30

is it possible (using the docker command or the docker-py API directly) to start a container from a remote host?

Lets assume I have two mac

4条回答
  •  生来不讨喜
    2020-12-30 02:29

    This article explains the concept very well: https://docs.docker.com/engine/reference/commandline/dockerd/#bind-docker-to-another-hostport-or-a-unix-socket

    Considering the huge warning on the page, I suggest you resort to using a secure connection via SSH ie. ssh user@host 'docker run hello-from-B'

    Warning: Changing the default docker daemon binding to a TCP port or Unix docker user group will increase your security risks by allowing non-root users to gain root access on the host. Make sure you control access to docker. If you are binding to a TCP port, anyone with access to that port has full Docker access; so it is not advisable on an open network.


    With -H it is possible to make the Docker daemon to listen on a specific IP and port. By default, it will listen on unix:///var/run/docker.sock to allow only local connections by the root user. You could set it to 0.0.0.0:2375 or a specific host IP to give access to everybody, but that is not recommended because then it is trivial for someone to gain root access to the host where the daemon is running.

    Similarly, the Docker client can use -H to connect to a custom port. The Docker client will default to connecting to unix:///var/run/docker.sock on Linux, and tcp://127.0.0.1:2376 on Windows.

    -H accepts host and port assignment in the following format:

    tcp://[host]:[port][path] or unix://path


    You can use multiple -H, for example, if you want to listen on both TCP and a Unix socket

    # Run docker in daemon mode
    $ sudo /dockerd -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock &
    # Download an ubuntu image, use default Unix socket
    $ docker pull ubuntu
    # OR use the TCP port
    $ docker -H tcp://127.0.0.1:2375 pull ubuntu
    

提交回复
热议问题