基础命令 :https://www.runoob.com/docker/docker-command-manual.html
下边仅列出常用操作,
1> 查看docker Container 列表:docker ps -a 注意:docker 状态必须
2> 进入某一个docker,就是一个小的虚拟机(Container):docker exec -it 9fbe362214a6 /bin/bash
3> 重启docker:docker restart 9fbe362214a6
4> 停止docker:docker stop 9fbe362214a6
5> 删除docker:docker rm 9fbe362214a6
6> 将docker中的目录/文件 拷贝到主机: docker cp 4c4a14b4c832:/etc/nginx/nginx.conf /home/nginx.conf
1)卸载docker:
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
2) 更新yum,否则有些资源库不存在,导致安装失败:yum update
3) 安装rz,让xshell支持拖拽上传:yum install lrzsz
4)安装yum-utils,切换源,这样下载速度会快很多
I、安装依赖包: yum install -y yum-utils device-mapper-persistent-data lvm2
II、更新源:yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
1、安装社区最新版本(也可以安装指定版本):sudo yum install docker-ce docker-ce-cli containerd.io
2、启动docker:sudo systemctl start docker
3、安装php。执行命令:docker pull php:7.0.24-fpm(正式项目统一切换为7.4)
4、安装nginx。执行命令:docker pull nginx
5、启动PHP,命令行:docker run -p 9000:9000 --name php7.0.24 -v /mnt/www:/www -d php:7.0.24-fpm
php7.0.24: 实例化的php docker名,可以任意填写
-v: /mnt/www 为宿主服务器的代码路径, :/www 为实例化的docker的脚本路径
php:7.0.24-fpm 必须和第3步的一致,否则会重新安装最新版PHP
6、创建配置文件目录及代码目录(此教程为多站点配置教程)
mkdir -p /mnt/www/cs1
mkdir -p /mnt/www/cs2
mkdir -p /mnt/nginx/conf.d
7、查看php-fpm 内网IP,需要配置到nginx.conf内:docker inspect --format='{{.NetworkSettings.IPAddress}}' php7.0.24
将查询到的IP地址更新到*.conf fastcgi_pass:IP:9000
8、创建物理主机路径到docker的映射,并启动nginx docker
docker run --name nginx -p 80:80 -d \
-v /mnt/www:/usr/share/nginx/html:ro \
-v /mnt/nginx/conf.d:/etc/nginx/conf.d:ro \
--link php7.0.24:php \
nginx
--name:docker的实例化名字
-d:后台运行,随系统自启动
nginx:stable,安装的是哪个版本的ngxin,这里就填什么,必须完整,否则会再下载安装最新的nginx
以下附带*.conf 配置文件代码,标红处为特别注意配置项,最终这两个配置文件上传到:/mnt/nginx/conf.d,且重启nginx docker
一、cs1.palmbly.com.conf
server {
charset utf-8;
client_max_body_size 128M;
listen 80;
server_name cs1.palmbly.com;
#charset koi8-r;
location / {
root /usr/share/nginx/html/cs1;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/cs1;
}
location ~ \.php {
root /usr/share/nginx/html/cs1;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/cs1$fastcgi_script_name;
fastcgi_pass 172.17.0.2:9000; #此处为第7步查出的IP
try_files $uri =404;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
location ~ \.(ini|conf|txt|log|gitignore|git)$ {
deny all;
}
location ^~ /.git {
deny all;
}
location ^~ /runtime {
deny all;
}
}
二、cs2.palmbly.com.conf
server {
charset utf-8;
client_max_body_size 128M;
listen 80;
server_name cs2.palmbly.com;
#charset koi8-r;
location / {
root /usr/share/nginx/html/cs2;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/cs2;
}
location ~ \.php {
root /usr/share/nginx/html/cs2;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/cs2$fastcgi_script_name;
fastcgi_pass 172.17.0.2:9000; #此处为第7步查出的IP
try_files $uri =404;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;