从新的镜像启动容器

[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


仅供参考

你可能感兴趣的:(从新的镜像启动容器)