通过上一节的学习,我们知道怎样执行docker容器,我们执行了一个普通的,一个后台的,我们还学习了几个指令:

docker ps - Lists containers.
docker logs - Shows us the standard output of a container.
docker stop - Stops running containers.

我们还能够查看下docker的版本号:

root@iZ28ikebrg6Z:~# docker version
Client version: 1.2.0
Client API version: 1.14
Go version (client): go1.3.1
Git commit (client): fa7b24f
OS/Arch (client): linux/amd64
Server version: 1.2.0
Server API version: 1.14
Go version (server): go1.3.1
Git commit (server): fa7b24f
root@iZ28ikebrg6Z:~#

docker是基于google公司的Go语言的。

假设不知道docker怎么用,或者忘记了的时候,直接输入docker。会给出使用方法提示

root@iZ28ikebrg6Z:~# docker
Usage: docker [OPTIONS] COMMAND [arg...]
-H=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use A self-sufficient runtime for linux containers. Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders from a container's filesystem to the host path
diff Inspect changes on a container's filesystem
events Get real time events from the server
export Stream the contents of a container as a tar archive
history Show the history of an image
images List images
import Create a new filesystem image from the contents of a tarball
info Display system-wide information
inspect Return low-level information on a container
kill Kill a running container
load Load an image from a tar archive
login Register or log in to a Docker registry server
logout Log out from a Docker registry server
logs Fetch the logs of a container
port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
pause Pause all processes within a container
ps List containers
pull Pull an image or a repository from a Docker registry server
push Push an image or a repository to a Docker registry server
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save an image to a tar archive
search Search for an image on the Docker Hub
start Start a stopped container
stop Stop a running container
tag Tag an image into a repository
top Lookup the running processes of a container
unpause Unpause a paused container
version Show the Docker version information
wait Block until a container stops, then print its exit code root@iZ28ikebrg6Z:~#

docker后面跟指令,

root@iZ28ikebrg6Z:~# docker attach

Usage: docker attach [OPTIONS] CONTAINER

Attach to a running container

  --no-stdin=false    Do not attach STDIN
--sig-proxy=true Proxy all received signals to the process (even in non-TTY mode). SIGCHLD, SIGKILL, and SIGSTOP are not proxied.
root@iZ28ikebrg6Z:~#

假设输入非法,总是会给出提示,告诉你怎么用。

Running a Web Application in Docker

利用Docker构建一个web程序

我们运行一个web应用。

root@iZ28ikebrg6Z:~# docker run -d -P training/weapp python app.py
Unable to find image 'training/weapp' locally
Pulling repository training/weapp
2014/10/16 11:01:56 Error: image training/weapp not found
root@iZ28ikebrg6Z:~# docker run -d -P training/webapp python app.py
Unable to find image 'training/webapp' locally
Pulling repository training/webapp
31fa814ba25a: Pulling dependent layers
511136ea3c5a: Download complete
f10ebce2c0e1: Download complete
82cdea7ab5b5: Download complete
5dbd9cb5a02f: Download complete
31fa814ba25a: Download complete
64523f641a05: Download complete
0e2afc9aad6e: Download complete
e8fc7643ceb1: Download complete
733b0e3dbcee: Download complete
a1feb043c441: Download complete
e12923494f6a: Download complete
a15f98c46748: Download complete
09792841c0b448a330a89ee656b4a16605d835f9d43bb7d6f80f204b6e8ed5b2
root@iZ28ikebrg6Z:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09792841c0b4 training/webapp:latest "python app.py" 54 minutes ago Up 54 minutes 0.0.0.0:49153->5000/tcp compassionate_torvalds
root@iZ28ikebrg6Z:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09792841c0b4 training/webapp:latest "python app.py" 56 minutes ago Up 56 minutes 0.0.0.0:49153->5000/tcp compassionate_torvalds
root@iZ28ikebrg6Z:~#

第一次敲错了。第二次它会去docker库下载,下载完了,ps查看一下。多了一行Ports。

表示将本机的49153port映射到compassionate_toralds容器的5000port。

我用浏览器试一下。-d选项。我们已经讲过,是将程序后台化。-P,大写的P,是让docker来指定一个port映射。

这里是49153,你能够通过-p小写的来指定这样的映射关系。

例如以下效果:

好,能够訪问。

哈哈。

root@iZ28ikebrg6Z:~# docker run -d -p 5000:5000 training/webapp python app.py
aa47ba8e71c8512f228a96bf80da117b6c86fc03bdb17eef1c2db353a3e18493

好。再訪问一下。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTWluaU1pY2FsbA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

