docker部署容器

作者: wolfe404 | 来源:发表于2018-04-03 15:37 被阅读1次

    1、安装docker,不清楚的请到https://www.jianshu.com/p/28dda99223f8  查看具体安装步骤

    2、查看本机已经拉取的镜像

    [root@localhost ~]# docker images

    REPOSITORY          TAG                IMAGE ID            CREATED            SIZE

    docker.io/nginx    1.13.10            7f70b30f2cc6        12 days ago        109 MB

    docker.io/tomcat    7                  b6002d3fc5ab        2 weeks ago        456 MB

    docker.io/centos    7                  2d194b392dd1        4 weeks ago        195 MB

    3、搜索可安装的镜像的版本

    # docker search +要搜索的镜像名称

    [root@localhost ~]# docker search centos

    INDEX      NAME                                        DESCRIPTION                                    STARS    OFFICIAL  AUTOMATED

    docker.io  docker.io/centos                            The official build of CentOS.              4153      [OK]     

    ......

    4、镜像拉取

    [root@localhost ~]# docker pull tomcat:7

    Trying to pull repository docker.io/library/tomcat ...

    7: Pulling from docker.io/library/tomcat

    ......

    Digest: sha256:6337eea67b0ce5c4ab991037f1de5a5046b46804b28b6cec2c7941595b1b1f63

    Status: Downloaded newer image for docker.io/tomcat:7

    5、镜像导出和导入建议查看 https://www.jianshu.com/p/8408e06b7273,写的还是挺详细的

    6、启动一个tomcat镜像

    启动tomcat实例:

    [root@localhost ~]# docker run -d --name my-tomcat7 -p 8888:8080 b6002d3fc5ab

    949433da208e7676b9e0a07b50af4436dc0b648b665867225d17876e998add3d

    启动命令说明:

    docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

    OPTIONS说明:

    -a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/STDERR 三项;

    -d: 后台运行容器,并返回容器ID;

    -i: 以交互模式运行容器,通常与 -t 同时使用;

    -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;

    --name="nginx-lb": 为容器指定一个名称;

    --dns 8.8.8.8: 指定容器使用的DNS服务器,默认和宿主一致;

    --dns-search example.com: 指定容器DNS搜索域名,默认和宿主一致;

    -h "mars": 指定容器的hostname;

    -e username="ritchie": 设置环境变量;

    --env-file=[]: 从指定文件读入环境变量;

    --cpuset="0-2" or --cpuset="0,1,2": 绑定容器到指定CPU运行;

    -m :设置容器使用内存最大值;

    --net="bridge": 指定容器的网络连接类型,支持 bridge/host/none/container: 四种类型;

    --link=[]: 添加链接到另一个容器;

    --expose=[]: 开放一个端口或一组端口;

    实例

    使用docker镜像nginx:latest以后台模式启动一个容器,并将容器命名为mynginx。

    docker run --name mynginx -d nginx:latest

    使用镜像nginx:latest以后台模式启动一个容器,并将容器的80端口映射到主机随机端口。

    docker run -P -d nginx:latest

    使用镜像nginx:latest以后台模式启动一个容器,将容器的80端口映射到主机的80端口,主机的目录/data映射到容器的/data。

    docker run -p 80:80 -v /data:/data -d nginx:latest

    使用镜像nginx:latest以交互模式启动一个容器,在容器内执行/bin/bash命令。

    runoob@runoob:~$ docker run -it nginx:latest /bin/bash

    root@b8573233d675:/#

    7、部署web应用

    查看tomcat 安装目录

    [root@localhost ~]# docker exec -it my-tomcat7 /bin/bash

    root@949433da208e:/usr/local/tomcat# ls

    LICENSE  NOTICE  RELEASE-NOTES RUNNING.txt  bin  conf include  lib  logs  native-jni-lib  temp  webapps  work

    root@949433da208e:/usr/local/tomcat# exit

    exit

    [root@localhost ~]#

    将打包好的war文件导入,查询文件位置

    [root@localhost ~]# ls

    anaconda-ks.cfg  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos  wolfe.war  work

    将war包导入容器的webapps目录中

    [root@localhost ~]# docker cp wolfe.war my-tomcat7:/usr/local/tomcat/webapps

    [root@localhost ~]#

    回车点击后,之后浏览器中输入相应的htpp地址即可访问部署好的项目

    写的有些简陋请多多包含。。。。。

    相关文章

      网友评论

        本文标题:docker部署容器

        本文链接:https://www.haomeiwen.com/subject/xyaqhftx.html