美文网首页docker
docker 部署常用容器

docker 部署常用容器

作者: fanderboy | 来源:发表于2021-04-12 10:06 被阅读0次

    一.Redis

    下载镜像

    docker pull redis
    

    启动容器

    默认配置启动:

    docker run -itd --name redis -e TZ="Asia/Shanghai" -p 6379:6379 --restart=always redis
    

    指定配置文件启动(redis.conf):

    docker run -itd --name redis -e TZ="Asia/Shanghai" -v /etc/redis:/etc/redis  -v /home/redis/data:/data -p 6379:6379 --restart=always redis redis-server /etc/redis/redis.conf
    

    二.Mysql

    下载镜像

    docker pull mysql
    

    启动容器

    install.sh

    #!/bin/bash
    
    echo "======configuration variables======"
    container_name=mysql
    image_name=mysql
    version=latest
    port=3306
    passwrod=123456
    
    echo "======run container======"
    docker run -itd \
      --name=${container_name} \
      -v /var/lib/mysql/conf:/etc/mysql \
      -v /var/lib/mysql/data:/var/lib/mysql \
      -v /var/lib/mysql/logs:/var/log/mysql \
      -e MYSQL_ROOT_PASSWORD=${passwrod} \
      -e TZ="Asia/Shanghai" \
      --restart=always \
      -p ${port}:${port} \
      ${image_name}:${version}
    

    三.kafka和zookeeper

    1 安装zookeeper

    1.1 先使用命令 docker search zookeeper查看zookeeper的安装包

    docker search zookeeper
    
    zookeeper

    1.2 下载zookeeper镜像

    docker pull zookeeper
    

    1.3 创建并启动zookeeper容器

    docker run -itd --name zookeeper -e TZ="Asia/Shanghai" -p 2181:2181 --restart=always zookeeper
    

    2 安装kafka

    2.1 先使用命令 docker search kafka 查看kafka的安装包

    docker search kafka
    
    kafka

    2.2 下载kafka镜像

    docker pull wurstmeister/kafka
    

    2.3 创建并启动kafka容器

    docker run -itd --name kafka -p 9092:9092 --link zookeeper -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e KAFKA_ADVERTISED_HOST_NAME=127.0.0.1 -e KAFKA_ADVERTISED_PORT=9092 -e TZ="Asia/Shanghai" -v /etc/localtime:/etc/localtime --restart=always wurstmeister/kafka:latest
    

    四.nginx

    下载镜像

    docker pull nginx
    

    启动容器

    默认配置启动:

    docker run -itd --name nginx -e TZ="Asia/Shanghai" -p 80:80 --restart=always nginx
    

    指定配置文件启动:
    install.sh

    #!/bin/bash
    
    echo "======configuration variables======"
    container_name=nginx
    image_name=nginx
    version=latest
    port=80
    
    echo "======run container======"
    docker run -itd \
      --name=${container_name} \
      -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
      -v /etc/nginx/conf.d:/etc/nginx/conf.d \
      -v /var/log/nginx:/var/log/nginx \
      -e TZ="Asia/Shanghai" \
      --restart=always \
      -p ${port}:${port} \
      ${image_name}:${version}
    

    nginx.conf:nginx配置文件(其中包含了conf.d文件夹下的配置文件),一般配置缓存、限流在这个里面...
    conf.d: nginx配置文件夹(默认default.conf),代理、转发、负载、集群...
    nginx.conf:

    
    user  nginx;
    worker_processes  auto;
    
    error_log  /var/log/nginx/error.log notice;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
    
        include /etc/nginx/conf.d/*.conf;
    }
    

    config.d/default.conf:

    server {
        listen       80;
        listen  [::]:80;
        server_name  localhost;
    
        #access_log  /var/log/nginx/host.access.log  main;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    
        #error_page  404              /404.html;
    
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    

    相关文章

      网友评论

        本文标题:docker 部署常用容器

        本文链接:https://www.haomeiwen.com/subject/kyitlltx.html