1、Docker 基础命令
//显示所有镜像
docker ps -a
//连接docker镜像
docker run -it IMGNAME /bin/bash
//搜索镜像
docker search 镜像名
//拉取镜像
docker pull 镜像名
//拉取完成后查看镜像
docker images
//运行镜像(TAG是docker images命令展示的列表字段,-itd是后台运行)
docker run -itd 镜像名:TAG名 bash
// –name centos_xpmb 中的 centos_xpmb 为镜像启动后的容器名称,centos 为镜像名称,多个版本可使用 centos:tag 区分
docker run -itd –name centos_xpmb centos /bin/bash
// 6a55是docker ps查看镜像启动后获得的容器id,可以取完整的容器id
docker exec -it 6a55 bash
//提交镜像副本
docker commit -m=”ubuntu20.04的基础镜像” -a=”Test” a84ef84ce8d4 testdocker/ubuntu_base:v1.0
- -m: 提交的描述信息
- -a: 指定镜像作者
- a84ef84ce8d4:容器 ID
- runoob/ubuntu:v1.0 : 指定要创建的目标镜像名
//推送镜像(testdocker/ubuntu_base为镜像名)
docker push testdocker/ubuntu_base
//映射端口及目录,并后台运行容器 -p 本地端口:容器端口 -v 本地路径:容器路径
docker run -itd –name=”lnmp” -p 8081:80 -p 33061:3306 -v /home/www:/home/wwwroot/default testdocker/ubuntu_base /bin/bash
//设置开机启动
docker update –restart=always a84ef84ce8d4 (自己docker的id)
2、配置域名绑定
1)宿主机配置转发
server { listen 80; server_name www.xxx.cn; location / { # 转发到8081端口 proxy_pass http://公网IP:8081/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X - Real - IP $remote_addr; proxy_set_header REMOTE - HOST $remote_addr; proxy_set_header X - Forwarded - For $proxy_add_x_forwarded_for; } access_log/home/wwwlogs/www.xxx.cn_access.log; error_log/home/wwwlogs/www.xxx.cn_error.log; }
2)docker 容器内 nginx 正常配置项目访问即可
server { listen 80; server_name www.xxx.cn; index index.html index.htm index.php; root /home/wwwroot/default/; include enable-php.conf; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; } } location /nginx_status { stub_status on; access_log off; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } access_log /home/wwwlogs/www.xxx.cn_access.log; error_log /home/wwwlogs/www.xxx.cn_error.log; }