容器镜像的制作
作者:互联网
手动制作docker镜像
制作一个基于centos6系统的nginx镜像(单服务)
1:启动一个纯净的centos:6.9容器,并安装nginx
[root@docker01 ~]# docker run -it centos:6.9
2:查看容器的yum源
[root@f9d00bc2114d /]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-fasttrack.repo
3.1:安装官方源中nginx
[root@f9d00bc2114d /]# vi /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@f9d00bc2114d /]# yum -y install nginx
[root@f9d00bc2114d /]# nginx -v
nginx version: nginx/1.16.1
3.2:安装epel源中nginx
[root@f9d00bc2114d /]# yum install -y epel-release
[root@f9d00bc2114d /]# yum -y install nginx
4:退出该容器,该容器死亡
curl+d
[root@f9d00bc2114d /]# exit
5:把安装好服务的容器,提交为镜像
[root@docker01 ~]# docker commit hungry_lichterman centos6.9_nginx:v0
sha256:c8c52a2b776fd6aa3c9dcc3643a5895a51ee8e7f8dd247138326d0c6fc7542fe
6:查看镜像是否存在
[root@docker01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6.9_nginx v0 c8c52a2b776f 55 seconds ago 331MB
7:删除创建时使用的容器
[root@docker01 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f9d00bc2114d centos:6.9 "/bin/bash" 13 minutes ago Exited (0) 6 minutes ago hungry_lichterman
[root@docker01 ~]# docker rm f9d00bc2114d
f9d00bc2114d
8:测试镜像是否能使用
[root@docker01 ~]# docker run -d -p 80:80 centos6.9_nginx:v0 nginx -g 'daemon off;'
ab03b88a88a6e879cf13c5130ffc1eb8d49fc202755355de25a406405e1944dd
制作一个基于centos6系统的kod网盘的镜像(多服务)
1:基于以上制作的centos6.9_nginx:v0镜像的基础上,进行在加工安装php
[root@docker01 ~]# docker run -it -d -p 80:80 centos6.9_nginx:v0
bd42b38406e92653bb2dcc22e2436f79934613dc6c7dc5bff9d7589cca251d0d
[root@docker01 ~]# docker attach angry_tharp
[root@bd42b38406e9 /]# yum install php-fpm php-gd php-mbstring -y
2:修改php运行用户,方便管理
[root@bd42b38406e9 /]# vi /etc/php-fpm.d/www.conf
底行模式/user = 回车
user = nginx
group = nginx
3:nginx运行一个网站
[root@bd42b38406e9 /]# cd /etc/nginx/conf.d/
[root@bd42b38406e9 /]# rm -rf /etc/nginx/conf.d/*
[root@bd42b38406e9 conf.d]# vi kod.com.conf
server {
listen 80;
server_name php.oldxu.com;
root /kod;
location / {
index index.php info.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
4:创建站点目录
[root@bd42b38406e9 conf.d]# mkdir /kod
5:下载站点文件kod,因为镜像中无wget,unzip所以使用curl,并下载unzip
[root@bd42b38406e9 kod]# curl -o kodexplorer4.40.zip http://static.kodcloud.com/update/download/kodexplorer4.40.zip
[root@bd42b38406e9 kod]# ls
kodexplorer4.40.zip
[root@bd42b38406e9 kod]# yum install -y unzip
6:解压kod文件并授权给nginx用户
[root@bd42b38406e9 kod]# unzip kodexplorer4.40.zip
[root@bd42b38406e9 kod]# ls
app ChangeLog.md config data index.php kodexplorer4.40.zip plugins README.MD static
[root@bd42b38406e9 /]# chown -R nginx. /kod/
7:书写镜像初始启动nginx,php脚本
[root@bd42b38406e9 kod]# vi /init.sh
#!/bin/bash
service php-fpm start
nginx -g 'daemon off;'
8:把安装好服务的容器,提交为镜像
[root@docker01 ~]# docker commit angry_tharp nginx6.9_nginx:v1
sha256:5ff19d734d0c03e821aca4471b6b9fe4e15dd06df415dbabab4bb2209e7b10f7
9:查看镜像是否存在
[root@docker01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6.9_nginx v1 77cc89bdd62c 31 seconds ago 483MB
10:删除创建时使用的容器
[root@docker01 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bd42b38406e9 centos6.9_nginx:v0 "/bin/bash" 26 minutes ago Exited (0) 8 minutes ago angry_tharp
[root@docker01 ~]# docker rm angry_tharp
angry_tharp
11:测试镜像是否能使用
[root@docker01 ~]# docker run -d -p 80:80 centos6.9_nginx:v1 /bin/bash /init.sh
e14154cb2f1947190f014adc212a3ba910955f7cb25592a3fa7aa5889a0e1f0e
[root@docker01 ~]# docker run -d -p 81:80 centos6.9_nginx:v1 su -c " service php-fpm start ; nginx -g 'daemon off;' "
d4d204cc36f725cbce9502dd3fd55c5d0ccadf171773aba37c21920764f1c2a7
[root@docker01 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d4d204cc36f7 centos6.9_nginx:v1 "su -c ' service php…" 6 seconds ago Up 6 seconds 0.0.0.0:81->80/tcp ecstatic_perlman
e14154cb2f19 centos6.9_nginx:v1 "/bin/bash /init.sh" 14 seconds ago Up 14 seconds 0.0.0.0:80->80/tcp upbeat_booth
想要生活就要努力活着
发布了22 篇原创文章 · 获赞 391 · 访问量 5万+
私信
关注
标签:容器,bd42b38406e9,制作,nginx,docker01,镜像,docker,php,root 来源: https://blog.csdn.net/Dakshesh/article/details/104440029