安装docker
- 下载docker
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
- 修改镜像仓库
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://dockerhub.azk8s.cn",
"https://hub-mirror.c.163.com"
]
}
- 查看docker
docker info
- 重启docker
systemctl restart docker.service
- 开机自启
systemctl enable docker.service
docker常用命令
- 进入容器
docker exec -it mysql /bin/bash
如果报错使用下面这个命令试试
OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown
docker exec -it mysql /bin/sh
- 修改容器启动命令
docker update <container_id> --restart=always
docker安装nginx
- 下载镜像
docker pull nginx
- 创建配置文件
vi /aqi/config/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/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 run \
-p 80:80 \
--name nginx \
--restart=always \
-v /aqi/config/nginx:/etc/nginx \
-v /aqi/log/nginx:/var/log/nginx \
-v /aqi/html/nginx:/usr/share/nginx/html \
-d nginx
docker安装mysql
- 下载镜像
docker pull mysql:5.7
- 启动镜像
docker run \
-p 3306:3306 \
--name mysql \
--restart=always \
-v /aqi/config/mysql:/etc/mysql \
-v /aqi/data/mysql:/var/lib/mysql \
-v /aqi/log/mysql:/var/log/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
- 参数说明
参数 | 说明 |
---|---|
-p 3306:3306 | 将容器的3306端口映射到主机的3306端口 |
–name mysql | 容器名称 |
–restart=always | 容器自启动 |
-v /aqi/config/mysql:/etc/mysql | 将配置文件挂载到主机(前面是主机地址,后面是容器地址) |
-v /aqi/data/mysql:/var/lib/mysql | 将数据文件挂在到主机 |
-v /aqi/log/mysql:/var/log/mysql | 将日志文件挂在到主机 |
-e MYSQL_ROOT_PASSWORD=root | 初始化用户密码 |
-d | 后台运行 |
mysql:5.7 | 指定启动镜像 |
- 修改配置文件
vi /aqi/config/mysql/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
- 重启容器
docker restart <container_id>
docker安装redis
- 下载镜像
docker pull redis
- 创建目录,以及配置文件
mkdir /aqi/config/redis
touch /aqi/config/redis/redis.conf
- 启动镜像
docker run -v /aqi/config/redis/redis.conf:/etc/redis/redis.conf \
-v /aqi/data/redis/data:/data \
-d --name redis \
-p 6379:6379 \
--restart=always \
redis:latest redis-server /etc/redis/redis.conf
- 修改配置文件
vi /aqi/config/redis/redis.conf
appendonly yes
requirepass 密码
- 重启容器
docker restart <container_id>
docker安装nacos
- 下载镜像
docker pull nacos/nacos-server
- 启动镜像,单机运行
docker run --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server
docker安装elasticsearch
- 下载镜像
docker pull elasticsearch:7.4.2
- 修改配置文件
mkdir /aqi/config/elasticsearch
mkdir /aqi/data/elasticsearch
设置所有地址都可以远程访问
echo "http.host: 0.0.0.0" >> /aqi/config/elasticsearch/elasticsearch.yml
- 启动镜像
docker run \
-p 9200:9200 \
-p 9300:9300 \
--name elasticsearch \
-v /aqi/config/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /aqi/data/elasticsearch:/usr/share/elasticsearch/data \
-v /aqi/plugins/elasticsearch:/usr/share/elasticsearch/plugins \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" \
-d elasticsearch:7.4.2
docker安装kibana
- 下载镜像
docker pull kibana:7.4.2
- 启动镜像
docker run \
--name kibana \
-e ELASTICSEARCH_HOSTS=http://ip:9200 \
-e "I18N_LOCALE=zh-CN" \
-p 5601:5601 \
-d kibana:7.4.2
安装jdk
yum install java-1.8.0-openjdk
docker 安装jenkins
- 下载镜像
docker pull jenkins/jenkins
- 创建jenkins工作区域
mkdir /var/jenkins_mount
- 修改权限
chmod 777 /var/jenkins_mount
- 启动容器
docker run \
-d \
-p 10240:8080 \
-p 50000:50000 \
-v /var/jenkins_mount:/var/jenkins_home \
-v /etc/localtime:/etc/localtime \
--name jenkins jenkins/jenkins
- 修改镜像地址
vi /var/jenkins_mount/hudson.model.UpdateCenter.xml
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
- 查看登录密码
docker logs <container_id>