MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / create

Method create

internal/test/docker.go:190–231  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

188}
189
190func (d *dockerContainer) create() {
191 d.t.Helper()
192 d.t.Logf("Creating container from %s...", d.image)
193 hostConfig := &containertypes.HostConfig{
194 AutoRemove: true,
195 PortBindings: map[nat.Port][]nat.PortBinding{},
196 }
197 for containerPort, hostPort := range d.ports {
198 portString := nat.Port(containerPort)
199 if hostPort == "" {
200 hostConfig.PortBindings[portString] = []nat.PortBinding{
201 {
202 HostIP: "127.0.0.1",
203 },
204 }
205 } else {
206 hostConfig.PortBindings[portString] = []nat.PortBinding{
207 {
208 HostIP: "127.0.0.1",
209 HostPort: hostPort,
210 },
211 }
212 }
213 }
214 resp, err := d.client.ContainerCreate(
215 context.Background(),
216 &containertypes.Config{
217 Image: d.image,
218 Cmd: d.cmd,
219 Env: d.env,
220 },
221 hostConfig,
222 nil,
223 nil,
224 "",
225 )
226 if err != nil {
227 d.t.Fatalf("failed to create %s container (%v)", d.image, err)
228 }
229 d.containerID = resp.ID
230 d.t.Logf("Container has ID %s...", d.containerID)
231}
232
233func (d *dockerContainer) start() {
234 d.t.Helper()

Callers 2

containerFromBuildFunction · 0.95
containerFromPullFunction · 0.95

Calls 3

FatalfMethod · 0.80
LogfMethod · 0.65
PortMethod · 0.65

Tested by

no test coverage detected