阿里云部署Docker(4)----容器的使用

本文涉及的产品
容器镜像服务 ACR,镜像仓库100个 不限时长
简介:

通过上一节的学习,我们知道如何运行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小写的来指定这种映射关系。

如下效果:

好,可以访问。哈哈。

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

好,再访问一下。





相关文章
|
5天前
|
存储 运维 监控
构建高效稳定的Docker容器监控体系
【4月更文挑战第18天】 在现代微服务架构中,Docker容器已成为部署和运行应用的标准环境。随之而来的挑战是如何有效监控这些容器的性能与健康状况,确保系统的稳定性和可靠性。本文将探讨构建一个高效稳定的Docker容器监控体系的关键技术和方法,包括日志管理、性能指标收集以及异常检测机制,旨在为运维人员提供实用的指导和建议。
10 0
|
5天前
|
Java 应用服务中间件 Linux
在阿里云服务器上部署Tomcat详细图文详解
本文介绍了在阿里云服务器上安装和配置JDK和Tomcat的步骤。首先,需要注册阿里云账号并进行实名认证,然后购买并设置服务器。接着,通过File Zilla连接服务器,创建Java和Tomcat的安装目录,并将JDK和Tomcat的tar.gz文件上传到服务器,解压并重命名。之后,配置JDK的环境变量,将catalina.sh复制到/etc/init.d/目录下,并修改相关配置。最后,启动Tomcat并配置安全组规则,确保可以通过公网访问。
|
5天前
|
弹性计算 Java Linux
阿里云服务器搭建部署宝塔详细流程
该内容是一个阿里云服务器和域名的配置指南。首先,需注册阿里云账号并进行企业实名认证。接着,选购服务器如2核2G1兆的Linux系统,并购买域名。完成域名备案后,进行域名解析和ICP备案。然后,通过远程连接登录服务器,重置密码,安装宝塔面板。在安全组中开启宝塔面板随机生成的端口。最后,登录宝塔面板安装LNMP环境,配置数据库如MySQL和Redis,部署JDK、Tomcat,上传前端和后端项目以实现上线。
|
6天前
|
弹性计算 JavaScript Java
阿里云服务器搭建部署宝塔详细流程
以下是内容的摘要: 本文主要介绍了在阿里云上创建和配置服务器环境的步骤,包括注册阿里云账号、实名认证、购买和设置服务器、域名的获取与备案、以及使用宝塔面板安装和配置环境。首先,用户需要注册阿里云账号并进行实名认证,选择合适的服务器配置。接着,购买服务器后,要准备并备案域名,以便通过友好的网址访问网站。在服务器上安装宝塔面板,可以方便地管理和配置LAMP/LNMP/Tomcat/Node.js等应用环境。完成这些步骤后,用户还需要在宝塔面板中安装MySQL、Redis等数据库,部署Java或Vue项目,并配置相关端口。最后,将前端项目打包上传至服务器,并设置站点,即可实现网站的上线。
|
6天前
|
应用服务中间件 Linux 开发工具
如何在阿里云服务器快速搭建部署Nginx环境
以下是内容的摘要: 本文档主要介绍了在阿里云上购买和配置服务器的步骤,包括注册阿里云账号、实名认证、选择和购买云服务器、配置安全组、使用Xshell和Xftp进行远程连接和文件传输,以及安装和配置Nginx服务器的过程。在完成这些步骤后,你将能够在服务器上部署和运行自己的网站或应用。
|
8天前
|
NoSQL 关系型数据库 MySQL
阿里云服务器部署项目流程
本文主要讲解阿里云服务器的部署,如何选择配置等
|
11天前
|
Java 应用服务中间件 Linux
阿里云服务器部署多个tomcat
阿里云服务器部署多个tomcat
|
14天前
|
Linux Docker 容器
docker 容器常用命令
docker 容器常用命令
13 0
|
14天前
|
Linux Shell 虚拟化
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
21 0
|
6月前
|
关系型数据库 MySQL 应用服务中间件
Docker容器常用命令大全:熟练掌握使容器优化更加高效
Docker容器常用命令大全:熟练掌握使容器优化更加高效
144 0