设为首页 收藏本站
查看: 1247|回复: 0

[经验分享] 阿里云部署Docker(4)----容器的使用

[复制链接]

尚未签到

发表于 2015-10-13 08:28:28 | 显示全部楼层 |阅读模式
  通过上一节的学习,我们知道如何运行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。表示将本机的49153端口映射到compassionate_toralds容器的5000端口。  
  我用浏览器试一下。-d选项,我们已经讲过,是将程序后台化;-P,大写的P,是让docker来指定一个端口映射。这里是49153,你可以通过-p小写的来指定这种映射关系。
  如下效果:
DSC0000.jpg
  好,可以访问。哈哈。
  

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

好,再访问一下。  
DSC0001.jpg




  


  



版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-126041-1-1.html 上篇帖子: 如何在Docker中安装DzzOffice 下篇帖子: 使用VS把ASP.NET 5的应用发布到Linux的Docker上
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表