Docker快速入门(十)Docker服务

Docker容器向外提供服务

分享04中的Nginx服务来试一下。
不过这次我直接用Nginx镜像创建容器,先下载Nginx镜像。

[root@promote ~]# docker search nginx
INDEX       NAME                                                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/nginx                                                  Official build of Nginx.                        8981      [OK]
docker.io   docker.io/jwilder/nginx-proxy                                    Automated Nginx reverse proxy for docker c...   1357                 [OK]
docker.io   docker.io/richarvey/nginx-php-fpm                                Container running Nginx + PHP-FPM capable ...   586                  [OK]
docker.io   docker.io/jrcs/letsencrypt-nginx-proxy-companion                 LetsEncrypt container to use with nginx as...   387                  [OK]
docker.io   docker.io/kong                                                   Open-source Microservice & API Management ...   203       [OK]
docker.io   docker.io/webdevops/php-nginx                                    Nginx with PHP-FPM                              106                  [OK]
docker.io   docker.io/kitematic/hello-world-nginx                            A light-weight nginx container that demons...   102
docker.io   docker.io/zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server ...   58                   [OK]
docker.io   docker.io/bitnami/nginx                                          Bitnami nginx Docker Image                      54                   [OK]
docker.io   docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          36                   [OK]
docker.io   docker.io/linuxserver/nginx                                      An Nginx container, brought to you by Linu...   36
docker.io   docker.io/tobi312/rpi-nginx                                      NGINX on Raspberry Pi / armhf                   20                   [OK]
docker.io   docker.io/nginxdemos/nginx-ingress                               NGINX Ingress Controller for Kubernetes . ...   11
docker.io   docker.io/blacklabelops/nginx                                    Dockerized Nginx Reverse Proxy Server.          9                    [OK]
docker.io   docker.io/wodby/drupal-nginx                                     Nginx for Drupal container image                9                    [OK]
docker.io   docker.io/webdevops/nginx                                        Nginx container                                 8                    [OK]
docker.io   docker.io/centos/nginx-18-centos7                                Platform for running nginx 1.8 or building...   6
docker.io   docker.io/1science/nginx                                         Nginx Docker images that include Consul Te...   4                    [OK]
docker.io   docker.io/centos/nginx-112-centos7                               Platform for running nginx 1.12 or buildin...   3
docker.io   docker.io/behance/docker-nginx                                   Provides base OS, patches and stable nginx...   2                    [OK]
docker.io   docker.io/pebbletech/nginx-proxy                                 nginx-proxy sets up a container running ng...   2                    [OK]
docker.io   docker.io/toccoag/openshift-nginx                                Nginx reverse proxy for Nice running on sa...   1                    [OK]
docker.io   docker.io/travix/nginx                                           NGinx reverse proxy                             1                    [OK]
docker.io   docker.io/ansibleplaybookbundle/nginx-apb                        An APB to deploy NGINX                          0                    [OK]
docker.io   docker.io/mailu/nginx                                            Mailu nginx frontend                            0                    [OK]

还是优先使用官方镜像,将镜像拉取到本地。

[root@promote ~]# docker pull docker.io/nginx
Using default tag: latest
Trying to pull repository docker.io/library/nginx ...
latest: Pulling from docker.io/library/nginx
683abbb4ea60: Pull complete
a470862432e2: Pull complete
977375e58a31: Pull complete
Digest: sha256:a65beb8c90a08b22a9ff6a219c2f363e16c477b6d610da28fe9cba37c2c3a2ac
Status: Downloaded newer image for docker.io/nginx:latest

查看一下本地镜像,看看是否下载成功。

[root@promote ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/nginx     latest              3c5a05123222        3 days ago          109 MB

接着用刚下载好的镜像创建容器。

[root@promote ~]# docker run -d --name nginx -p 80:80 docker.io/nginx
09823eb382b49c72cde153bafa23170212d9ea0da5754d069c68c5e2d29b6a64

使用-p选项将本地端口映射到容器端口,这里是将Centos的80端口映射到Nginx容器的80端口。
可以通过访问Centos的80端口查看Nginx是否安装成功。

可以看到Docker容器就是通过端口映射向外提供服务的。

posted @ 2018-07-13 14:23  顾北清  阅读(269)  评论(0编辑  收藏  举报