1. 手动制作nginx镜像
- 下载镜像并且初始化系统`
[root@centos1 ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
Digest: sha256:307835c385f656ec2e2fec602cf093224173c51119bbebd602c53c3653a3d6eb
Status: Image is up to date for centos:latest
docker.io/library/centos:latest
[root@centos1 ~]# docker run -d -it --name centos centos:latest
679427d7bb3bfc66d198d73f2b6278721ab0af0f94c406b19d159842cdb86cb9
[root@centos1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
679427d7bb3b centos:latest "/bin/bash" 2 seconds ago Up 1 second centos
[root@centos1 ~]# docker exec -it centos bash
[root@ed615c24f953 /]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-09-25 07:18:40-- http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 101.37.183.146, 101.37.183.169, 101.37.183.143, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|101.37.183.146|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: '/etc/yum.repos.d/CentOS-Base.repo'
100%[==================================================================================================================>] 2,523 --.-K/s in 0s
2019-09-25 07:18:41 (166 MB/s) - '/etc/yum.repos.d/CentOS-Base.repo' saved [2523/2523]
[root@ed615c24f953 /]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2019-09-25 07:19:49-- http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 101.37.183.143, 101.37.183.147, 101.37.183.169, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|101.37.183.143|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: '/etc/yum.repos.d/epel.repo'
100%[==================================================================================================================>] 664 --.-K/s in 0s
2019-09-25 07:19:49 (133 MB/s) - '/etc/yum.repos.d/epel.repo' saved [664/664]
- yum 安装并且配置nginx
yum -y install nginx #yum安装nginx
yum install -y vim wget pcre pcrepcre-devel zlib zlibzlib-devel openssl openssl openssl-devel iproute net net-tools iotop #安装常用工具以及命令
- 关闭nginx后台运行
[root@ed615c24f953 /]# vim /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
daemon off; #关闭后台运行,需要添加
- 自定义WEB页面(无关紧要步骤)
[root@ed615c24f953 /]# echo "AiL test page" > /usr/share/nginx/html/index.html
- 提交为镜像
[root@centos1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ed615c24f953 centos:latest "/bin/bash" 4 hours ago Up 4 hours centos
[root@centos1 ~]# docker commit -a "linux_ghw@163.com" -m "nginx v1.0" --change="EXPOSE 80 443" ed615c24f953 centos-nginx:v1.0
sha256:4a19849b6909581ea22ad5ba58b4432e29b9d0fa777321a2b3307e7cc6fb7848
- 使用自己的镜像启动容器
[root@centos1 ~]# docker images | grep nginx
centos-nginx v1.0 4a19849b6909 5 minutes ago 398MB
nginx latest ab56bba91343 12 days ago 126MB
[root@centos1 ~]# docker run -d -it -p 88:80 --name mynginx centos-nginx:v1.0 /usr/sbin/nginx
549fedfa9671ffb1a6a90f89ba194f67798de044e0869a2656d8dfc3f704998e
[root@centos1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
549fedfa9671 centos-nginx:v1.0 "/usr/sbin/nginx" 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:88->80/tcp mynginx
ed615c24f953 centos:latest "/bin/bash" 5 hours ago Up 5 hours centos
-
页面测试
-
技能点总结
[root@centos1 merged]# docker commit -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Create a new image from a container's changes
Options:
-a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
-c, --change list Apply Dockerfile instruction to the created image
-m, --message string Commit message
-p, --pause Pause container during commit (default true)
2. Docker file 制作nginx镜像
DOCKER FILE 简介:
DockerFile可以说是一种可以被Docker程序解释的脚本,DockerFile是由一条条的命令组成,每对应linux下面
的一条命令,Docker程序将这些DockerFile指令再翻译成真正的linux命令,其有自己的书写方式和支持的命令,Docker程序读取DockerFile并根据指令生成Docker镜像,相比手动制作镜像的方式,DockerFile更能直观的
展示镜像是怎么产生,有了DockerFileDockerFile,当后期有额外的需求时,只要在之前DockerFile添加或者修
改响应的命令即可重新生成的Docke镜像。
- 创建工作目录
[root@centos1 ~]# mkdir /opt/nginx-v1.1
[root@centos1 ~]# cd /opt/nginx-v1.1/
[root@centos1 nginx-v1.1]#
- 编写Docker file文件