Fix for tabs on Engine API

This commit is contained in:
John Mulhausen 2017-03-17 13:56:14 -07:00
parent ff1f8b34be
commit 1cad0f77c2
1 changed files with 68 additions and 68 deletions

View File

@ -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`:
<dl class="horizontal tabs" data-tab>
<dd class="active"><a href="#tab-python" class="noanchor">Python</a></dd>
<dd><a href="#tab-go" class="noanchor">Go</a></dd>
<dd><a href="#tab-curl" class="noanchor">curl</a></dd>
</dl>
<div class="tabs-content">
<section class="content active" id="tab-python">
{% highlight python %}
import docker
client = docker.from_env()
print client.containers.run("alpine", ["echo", "hello", "world"])
{% endhighlight %}
</section>
<section class="content" id="tab-go">
{% highlight go %}
package main
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#python">Python</a></li>
<li><a data-toggle="tab" href="#go">Go</a></li>
<li><a data-toggle="tab" href="#curl">curl</a></li>
</ul>
<div class="tab-content">
<div id="python" class="tab-pane fade in active">
{% highlight python %}
import docker
client = docker.from_env()
print client.containers.run("alpine", ["echo", "hello", "world"])
{% endhighlight %}
</div>
<div id="go" class="tab-pane fade">
{% highlight go %}
package main
import (
"io"
"os"
import (
"io"
"os"
"github.com/docker/docker/client"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"golang.org/x/net/context"
)
"github.com/docker/docker/client"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"golang.org/x/net/context"
)
func main() {
ctx := context.Background()
cli, err := client.NewEnvClient()
if err != nil {
panic(err)
}
func main() {
ctx := context.Background()
cli, err := client.NewEnvClient()
if err != nil {
panic(err)
}
_, err = cli.ImagePull(ctx, "alpine", types.ImagePullOptions{})
if err != nil {
panic(err)
}
_, err = cli.ImagePull(ctx, "alpine", types.ImagePullOptions{})
if err != nil {
panic(err)
}
resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: "alpine",
Cmd: []string{"echo", "hello world"},
}, nil, nil, "")
if err != nil {
panic(err)
}
resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: "alpine",
Cmd: []string{"echo", "hello world"},
}, nil, nil, "")
if err != nil {
panic(err)
}
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
panic(err)
}
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
panic(err)
}
if _, err = cli.ContainerWait(ctx, resp.ID); err != nil {
panic(err)
}
if _, err = cli.ContainerWait(ctx, resp.ID); err != nil {
panic(err)
}
out, err := cli.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true})
if err != nil {
panic(err)
}
out, err := cli.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true})
if err != nil {
panic(err)
}
io.Copy(os.Stdout, out)
}
{% endhighlight %}
</section>
<section class="content" id="tab-curl">
{% highlight bash %}
$ curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" \
-d '{"Image": "alpine", "Cmd": ["echo", "hello world"]}' \
-X POST http:/v1.24/containers/create
{"Id":"1c6594faf5","Warnings":null}
io.Copy(os.Stdout, out)
}
{% endhighlight %}
</div>
<div id="curl" class="tab-pane fade">
{% highlight bash %}
$ curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" \
-d '{"Image": "alpine", "Cmd": ["echo", "hello world"]}' \
-X POST http:/v1.24/containers/create
{"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
{"StatusCode":0}
$ curl --unix-socket /var/run/docker.sock -X POST http:/v1.24/containers/1c6594faf5/wait
{"StatusCode":0}
$ curl --unix-socket /var/run/docker.sock "http:/v1.24/containers/1c6594faf5/logs?stdout=1"
hello world
{% endhighlight %}
</section>
$ curl --unix-socket /var/run/docker.sock "http:/v1.24/containers/1c6594faf5/logs?stdout=1"
hello world
{% endhighlight %}
</div>
</div>
To learn more, take a look at the [getting started guide](getting-started.md)