192.168.58.151? (关闭防火墙和selinux)
安装好docker服务? ? ? ? (详细参照:http://t.csdnimg.cn/usG0s?中的国内源安装docker)
?创建目录:
[root@docker ~]# mkdir wordpress
[root@docker ~]# ls
anaconda-ks.cfg wordpress ip_fixed.sh
获取wordpress的安装包:? cn.wordpress.org
服务器端下载:
[root@docker ~]# cd wordpress/
[root@docker wordpress]# wget https://cn.wordpress.org/latest-zh_CN.tar.gz
修改nginx.conf文件,并将其放在wordpress目录下
[root@docker wordpress]# cat nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
server {
listen 80;
server_name www.itnzs.top;
location / {
root /usr/share/nginx/wordpress;
index index.php;
}
location ~ \.php$ {
root /usr/share/nginx/wordpress; #指定网站目录
fastcgi_pass 127.0.0.1:9000; #指定访问地址
fastcgi_index index.php; #指定默认文件
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #站点根目录,取决于root配置项
include fastcgi_params; #包含nginx常量定义
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
在wordpress目录下创建Dockerfile
[root@docker wordpress]# vim Dockerfile
# 设置基础镜像
FROM daocloud.io/library/centos:7
# 安装环境
RUN yum install -y epel-release \
; yum install -y nginx \
; yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm \
; yum install -y php80-php-xsl php80-php php80-php-cli php80-php-devel php80-php-gd php80-php-pdo php80-php-mysql php80-php-fpm \
; yum clean all
# 将代码包拷贝到镜像中
# RUN wget https://cn.wordpress.org/latest-zh_CN.tar.gz
ADD latest-zh_CN.tar.gz /usr/share/nginx
# 将配置文件拷贝到镜像中
COPY nginx.conf /etc/nginx/
# 将启动脚本拷贝到镜像中
COPY docker-entrypoint.sh /
# 在启动容器时执行脚本
CMD ["sh","/docker-entrypoint.sh"]
创建docker-entrypoint.sh文件并编辑,其目的是执行启动服务并hang住。?
[root@docker wordpress]# vim docker-entrypoint.sh
chmod 777 /usr/share/nginx/wordpress -R
nginx
/opt/remi/php80/root/usr/sbin/php-fpm
echo "nginx 和 php 启动成功"
tail -f /var/log/nginx/*
查看文件及镜像
[root@docker wordpress]# ls
docker-entrypoint.sh Dockerfile latest-zh_CN.tar.gz nginx.conf
[root@docker wordpress]# docker pull daocloud.io/library/centos:7
[root@docker wordpress]# docker pull mysql:5.7
[root@docker wordpress]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
daocloud.io/library/centos 7 7e6257c9f8d8 3 years ago 203MB
mysql 5.7 c20987f18b13 23 months ago 448MB
?开始build 并 run?
[root@docker wordpress]# docker build -t wordpress:1.0 .
[+] Building 0.1s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
····
=> => naming to docker.io/library/wordpress:1.0
[root@docker wordpress]# docker run -it -p 80:80 wordpress:1.0
nginx 和 php 启动成功
==> /var/log/nginx/access.log <==
==> /var/log/nginx/error.log <==
浏览器访问 :192.168.58.151
服务器端另开端口启动MySQL镜像,并设置密码与数据库名
[root@docker wordpress]# docker run -itd -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress mysql:5.7
c7ec40a5eb7fa8e9f03707f629a58fc1769a0b6d9b69d97be06e440d46023464
查看服务并获取数据库的ip地址(172.17.0.3)
[root@docker wordpress]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7ec40a5eb7f mysql:5.7 "docker-entrypoint.s…" 8 minutes ago Up 8 minutes 3306/tcp, 33060/tcp clever_napier
8f19b43d21b2 wordpress:1.0 "sh /docker-entrypoi…" 13 minutes ago Up 13 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp elastic_hertz
[root@docker wordpress]# docker inspect c
·····
"NetworkID": "32010babc4ca892ce8aa2d7c58188897ed69613f94147b81e5ad0cfdfae06672",
"EndpointID": "741536bb8a5e9ec8fafe13aa1e8d876f404a7d7a40943eccecf6e57ea67210a3",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03",
"DriverOpts": null
}
}
}
}
]
[root@docker wordpress]#
浏览器端进行填写
获取jenkins.war包请到官网下载:Jenkins download and deployment
创建目录并上传jdk
[root@docker ~]# mkdir jenkins
[root@docker ~]# cd jenkins/
[root@docker jenkins]# ls
jenkins.war jdk-17_linux-x64_bin.tar.gz plugins-2.414.3.tar.gz
[root@docker jenkins]#
新建Dockerfile并编辑
[root@docker jenkins]# vim Dockerfile
FROM daocloud.io/library/centos:7
ADD jdk-17_linux-x64_bin.tar.gz /usr/local
ADD jenkins-2.414.3.war /usr/local
ENV JENKINS_HOME=/usr/local/.jenkins
ENV JAVA_HOME /usr/local/jdk-17.0.7
ENV PATH=$JAVA_HOME/bin:$PATH
ADD plugins-2.414.3.tar.gz /usr/local/.jenkins/ #plugins包代替可以减少后期的安装时间
RUN yum -y install fontconfig
ENTRYPOINT ["java","-jar","/usr/local/jenkins-2.414.3.war"]
?构建镜像并创建容器
[root@docker jenkins]# docker build -t jenkins:1.0 .
[+] Building 0.1s (10/10) FINISHED
=> [internal] load .dockerignore ······
=> => naming to docker.io/library/jenkins:1.0
[root@docker jenkins]# docker run -it -p 8080:8080 jenkins:1.0
Running from: /usr/local/jenkins-2.414.3.war
webroot: /usr/local/.jenkins/war
·····
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
d728551b74fe4634a3d22fa8c4ffa36f #此行为密码,后面登录需要
····
*************************************************************
另起端口看看8080端口是否启动
[root@docker ~]# ss -nplt | grep 8080
LISTEN 0 128 *:8080 *:* users:(("docker-proxy",pid=25919,fd=4))
LISTEN 0 128 [::]:8080 [::]:* users:(("docker-proxy",pid=25925,fd=4))
成功启动,浏览器访问 ip:8080? (192.168.58.151:8080)?
?创建管理员用户
点击重启;
登录
jenkins部署完成。