containerFromBuild starts a container from an image pulled from a registry - image specifies the image tag to pull. - cmd specifies the command line in execv format if any. - env specifies the environment variables in the VAR=VALUE format. - ports specifies the port mappings. The key is the contain
( t *testing.T, image string, cmd []string, env []string, ports map[string]string, )
| 75 | // - ports specifies the port mappings. The key is the container port, the value is the host port. |
| 76 | // If the host port is left empty it is automatically mapped and can be retrieved later. |
| 77 | func containerFromPull( |
| 78 | t *testing.T, |
| 79 | image string, |
| 80 | cmd []string, |
| 81 | env []string, |
| 82 | ports map[string]string, |
| 83 | ) container { |
| 84 | t.Helper() |
| 85 | t.Logf("Creating and starting a container from %s...", image) |
| 86 | cnt := &dockerContainer{ |
| 87 | client: dockerClient(t), |
| 88 | image: image, |
| 89 | t: t, |
| 90 | cmd: cmd, |
| 91 | env: env, |
| 92 | ports: ports, |
| 93 | } |
| 94 | |
| 95 | cnt.pull() |
| 96 | cnt.create() |
| 97 | t.Cleanup(cnt.remove) |
| 98 | cnt.start() |
| 99 | cnt.inspect() |
| 100 | |
| 101 | return cnt |
| 102 | } |
| 103 | |
| 104 | type container interface { |
| 105 | // id returns the container ID of the container. |