mirror of https://github.com/docker/docs.git
Fix for tabs on Engine API
This commit is contained in:
parent
ff1f8b34be
commit
1cad0f77c2
|
@ -22,86 +22,86 @@ The API can be accessed with any HTTP client, but we also provide [SDKs](sdks.md
|
||||||
|
|
||||||
As an example, the `docker run` command can be easily implemented in various programming languages and by hitting the API directly with `curl`:
|
As an example, the `docker run` command can be easily implemented in various programming languages and by hitting the API directly with `curl`:
|
||||||
|
|
||||||
<dl class="horizontal tabs" data-tab>
|
<ul class="nav nav-tabs">
|
||||||
<dd class="active"><a href="#tab-python" class="noanchor">Python</a></dd>
|
<li class="active"><a data-toggle="tab" href="#python">Python</a></li>
|
||||||
<dd><a href="#tab-go" class="noanchor">Go</a></dd>
|
<li><a data-toggle="tab" href="#go">Go</a></li>
|
||||||
<dd><a href="#tab-curl" class="noanchor">curl</a></dd>
|
<li><a data-toggle="tab" href="#curl">curl</a></li>
|
||||||
</dl>
|
</ul>
|
||||||
<div class="tabs-content">
|
<div class="tab-content">
|
||||||
<section class="content active" id="tab-python">
|
<div id="python" class="tab-pane fade in active">
|
||||||
{% highlight python %}
|
{% highlight python %}
|
||||||
import docker
|
import docker
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
print client.containers.run("alpine", ["echo", "hello", "world"])
|
print client.containers.run("alpine", ["echo", "hello", "world"])
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
</section>
|
</div>
|
||||||
<section class="content" id="tab-go">
|
<div id="go" class="tab-pane fade">
|
||||||
{% highlight go %}
|
{% highlight go %}
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cli, err := client.NewEnvClient()
|
cli, err := client.NewEnvClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = cli.ImagePull(ctx, "alpine", types.ImagePullOptions{})
|
_, err = cli.ImagePull(ctx, "alpine", types.ImagePullOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.ContainerCreate(ctx, &container.Config{
|
resp, err := cli.ContainerCreate(ctx, &container.Config{
|
||||||
Image: "alpine",
|
Image: "alpine",
|
||||||
Cmd: []string{"echo", "hello world"},
|
Cmd: []string{"echo", "hello world"},
|
||||||
}, nil, nil, "")
|
}, nil, nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
|
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = cli.ContainerWait(ctx, resp.ID); err != nil {
|
if _, err = cli.ContainerWait(ctx, resp.ID); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := cli.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true})
|
out, err := cli.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
io.Copy(os.Stdout, out)
|
io.Copy(os.Stdout, out)
|
||||||
}
|
}
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
</section>
|
</div>
|
||||||
<section class="content" id="tab-curl">
|
<div id="curl" class="tab-pane fade">
|
||||||
{% highlight bash %}
|
{% highlight bash %}
|
||||||
$ curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" \
|
$ curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" \
|
||||||
-d '{"Image": "alpine", "Cmd": ["echo", "hello world"]}' \
|
-d '{"Image": "alpine", "Cmd": ["echo", "hello world"]}' \
|
||||||
-X POST http:/v1.24/containers/create
|
-X POST http:/v1.24/containers/create
|
||||||
{"Id":"1c6594faf5","Warnings":null}
|
{"Id":"1c6594faf5","Warnings":null}
|
||||||
|
|
||||||
$ curl --unix-socket /var/run/docker.sock -X POST http:/v1.24/containers/1c6594faf5/start
|
$ curl --unix-socket /var/run/docker.sock -X POST http:/v1.24/containers/1c6594faf5/start
|
||||||
|
|
||||||
$ curl --unix-socket /var/run/docker.sock -X POST http:/v1.24/containers/1c6594faf5/wait
|
$ curl --unix-socket /var/run/docker.sock -X POST http:/v1.24/containers/1c6594faf5/wait
|
||||||
{"StatusCode":0}
|
{"StatusCode":0}
|
||||||
|
|
||||||
$ curl --unix-socket /var/run/docker.sock "http:/v1.24/containers/1c6594faf5/logs?stdout=1"
|
$ curl --unix-socket /var/run/docker.sock "http:/v1.24/containers/1c6594faf5/logs?stdout=1"
|
||||||
hello world
|
hello world
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
</section>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
To learn more, take a look at the [getting started guide](getting-started.md)
|
To learn more, take a look at the [getting started guide](getting-started.md)
|
||||||
|
|
Loading…
Reference in New Issue