Can I build a Docker container from the CLI against a remote daemon?
Asked Answered
C

3

7

Currently I've the following setup:

  • An Hyper-V VM running Windows 10 on which is my dev machine. My CPU doesn't support nested virtualization.
  • Docker for Windows is installed on the host machine which runs Windows 10 too.

Is it possible to run docker build from the VM against Docker on the host machine?

Cangue answered 26/5, 2017 at 12:27 Comment(6)
Yes, just use PowerShell from the guest to run docker build on the host.Moonrise
@ΔλЛ So I need to enable remote Powershell commands from the host, right?Headward
Either that or just open a PowerShell session from guest to host.Moonrise
@ΔλЛ Ok I could configure my host to accept remote PowerShell sessions. So... now I understand that I should copy the sources to the remote host via the remote PowerShell session and then run docker build .?Headward
You didn't mention having sources on the guest but if that's the case then yes, copy them and run docker build using PowerShell.Moonrise
@ΔλЛ Well, sources should be in the VM as it's the dev machine :DHeadward
B
4

Yes, you can. According to the documentation, there is 3 ways to do this,

# with Git repo
docker -H xxx build https://github.com/docker/rootfs.git#container:docker

# Tarball contexts
docker -H xxx build http://server/context.tar.gz

Text files
docker -H xxx build - < Dockerfile

When doing this, you need to make sure that,

  1. your client have docker installed.
  2. all the dependent files are accessible by the host.

At the end, the docker image will be created in your host.


Update

the docker options is documented here now.

Brockway answered 26/5, 2017 at 15:36 Comment(4)
The questions is about build on a remote docker daemon, not about building locally remote files.Giltzow
hi @motobói, please read carefully. it is docker with argument -H xxx, specifying the remote host. using remote files is one of the easiest way to make sure remote host has access to all depending files.Brockway
The documentation you linked does not mention an -H option now. Has it been removed/renamed?Bohaty
You should consider highlighting the -H option, it is not that obvious for someone who doesn't know the docker cliInveigh
H
2
export DOCKER_HOST=ssh://sammy@your_server_ip

then you can run docker build on your host machine

reference

Houppelande answered 14/6, 2022 at 7:58 Comment(0)
I
0

There is (from my understanding) 3 different way of building a docker using a remote docker host / daemon:

  1. Using the DOCKER_HOST variable
  2. Using contexts
  3. Using -H cli option

as in :

  1. DOCKER_HOST="ssh://[email protected]" docker build -t toto .
  2. docker use context remote-build-host && docker build -t toto .
  3. docker -H ssh://[email protected]:22 build -t toto .

Please note the port is required in the last form (-H)

See this page and this one too for more info.

Inveigh answered 6/2, 2023 at 21:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.