diff --git a/engine/api/index.md b/engine/api/index.md index e4112b85a6..5b5154dc56 100644 --- a/engine/api/index.md +++ b/engine/api/index.md @@ -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`: -
-
Python
-
Go
-
curl
-
-
-
-{% highlight python %} -import docker -client = docker.from_env() -print client.containers.run("alpine", ["echo", "hello", "world"]) -{% endhighlight %} -
-
-{% highlight go %} -package main + +
+
+ {% highlight python %} + import docker + client = docker.from_env() + print client.containers.run("alpine", ["echo", "hello", "world"]) + {% endhighlight %} +
+
+ {% 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 %} -
-
-{% 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 %} +
+
+ {% 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 %} - + $ curl --unix-socket /var/run/docker.sock "http:/v1.24/containers/1c6594faf5/logs?stdout=1" + hello world + {% endhighlight %} +
To learn more, take a look at the [getting started guide](getting-started.md)