美文网首页
从新的镜像启动容器

从新的镜像启动容器

作者: Al_不期而遇 | 来源:发表于2019-03-12 11:16 被阅读0次

[root@centos-ops ~]# docker run -d -p 80 --name static_web tlhao/static_web nginx -g "daemon off;"(使用 -p指定端口,-d是放在后台启动)

941f7970bcc08a1cc62bdb45591bfa5ad9687055c8d41e5edb24089f3a81a31c

[root@centos-ops ~]# docker ps -l

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                   NAMES

941f7970bcc0        tlhao/static_web    "nginx -g 'daemon ..."   10 seconds ago      Up 7 seconds        0.0.0.0:32768->80/tcp   static_web

[root@centos-ops ~]# docker port 941f7970bcc0 80(因为docker会随机选择一个49153~65535的端口启动)

0.0.0.0:32768

[root@centos-ops ~]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                   NAMES

941f7970bcc0        tlhao/static_web    "nginx -g 'daemon ..."   3 minutes ago       Up 3 minutes        0.0.0.0:32768->80/tcp   static_web

3831094738b5        ubuntu:14.04        "/bin/sh -c 'while..."   2 weeks ago         Up 33 minutes                               daemon_dave3

[root@centos-ops ~]# docker stop static_web;

static_web

[root@centos-ops ~]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES

3831094738b5        ubuntu:14.04        "/bin/sh -c 'while..."   2 weeks ago         Up 34 minutes                           daemon_dave3

[root@centos-ops ~]# docker run -d -p 80:80 --name static_web tlhao/static_web  nginx -g "daemon off;"

/usr/bin/docker-current: Error response from daemon: Conflict. The container name "/static_web" is already in use by container 941f7970bcc08a1cc62bdb45591bfa5ad9687055c8d41e5edb24089f3a81a31c. You have to remove (or rename) that container to be able to reuse that name..

See '/usr/bin/docker-current run --help'.

[root@centos-ops ~]# docker run -d -p 80:80 --name static_web1 tlhao/static_web  nginx -g "daemon off;"(将docker的80端口绑定到本机80端口上)

e3ff1f437d8726641b53d3f659d5936fac36312a13343d4293d92e929fdb4706

[root@centos-ops ~]# docker start 941f7970bcc0

941f7970bcc0

[root@centos-ops ~]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                   NAMES

e3ff1f437d87        tlhao/static_web    "nginx -g 'daemon ..."   28 seconds ago      Up 27 seconds       0.0.0.0:80->80/tcp      static_web1

941f7970bcc0        tlhao/static_web    "nginx -g 'daemon ..."   7 minutes ago       Up 3 seconds        0.0.0.0:32769->80/tcp   static_web

3831094738b5        ubuntu:14.04        "/bin/sh -c 'while..."   2 weeks ago         Up 37 minutes                               daemon_dave3

[root@centos-ops ~]# docker run -d -p 8080:80 --name static_web2 tlhao/static_web nginx -g "daemon off;"(指定本地8080的端口给容器的80端口使用)

65a2a5de02501e19eb06034c5b24564c36db352fdae8d73010b11bd2c6b00d0c

[root@centos-ops ~]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                   NAMES

65a2a5de0250        tlhao/static_web    "nginx -g 'daemon ..."   9 seconds ago       Up 7 seconds        0.0.0.0:8080->80/tcp    static_web2

e3ff1f437d87        tlhao/static_web    "nginx -g 'daemon ..."   17 minutes ago      Up 17 minutes       0.0.0.0:80->80/tcp      static_web1

941f7970bcc0        tlhao/static_web    "nginx -g 'daemon ..."   24 minutes ago      Up 16 minutes       0.0.0.0:32769->80/tcp   static_web

3831094738b5        ubuntu:14.04        "/bin/sh -c 'while..."   2 weeks ago         Up 54 minutes                               daemon_dave3

[root@centos-ops ~]# docker port static_web2 80

0.0.0.0:8080

[root@centos-ops ~]# docker run -d -p 127.0.0.1:80:80 --name static_web3 tlhao/static_web nginx -g "daemon off;"(指定ip和端口给容器使用,这里我们的ip会显示已经被使用)

3087d0284cdd36509bd46f6f93d2972e34b6c8001d8e3969c61889e459eea876

[root@centos-ops ~]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                   NAMES

65a2a5de0250        tlhao/static_web    "nginx -g 'daemon ..."   21 minutes ago      Up 21 minutes       0.0.0.0:8080->80/tcp    static_web2

e3ff1f437d87        tlhao/static_web    "nginx -g 'daemon ..."   38 minutes ago      Up 38 minutes       0.0.0.0:80->80/tcp      static_web1

941f7970bcc0        tlhao/static_web    "nginx -g 'daemon ..."   45 minutes ago      Up 38 minutes       0.0.0.0:32769->80/tcp   static_web

仅供参考

相关文章

  • 从新的镜像启动容器

    [root@centos-ops ~]# docker run -d -p 80 --name static_we...

  • Docker常用命令&操作

    镜像操作 容器操作 下载mysql镜像 启动mysql容器 下载tomcat镜像 启动tomcat容器 -d:后台...

  • docker搭建Kafka集群及监控、可视化部署实战

    下载zookeeper镜像 下载kafka镜像 启动zk镜像生成容器 启动kafka1镜像生成容器 启动kafka...

  • docker

    搜索镜像 拉取镜像 启动镜像 查看所有容器 启动已存在容器 停止容器 进入容器 查询容器运行详细信息 容器打包 查...

  • docker容器

    docker容器 查看容器 启动容器 启动已有镜像的容器,如果没有对应的镜像,会先从仓库中下载下来后创建容器 启动...

  • Docker镜像和容器

    搜索镜像 获取镜像 查看镜像 删除镜像 启动容器 查看容器 启动交互式容器--name mydocker1 自定义...

  • Docker入门

    获取镜像 列出镜像 删除本地镜像 启动镜像运行容器 查看已经运行容器

  • Docker 常用操作指令

    镜像操作 列出docker下的所有镜像 搜索镜像 拉取镜像 删除镜像 容器操作 查看容器 创建与启动容器 创建容器...

  • docker常用命令

    基础操作 使用镜像构建容器并启动 停止正在运行的容器 移除容器 & 移除本地镜像 启动容器 查看容器运行状态(日志...

  • docker初识

    镜像命令:拉取镜像查看镜像容器命令:创建容器启动容器/停止容器容器删除拷贝容器目录挂载查看IP 》拉取镜像,创建容...

网友评论

      本文标题:从新的镜像启动容器

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