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
相关推荐
yuxb7314 分钟前
集群与负载均衡:HAProxy 与 Nginx 实践
运维·nginx·负载均衡
hqxstudying20 分钟前
MyBatis 和 MyBatis-Plus对比
java·数据库·mysql·mybatis
YBCarry_段松啓36 分钟前
DeerFlow单服务器低成本公网访问
docker·开源·llm
OrionZephyr1 小时前
使用watchtower更新docker容器
docker
好奇的菜鸟1 小时前
使用 Apache Flink CDC 3.0 实现 MySQL 到 Elasticsearch 的数据同步
mysql·flink·apache
T001 小时前
保姆级教学--黑马点评,批量获取用户登录token及jemeter多线程测试
redis
Seven972 小时前
Redis支持事务吗?了解Redis的持久化机制吗?
redis
DemonAvenger2 小时前
高效JOIN操作:多表关联查询技巧与实战经验分享
数据库·mysql·性能优化
麦兜*3 小时前
【Prometheus】 + Grafana构建【Redis】智能监控告警体系
java·spring boot·redis·spring·spring cloud·grafana·prometheus
秋已杰爱4 小时前
Redis分布式锁
数据库·redis·分布式