安装在虚拟机环境下
查看当前系统版本使用命令:
lsb_release -a
执行命令更新库
sudo apt update
sudo apt upgrade
查看磁盘分区情况
df -h
安装docker
curl -fsSL https://get.docker.com -o get-docker.sh //获取官方安装docker的 shell文件
sudo apt install curl //上面不能执行的话执行 这一句 安装curl
sudo sh get-docker.sh //安装docker
sudo usermod -aG docker $USER //该命令设置当前用户执行不需要在执行docker前面每次都输入sudo 这一步执行完之后至少需要注销一下才能生效,或者关机重启
调整docker使用国内镜像
docker info //查看当前docker的信息 记录一下状态,后面设置好对比这个信息
sudo vi /etc/docker/daemon.json //执行该命令使用vi编辑器编辑粘贴下面内容
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn",
"https://docker.m.daocloud.io","https://noohub.ru",
"https://dockerhub.timeweb.cloud","https://huecker.io"]
}
这个vi保存 需要使用 1.按esc,2.输入冒号:,3.输入wq,4回车保存
sudo systemctl daemon-reload //重启 daemon服务
sudo systemctl restart docker //重启docker服务
docker info // 查看国内镜像是否生效
docker下载mysql下载nginx 的镜像
docker pull mysql:5.7 //后面的命令对5.7使用正常,否则会出错
docker pull nginx
docker images 或者docker image list 查看docker镜像是否安装完成
创建mysql容器:
当前目录创建几个放置mysql相关参数的文件夹 为的目录在桌面上所有命令有
cd 桌面mkdir mysql
cd mysql
mkdir conf log data
cd conf
mkdir conf.d
在conf.d文件夹中放入配置内容my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/9.1/en/server-configuration-defaults.html[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2Mhost-cache-size=0
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysqlpid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock!includedir /etc/mysql/conf.d/
这个vi保存 需要使用 1.按esc,2.输入冒号:,3.输入wq,4回车保存
docker创建mysql关联上面绑定的目录命令:
docker run --name mysql -d -p 3306:3306 --restart=always -v ~/mysql/log:/var/log/mysql -v ~/mysql/data:/var/lib/mysql -v ~/mysql/conf/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=root mysql:5.7
防火墙打开3306端口让外部可以远程访问mysql
sudo ufw allow 3306
docker 当前文件夹下创建 nginx文件夹为后续docker放置nginx配置和相关文件作准备
mkdir nginx
cd nginx
mkdir log html conf.d
进入conf.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;
#}
}
这个vi保存 需要使用 1.按esc,2.输入冒号:,3.输入wq,4回车保存
docker创建nginx关联上面绑定的目录命令:
docker run --name nginx -p 8080:80 -d --restart=always -v ~/zm/nginx/log:/var/log/nginx -v ~/zm/nginx/html:/usr/share/nginx/html -v ~/zm/nginx/conf.d:/etc/nginx/conf.d nginx
docker中查看 容器命令:
docker ps //查看运行中的容器 加 -a 后缀查看包含停止的容器
docker stop 容器名
docker rm 容器名
版权所有:有信心——uxinxin 我的个人网站欢迎常来!手机版(新站开启,请多多关照) 豫ICP备12017930号-1
豫公网安备 41910102000493号