docker 安装
安装环境
Ubuntu-18.04安装Docker
开始安装
更新
sudo apt update
安装依赖
sudo apt install apt-transport-https ca-certificates curl software-properties-common
添加Dokcer官方密钥到系统中
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
添加docker源
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
这里在更新一下源
sudo apt update
查看可以安装的docker版本
apt-cache policy docker-ce
开始安装docker
sudo apt install docker-ce
运行docker命令正常就ok了。
docker 安装redis
拉取镜像
docker pull redis
下载redis配置文件(先进入一个下载的文件夹,比如:/develop/redis/)
wget http://download.redis.io/redis-stable/redis.conf
修改配置文件
vim redis.conf //修改配置文件
bind 127.0.0.1 #注释掉这部分,这是限制redis只能本地访问
protected-mode no #默认yes,开启保护模式,限制为本地访问
daemonize no#默认no,改为yes意为以守护进程方式启动,可后台运行,除非kill进程(可选),改为yes会使配置文件方式启动redis失败
dir ./ #输入本地redis数据库存放文件夹(可选)
appendonly yes #redis持久化(可选)
docker 启动 redis (不使用配置文件,直接命令启动)
docker run --name redis_docker -p 6379:6379 -d redis --requirepass "123"
docker安装zookeeper和kafka
docker pull zookeeper
启动镜像生成容器
docker run -d --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name zookeeper -p 2181:2181 -v /etc/localtime:/etc/localtime wurstmeister/zookeeper
下载kafka镜像
docker pull wurstmeister/kafka
docker run -d --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kafka -p 9092:9092 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=127.0.0.1:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -v /etc/localtime:/etc/localtime wurstmeister/kafka
docker 安装nginx
docker pull nginx
创建自定义配置文件替换容器内的配置
mkdir -p /data/nginx/{conf,conf.d,html,log}
-- 启动方式1
docker run -p 8080:80 -d docker.io/nginx
-- 启动方式2
docker run --name my_nginx -d -p 80:80 -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/log:/var/log/nginx -v /data/nginx/html:/usr/share/nginx/html nginx
nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server{
listen 80;
server_name your_server_name; #你的serverName
root /usr/share/nginx/html;
index index.html;
}
}
docker常用命令
docker ps -a # 查看所有创建的容器
docker stop pid # 停止某个容器的运行
docker rm -f pid # 移除某个容器
docker restart pid
docker stop $(docker ps -a -q) # stop停止所有容器
docker rm $(docker ps -a -q) # remove删除所有容器
参考资料
https://blog.csdn.net/u012798683/article/details/88052528