标签(空格分隔): Docker nginx
在docker中创建镜像有两种方式:一:使用Dockfile文件创建;二:从Docker hub 镜像仓库拉取.
就像我们在 史上最简单的Docker入门教程中了解的那样:
为了简单起见,像这种常见的容器,我们没必要从新写Dockerfile文件去创建image文件.直接使用docker image pull
从docker hub拉取一个就可以.
首先通过 docker search [imageName]
命令搜索一下docker hub有没有我们想要的镜像.
ig:~ itguang$ docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 8341 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1328 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 547 [OK]
jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 364 [OK]
kong Open-source Microservice & API Management la… 184 [OK]
webdevops/php-nginx Nginx with PHP-FPM 102 [OK]
kitematic/hello-world-nginx A light-weight nginx container that demonstr… 97
zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 50 [OK]
bitnami/nginx Bitnami nginx Docker Image 49 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 35
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 34 [OK]
tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 19 [OK]
nginxdemos/nginx-ingress NGINX Ingress Controller for Kubernetes . Th… 10
wodby/drupal-nginx Nginx for Drupal container image 9 [OK]
webdevops/nginx Nginx container 8 [OK]
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 8 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 6 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 6
1science/nginx Nginx Docker images that include Consul Temp… 4 [OK]
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 3
pebbletech/nginx-proxy nginx-proxy sets up a container running ngin… 2 [OK]
behance/docker-nginx Provides base OS, patches and stable nginx f… 2 [OK]
travix/nginx NGinx reverse proxy 1 [OK]
toccoag/openshift-nginx Nginx reverse proxy for Nice running on same… 1 [OK]
mailu/nginx Mailu nginx frontend 0 [OK]
ig:~ itguang$
NAME:镜像仓库源的名称
DESCRIPTION:镜像的描述
STARS: 点赞数
OFFICIAL:是否docker官方发布
接下来我们使用 docker pull [imageName]
命令拉取我们想要的镜像:
ig:~ itguang$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
f2aa67a397c4: Pull complete
3c091c23e29d: Pull complete
4a99993b8636: Pull complete
Digest: sha256:0fb320e2a1b1620b4905facb3447e3d84ad36da0b2c8aa8fe3a5a81d1187b884
Status: Downloaded newer image for nginx:latest
ig:~ itguang$
拉取完毕,使用 docker images
或者docker image ls
命令查看当前镜像文件:
ig:~ itguang$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ae513a47849c 7 days ago 109MB
ig:~ itguang$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ae513a47849c 7 days ago 109MB
ig:~ itguang$
运行容器:
首先我们现在当前目录创建几个目录
$PWD/www:/www
$PWD/logs
$PWD/conf/nginx.conf
接下来运行下面的命令
ig:nginx itguang$ docker run -p 8000:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx
ad6de61641e02bfcec56a44c2ba51c4f42f9e4bb47d0c3ca67390d4d4676c750
ig:nginx itguang$
解释一下上面的参数:
-p 8000:80:将容器的80端口映射到主机的80端口.
–name mynginx: 将容器命名为 mynginx.
-v $PWD/www:/www: 将主机当前目录下的www目录挂在到容器的/www目录下.
-v $PWD/logs:/wwwlogs: 将主机当前目录下的logs目录挂在到容器的/wwwlogs目录下
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf:将主机当前目录下的nginx.conf挂在到容器目录下的etc/nginx/nginx.conf 文件.
-d nginx: 后台运行nginx容器,并且打印containerID.
使用docker ps
或者docker container ls
ig:~ itguang$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e8c8fae59eaf nginx "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:8000->80/tcp mynginx
ig:~ itguang$
可以看到nginx的欢迎页,证明docker安装nginx容器已经成功.