通过上一节的学习,我们知道怎样执行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. 粗略整理的java面试题

    1.垃圾回收  是回收的空闲堆空间 只有在cpu空闲并且堆空间不足的情况下才回收 2.threadlocal  就是为线程的变量都提供了一个副本,每个线程运行都只是在更新这个副本. Threadloc ...

  2. redis数据库安装及简单的增删改查

    redis下载地址:https://github.com/MSOpenTech/redis/releases. 解压之后,运行 redis-server.exe redis.windows.conf  ...

  3. JavaScript系列----面向对象的JavaScript(1)

    1.面向对象的编程 1.1.什么是面向对象编程 面向对象编程:即是把能够完成独立完成一部分功能的代码封装在一起,组成一个类. 举个例子来说: 这里有一把枪, 枪的种类很多,有步枪,机关枪,阻击枪... ...

  4. Scrum Meeting Alpha - 7

    Scrum Meeting Alpha - 7 NewTeam 2017/11/1 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 登录部分的API仍存在问题 完成登陆部分的AP ...

  5. 项目实战1—LNMP的搭建、nginx反向代理和缓存等的实现

    实战一:搭建lnmp及类小米等商业网站的实现 环境:关闭防火墙,selinux 1.安装包,开启服务 yum -y install nginx mariadb-server php-fpm php-m ...

  6. 通过hibernate封装数据库持久化过程回顾泛型/继承/实现等概念

    前言 在开发过程中,我们不难发现,客户的需求以及产品的定位对开发内容的走向有很大的决策作用,而这些往往需要在一开始就尽可能考虑周全和设计完善.为什么说是尽可能,因为我们都知道,需求这种东西,一言难尽. ...

  7. Spring JDBC 示例

    在使用普通的 JDBC 数据库时,就会很麻烦的写不必要的代码来处理异常,打开和关闭数据库连接等.但 Spring JDBC 框架负责所有的低层细节,从开始打开连接,准备和执行 SQL 语句,处理异常, ...

  8. php中向前台js中传送一个二维数组

    在php中向前台js中传送一个二维数组,并在前台js接收获取其中值的全过程方法: (1),方法说明:现在后台将数组发送到前台 echo json_encode($result); 然后再在js页面中的 ...

  9. 《Linux命令行与shell脚本编程大全》第十三章 更多的结构化命令

    本章讨论bash shell的循环命令for.while和until 13.1 for命令 重复执行一系列命令在编程中很常见. bash shell提供了for命令,允许你创建一个遍历一系列值的循环. ...

  10. 《java.util.concurrent 包源码阅读》15 线程池系列之ScheduledThreadPoolExecutor 第二部分

    这篇文章主要说说DelayedWorkQueue. 在ScheduledThreadPoolExecutor使用DelayedWorkQueue来存放要执行的任务,因为这些任务是带有延迟的,而每次执行 ...