目录
1、官网搜索镜像
2、拉取镜像并查看
3、启动
4、测试
1、官网搜索镜像
官网地址:Docker Hub
搜索nginx,会出来很多版本的镜像,一般拉取官方的或者star数多的,详细信息可以参考官网
2、拉取镜像并查看
[root@iZbp1dlz0y8paqewduhmx6Z ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@iZbp1dlz0y8paqewduhmx6Z ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 3 months ago 141MB
hello-world latest feb5d9fea6a5 7 months ago 13.3kB
centos latest 5d0da3dc9764 7 months ago 231MB
[root@iZbp1dlz0y8paqewduhmx6Z ~]#
3、启动
[root@iZbp1dlz0y8paqewduhmx6Z ~]# docker run -d -p80:80 --name nginx01 nginx
dbba3d32465ac57fe022f1b6541612cdc477d108d79a50bd148f9dbdb51ef54f
[root@iZbp1dlz0y8paqewduhmx6Z ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dbba3d32465a nginx "/docker-entrypoint.…" 5 seconds ago Up 5 seconds 0.0.0.0:80->80/tcp nginx01
[root@iZbp1dlz0y8paqewduhmx6Z ~]#
[root@iZbp1dlz0y8paqewduhmx6Z ~]# docker run -d -p80:80 --name nginx01 nginx dbba3d32465ac57fe022f1b6541612cdc477d108d79a50bd148f9dbdb51ef54f [root@iZbp1dlz0y8paqewduhmx6Z ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dbba3d32465a nginx "/docker-entrypoint.…" 5 seconds ago Up 5 seconds 0.0.0.0:80->80/tcp nginx01 [root@iZbp1dlz0y8paqewduhmx6Z ~]#
说明:docker run -d -p 80:80 --name nginx01 nginx
-d:后台启动
--name 给镜像起个名字,如果不起就是默认的nginx
-p 80:80 第一个80是虚拟机的端口,第二个80是nginx的端口,这一步就是将容器内部的端口映射到外部的端口
方便直接在外面用80端口访问
4、测试
记得关闭防火墙
1、虚拟机中测试: curl localhoat:80 发现是成功的
[root@iZbp1dlz0y8paqewduhmx6Z ~]# curl localhost:80Welcome to nginx! Welcome to nginx!If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.Thank you for using nginx.
[root@iZbp1dlz0y8paqewduhmx6Z ~]#
2、外网测试
3、进入nginx容器内部查看配置文件
命令:docker exec -it nginx01 /bin/bash
root@iZbp1dlz0y8paqewduhmx6Z ~]# docker exec -it nginx01 /bin/bash root@dbba3d32465a:/etc# ls adduser.conf cron.daily fonts host.conf ld.so.cache mke2fs.conf pam.conf rc2.d security subuid alternatives debconf.conf fstab hostname ld.so.conf motd pam.d rc3.d selinux systemd apt debian_version gai.conf hosts ld.so.conf.d mtab passwd rc4.d shadow terminfo bash.bashrc default group init.d libaudit.conf netconfig passwd- rc5.d shadow- timezone bindresvport.blacklist deluser.conf group- inputrc localtime nginx profile rc6.d shells ucf.conf ca-certificates dpkg gshadow issue login.defs nsswitch.conf profile.d rcS.d skel update-motd.d ca-certificates.conf e2scrub.conf gshadow- issue.net logrotate.d opt rc0.d resolv.conf ssl xattr.conf cron.d environment gss kernel machine-id os-release rc1.d rmt subgid root@dbba3d32465a:/etc# ll
这一步相当于进入了宿主机里面的nginx容器中,对linux进行配置。但是这样非常麻烦,每次部署应用后修改文件都得进入子容器中,有没有办法,能够在宿主机目录直接修改了,答案是有的,那就是数据卷技术。下篇接着讲