阿里云部署Docker(4)----容器的使用的更多相关文章

  1. 阿里云部署Docker(5)----管理和公布您的镜像

    出到这节,我在百度搜索了一下"阿里云部署Docker",突然发现怎么会有人跟我写的一样呢?哦,原来是其它博客系统的爬虫来抓取,然后也不会写转载自什么什么的.所以,我最终明确为什么那 ...

  2. 阿里云部署Docker(7)----将容器连接起来

    路遥知马力.日久见人心.恩. 该坚持的还是要坚持. 今天看到一个迅雷的师弟去了阿里,祝福他,哎,尽管老是被人家捧着叫大牛.我说不定通过不了人家的面试呢.哎,心有惭愧. 本文为本人原创,转载请表明来源: ...

  3. 阿里云部署Docker(2)

    之前有一篇文章讲过在阿里云中安装Docker,相对来说那个是安装.可是安装完之后我们通常会碰到问题. 今天我给大家记录一下我的新的解决过程. 环境还是ubuntu12.04.如果我们已经把内核升级到了 ...

  4. 阿里云部署Docker(3)----指令学习

    通过上两节的学习http://blog.csdn.net/minimicall/article/details/40119177 和http://blog.csdn.net/minimicall/ar ...

  5. 阿里云部署Docker(8)----安装和使用redmine

    安装redmine对过程进行管理. 须要说明的是:当你在docker images的时候,会说没连接到xxxx的时候,并且会提示用"docker -d".事实上这仅仅是把docke ...

  6. 阿里云部署Docker(6)----解决删除<none>镜像问题

    转载请注明来源,本博客原创作者为:http://blog.csdn.net/minimicall?viewmode=contents 在Docker使用中,常常会碰到删除镜像不成功.反而让镜像变成了& ...

  7. 阿里云部署Docker(9)----Dockerfile脚本定制镜像

    本文为原创文章.转载需注明转自:http://blog.csdn.net/minimicall? viewmode=contents 技术爱好者都是比較懒的.而docker又是开发人员支持起来的.所以 ...

  8. 阿里云服务器安装Docker并部署nginx、jdk、redis、mysql

    阿里云服务器安装Docker并部署nginx.jdk.redis.mysql 一.安装Docker 1.安装Docker的依赖库 yum install -y yum-utils device-map ...

  9. 阿里云-部署-服务-Docker

    目录 ♫ MusicPlayer Naiveboom - 比较安全 个人阿里云部署的小服务,欢迎使用,服务器资源有限,如果遇到卡顿还请谅解~ 索引: 在线音乐播放器 阅后即焚 ♫ MusicPlaye ...

随机推荐

  1. NHibernate Criteria中 Restriction与Expression的差别

    http://stackoverflow.com/questions/5483393/nhibernate-criteria-restriction-vs-expression 据说是Restrict ...

  2. 解决Cordova安装Cannot find module 'bplist-parser'问题

    安装完cordova出现找不到必须的模块 出现原因不明,不过如果出现这个问题,我们遇到缺什么模块就安装什么模块就可以了.如图所示

  3. 无状态的web应用(单个py文件的Django占位图片服务器)

    本文为作者原创,转载请注明出处(http://www.cnblogs.com/mar-q/)by 负赑屃 阅读本文建议了解Django框架的基本工作流程,了解WSGI应用,如果对以上不是很清楚,建议结 ...

  4. [原创]阿里云RocketMQ踩过的哪些坑

    由于公司的最近开始使用RocketMQ来做支付业务处理, 便开启了学习阿里云RocketMQ的学习与实践之路, 其中踩了不少的坑, 大部份是由于没有仔细查看阿里云的技术文档而踩的坑. 但是有一个非常大 ...

  5. python基础-------函数(三)

    迭代器 一.迭代的概念 迭代:1 重复2 下一次重复是基于上一次的结果 l=['a','b','c','d'] count=0while count < len(l): print(l[coun ...

  6. prometheus client_golang使用

    序言 Prometheus是一个开源的监控系统,拥有许多Advanced Feature,他会定期用HTTP协议来pull所监控系统状态进行数据收集,在加上timestamp等数据组织成time se ...

  7. C#表达式目录树(Expression)

    1.什么是表达式目录树 :简单的说是一种语法树,或者说是一种数据结构(Expression) 2.用Lambda声明表达式目录树: Expression<Func<; //表达试目录树的方 ...

  8. mybatis逆向工程之生成文件解释

    一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...

  9. jmockit学习总结

    mock类型和实例 从依赖的测试代码调用的方法和构造函数是mock(模拟)的目标. Mocking提供了我们需要的机制,以便将被测试的代码与(一些)依赖关系隔离开来.我们通过声明适当的模拟字段和/或模 ...

  10. JAVA面试之集合框架(三)

    21.ArrayList和Vector的区别 这两个类都实现了List接口(List接口继承了Collection接口),他们都是有序集合,即存储在这两个集合中的元素的位置都是有顺序的,相当于一种动态 ...