镜像版本
镜像 | 版本 |
---|---|
mysql | 5.7 |
nginx | 1.17 |
php-fpm | 7.4 |
swoole(手动编译安装) | 4.4.16 |
安装
# 拉去mysql:5.7版本.最新版本mysql:latest
[root@localhost ~]# docker pull mysql:5.7
# 验证是否安装成功
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/mysql 5.7 84164b03fa2e 9 days ago 456 MB
启动
# 后台运行mysql容器 使用3306端口,将端口映射在宿主机3306端口
[root@localhost ~]# docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=qvbilam mysql:5.7
# 查看进程
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c14a3d573dde mysql:5.7 "docker-entrypoint..." 6 seconds ago Up 5 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp priceless_perlman
# 查看3306端口
[root@localhost ~]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 17018 root 4u IPv6 656673 0t0 TCP *:mysql (LISTEN)
连接
# Docker连接Mysql.通过-it CONTAINER ID.通过docker ps获取
[root@localhost ~]# docker exec -it c14a3d573dde /bin/bash
# 输入连接用户名和密码即可
root@c14a3d573dde:/# mysql -uroot -pqvbilam
# 客户端连接需要指定ip
[root@localhost ~]# mysql -uroot -pqvbilam -h192.168.128.136
安装
# 安装最新版本的nginx
[root@localhost ~]# docker pull nginx:latest
# 验证是否安装成功
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest 6678c7c2e56c 9 days ago 127 MB
docker.io/mysql 5.7 84164b03fa2e 9 days ago 456 MB
docker.io/mysql latest 9b51d9275906 9 days ago 547 MB
启动
# 关闭原有nginx服务
[root@localhost ~]# service nginx stop
Redirecting to /bin/systemctl stop nginx.service
# 测试链接
[root@localhost ~]# curl 127.0.0.1:80
curl: (7) Failed connect to 127.0.0.1:80; 拒绝连接
# docker后台运行nginx,本地8080映射容器内部端口80
[root@localhost ~]# docker run -d -p 8080:80 nginx
365d05613767155a8e5de5da68135c31359b26be90f5e668fda1a4aaa63a9643
# 验证是否启动
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
365d05613767 nginx "nginx -g 'daemon ..." 17 seconds ago Up 16 seconds 0.0.0.0:8080->80/tcp optimistic_heyrovsky
c14a3d573dde mysql:5.7 "docker-entrypoint..." 27 minutes ago Up 27 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp priceless_perlman
# 端口验证
[root@localhost ~]# lsof -i:80
[root@localhost ~]# lsof -i:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 18779 root 4u IPv6 668442 0t0 TCP *:webcache (LISTEN)
访问
[root@localhost ~]# curl 192.168.128.136:80
curl: (7) Failed connect to 192.168.128.136:80; 拒绝连接
[root@localhost ~]# curl 192.168.128.136:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
修改默认页面
进入Docker寻找nginx默认页面
# 进入docker 容器
docker exec -it 365d05613767 /bin/bash
vi /etc/nginx/nginx.conf
# 没有vi. 安装vim
apt-get update
apt-get install vim
vi /etc/nginx/nginx.conf
# 获得到包含的配置文件路径nginx.conf部分信息 include /etc/nginx/conf.d/*.conf
cd /etc/nginx/conf.d
# 查看文件
ls
# 编辑默认配置文件
vi default.conf
# 获得到默认文件路径default.conf部分信息 root /usr/share/nginx/html
cd /usr/share/nginx/html
vi index.html
修改内容
# 修改配置h1内容,区分是否修改成功
<h1>Welcome to QvBiLam Docker Nginx!</h1>
重启测试
# 退出docker 容器
exit
# 查看docker nginx进程id
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
365d05613767 nginx "nginx -g 'daemon ..." 19 minutes ago Up 19 minutes 0.0.0.0:8080->80/tcp optimistic_heyrovsky
c14a3d573dde mysql:5.7 "docker-entrypoint..." 47 minutes ago Up 47 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp priceless_perlman
# 通过进程id重启docker nginx
[root@localhost ~]# docker restart 365d05613767
365d05613767
[root@localhost ~]# curl 127.0.0.1
curl: (7) Failed connect to 127.0.0.1:80; 拒绝连接
[root@localhost ~]# curl 127.0.0.1:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body>
<h1>Welcome to QvBiLam Docker Nginx!</h1>
</body>
</html>
安装
# 安装php7.4
[root@localhost ~]# docker pull php:7.4-fpm
# 验证是否安装成功
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest 6678c7c2e56c 9 days ago 127 MB
docker.io/mysql 5.7 84164b03fa2e 9 days ago 456 MB
docker.io/mysql latest 9b51d9275906 9 days ago 547 MB
docker.io/php 7.4-fpm 77cd7cd803b2 2 weeks ago 405 MB
启动
[root@localhost ~]# docker run -d php:7.4-fpm
33c2f07d76add221105993d3739e7a47acdbb91cd70a735f413393f34b943c4f
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33c2f07d76ad php:7.4-fpm "docker-php-entryp..." 8 seconds ago Up 7 seconds 9000/tcp stoic_mccarthy
365d05613767 nginx "nginx -g 'daemon ..." About an hour ago Up 49 minutes 0.0.0.0:8080->80/tcp optimistic_heyrovsky
c14a3d573dde mysql:5.7 "docker-entrypoint..." About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tcp priceless_perlman
验证
# 进入docker 容器
docker exec -it 33c2f07d76ad /bin/bash
# 构建vim
apt-get update
apt-get install vim
# 创建测试文件
vi test.php
添加内容
<?php
echo 'hello QvBilam' . PHP_EOL;
执行测试
php test.php
# 输出
hello QvBilam
以swoole为演示.
编译安装
# 进入php容器
docker exec -it 33c2f07d76ad /bin/bash
# 创建存放包目录
mkdir -p /data/package
cd /data/package/
# 安装wget
apt-get install wget
# 下载swoole
wget https://github.com/swoole/swoole-src/archive/v4.4.16.tar.gz
tar -zxvf v4.4.16.tar.gz
cd swoole-src-4.4.16/
phpize
./configure
make && make install
# 变异后获得的信息(记录下来.怕忘了目录)
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/
Installing header files: /usr/local/include/php/
修改配置
# PHP官方镜像为设置php.ini
cd /usr/local/etc/php
cp php.ini-development php.ini
# 添加extension=swoole.so
重启容器
# 退出容器
exit
# 重启容器 进程id(通过docker ps 查看 CONTAINER ID)
[root@localhost ~]# docker restart 33c2f07d76ad
# 进入容器 进程id
[root@localhost ~]# docker exec -it 33c2f07d76ad /bin/bash
测试swoole
执行输出hello qvbilam 代表安装成功
<?php
Swoole\Runtime::enableCoroutine();
go(function ()
{
echo "hello qvbilam" . PHP_EOL;
});
Swoole拓展是手动编译安装.不是从Docker镜像中下载的. 多占一个tag主要是感觉写在PHP的tags里显得太长了...