docker常用容器启动命令

docker常用容器启动命令

mysql启动

bash 复制代码
docker run -itd --name mysql-test --restart=always -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

redis启动

bash 复制代码
docker run -itd --name redis-test --restart=always -p 6379:6379 redis

nginx配置文件&启动

备注: 当前是把配置文件、日志、HTML资源文件夹映射到宿主机的,所以要先创建对应的目录和配置文件nginx.conf

bash 复制代码
mkdir -p /app/nginx/html
mkdir -p /app/nginx/logs
mkdir -p /app/nginx/conf
cd /app/nginx/conf
vi nginx.conf
# 将配置文件内容粘贴到配置文件中,然后保存并退出

nginx.conf配置文件内容模板如下:

bash 复制代码
user  root;
worker_processes  2;

#error_log  /var/log/nginx/error.log;
#pid        /var/log/nginx/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    #default_type  application/octet-stream;
    default_type  application/javascript;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent"';

    #access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nodelay     on;

    keepalive_timeout  65;

    gzip  on;
    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /html/;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }

        location /prod-api/ {
                proxy_pass http://192.168.3.207:8080/;
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
                if ($request_method = 'OPTIONS') {
                        return 204;
                }
        }
        error_page   500 501 502 503 504  /50x.html;
        location = /50x.html {
            root   /html;
        }
    }
}

nginx启动命令

bash 复制代码
docker run -itd --name nginx-test --restart=always -p 80:80 -v /app/nginx/html:/html -v /app/nginx/logs:/var/log/nginx -v /app/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime nginx
相关推荐
学代码的真由酱14 小时前
Docker基础
运维·docker·容器
拾贰_C14 小时前
【mysql | windows | installation】 MySQL5.安装
数据库·windows·mysql
真实的菜14 小时前
【无标题】Redis 从入门到精通(七):缓存设计与最佳实践 —— 穿透、击穿、雪崩与一致性终极指南
数据库·redis·缓存
念何架构之路14 小时前
存储技术Redis
数据库·redis·缓存
元直数字电路验证15 小时前
云计算实验笔记(四):容器编排(Container Orchestration)
运维·笔记·docker·云计算
kukubuzai15 小时前
Docker Note
linux·运维·docker
惜年_night15 小时前
Docker部署05-GitLab的CI-CD发布
ci/cd·docker·gitlab
yuezhilangniao15 小时前
MySQL 8.0.32 二进制安装脚本 和初始化 操作系统版本rocky86
数据库·mysql·adb
Trouvaille ~15 小时前
【Redis篇】Redis 主从复制:数据同步的原理与实现
数据库·redis·缓存·中间件·高可用·主从复制·后端开发
杨某不才16 小时前
内网环境下,使用Docker安装Elasticsearch分词器插件
elasticsearch·docker·jenkins