Docker Engine SDKs and API 的开发2

 

Examples using the Docker Engine SDKs and Docker API

 

After you install Docker, you can install the Go and Python SDKs and also try out the Docker Engine API.

Each of these examples show how to perform a given Docker operation using the Go and Python SDKs and the HTTP API using curl.

 

Run a container

This first example shows how to run a container using the Docker API. On the command line, you would use the docker run command, but this is just as easy to do from your own apps too.

This is the equivalent of typing docker run alpine echo hello world at the command prompt:

 

 

Run a container in the background

You can also run containers in the background, the equivalent of typing docker run -d bfirsh/reticulate-splines:

 

 

List and manage containers

You can use the API to list containers that are running, just like using docker ps:

 

 

Stop all running containers

Now that you know what containers exist, you can perform operations on them. This example stops all running containers.

Note: Don’t run this on a production server.

Also, if you are using swarm services, the containers stop, but Docker creates new ones to keep the service running in its configured state.

 

 

You can also perform actions on individual containers. This example prints the logs of a container given its ID. You need to modify the code before running it to change the hard-coded ID of the container to print the logs for.

 

 

List all images

List the images on your Engine, similar to docker image ls:

 

 

Pull an image

Pull an image, like docker pull:

 

 

Pull an image with authentication

Pull an image, like docker pull, with authentication:

Note: Credentials are sent in the clear.

Docker’s official registries use HTTPS.

Private registries should also be configured to use HTTPS.

 

 

 

Commit a container

Commit a container to create an image from its contents:

转载于:https://www.cnblogs.com/panpanwelcome/p/9295507.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值