docker 部署常用容器

一.Redis

下載鏡像

docker pull redis

啟動(dòng)容器

默認(rèn)配置啟動(dòng):

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

指定配置文件啟動(dòng)(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

常用命令

遠(yuǎn)程連接:
redis-cli -h host -p port -a password

二.Mysql

下載鏡像

docker pull mysql

啟動(dòng)容器

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}

常用命令

遠(yuǎn)程連接:
格式: mysql -hhost -uusername -ppassword

三.kafka和zookeeper

1 安裝zookeeper

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

docker search zookeeper
zookeeper

1.2 下載zookeeper鏡像

docker pull zookeeper

1.3 創(chuàng)建并啟動(dòng)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 創(chuàng)建并啟動(dòng)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

啟動(dòng)容器

默認(rèn)配置啟動(dòng):

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

指定配置文件啟動(dòng):
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文件夾下的配置文件),一般配置緩存、限流在這個(gè)里面...
conf.d: nginx配置文件夾(默認(rèn)default.conf),代理、轉(zhuǎn)發(fā)、負(fù)載、集群...
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;
    #}
}

五.Centos

下載鏡像

docker pull centos:7.9.2009

啟動(dòng)容器

默認(rèn)配置啟動(dòng):

docker run -itd --name centos -e TZ="Asia/Shanghai" --privileged=true -p 22:22 --restart=always centos:7.9.2009 /usr/sbin/init

六.Nacos

下載鏡像

docker pull nacos/nacos-server

啟動(dòng)容器

默認(rèn)配置啟動(dòng):

docker run -itd --name nacos -e TZ="Asia/Shanghai" -e PREFER_HOST_MODE=hostname -e MODE=standalone -p 8848:8848 --restart=always nacos/nacos-server
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容