安装
nginx
下载最新的nginx
启动nginx
为了方便,把nginx配置文件、静态文件和日志映射到容器外面
1 2 3 4 5 6 7 8
| d:\\
md \docker-data\nginx\conf md \docker-data\nginx\conf.d md \docker-data\nginx\logs md \docker-data\nginx\www
md \docker-data\nginx\conf \docker-data\nginx\conf.d \docker-data\nginx\logs \docker-data\nginx\www
|
在启动nginx前要先创建nginx配置文件,不然会把配置文件当成文件夹
可以先启动一个nginx,复制配置文件到服务器上
1 2 3 4 5
| docker run --name nginx -p 8081:80 -d nginx
docker cp aacfa7df8232:/etc/nginx/nginx.conf D:\docker-data\nginx\conf\ docker cp aacfa7df8232:/etc/nginx/conf.d/default.conf D:\docker-data\nginx\conf.d\
|
修改 D://docker-data/nginx/conf.d/default.conf
就可以了,因为D://docker-data/nginx/conf/
已经通过include
引入了default.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| server { listen 80; listen [::]:80; server_name localhost;
location / { root /usr/share/nginx/html; index index.html index.htm; }
location ^~ /api/ { proxy_pass http://192.168.40.26:9090/; }
location ~ \.zz$ { proxy_pass http://192.168.40.26:9090; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
|
启动nginx
注意:把命令合成一行,此处只是为了看起来更直观
1 2 3 4 5 6
| docker run --name nginx -p 81:80 -d -v D:\docker-data\nginx\www:/usr/share/nginx/html -v D:\docker-data\nginx\conf/nginx.conf:/etc/nginx/nginx.conf -v D:\docker-data\nginx\conf.d/default.conf:/etc/nginx/conf.d/default.conf -v D:\docker-data\nginx\logs:/var/log/nginx nginx
|
进入nginx容器内部
1
| docker exec -it nginx /bin/bash
|
设置开机自启
1
| docker update nginx --restart=always
|
redis
下载最新的redis
启动redis
在启动redis前要先创建redis配置文件,不然会把配置文件当成文件夹
1 2 3 4 5 6 7
| d:\\
md \docker-data\redis\data md \docker-data\redis\conf
md \docker-data\redis\data \docker-data\redis\conf
|
默认没有开启持久化,数据在内存中,重启服务器后数据会丢失,在配置文件中设置持久化
1 2 3
| vi D:\docker-data\redis\conf\redis.conf
appendonly yes
|
启动redis
注意:把命令合成一行,此处只是为了看起来更直观
1 2 3 4
| docker run -p 6379:6379 --name redis -v D:\docker-data\redis\data:/data -v D:\docker-data\redis\conf\redis.conf:/etc/redis/redis.conf -d redis redis-server /etc/redis/redis.conf
|
进入redis客户端
1
| docker exec -it redis redis-cli
|
设置开机自启
1
| docker update redis --restart=always
|
mysql
下载mysql5.7
mysql配置文件
创建mysql配置文件
1 2 3 4 5 6 7
| d:\\
md \docker-data\mysql\data md \docker-data\mysql\conf md \docker-data\mysql\log
md \docker-data\mysql\data \docker-data\mysql\conf \docker-data\mysql\log
|
新建配置文件
1 2
| vi D:\docker-data\mysql\conf\my.conf
|
配置文件内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13
| [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
|
启动mysql
1 2 3 4 5 6
| docker run -p 3306:3306 --name mysql -v D:\docker-data\mysql\conf:/etc/mysql/ -v D:\docker-data\mysql\log:/var/log/mysql -v D:\docker-data\mysql\data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
|
进入容器内部
1
| docker exec -it mysql /bin/bash
|
重启mysql
进入mysql容器内部,可以看到里面有在外面配置的配置文件my.conf
1 2 3
| docker exec -it mysql /bin/bash
cat /etc/mysql/my.conf
|
设置开机自启
1
| docker update mysql --restart=always
|