部署一个完整的项目到docker(三)
2019-04-26 本文已影响0人
焚_44b3
本节主要将项目上传至docker镜像,并且能正常运行项目,然后生成最终的发布版镜像
安装vim
, git
等工具
apt-get update
apt-get install vim
apt-get install git
源码部署到容器的方式有直接在容器中clone已经在 git上的项目,也可以把本地的文件拷贝到服务器。
本节只介绍git 的方式,下一节简单介绍下ia如果从本地上传到镜像容器下。
git方式下载码云上源码
# 进入web根目录
cd /var/www/html
#下载
git clone 源码地址
# 一般下载下来的文件在根目录下某个子文件夹下,将子文件夹下所有内容移动到web根目录
cd 子目录
mv -f * /var/www/html
启动数据库
service mysql start
导入数据到数据库
mysql -u root -p
# 进入数据库
create database 数据库名称;
# 创建数据库
source 数据库.sql文件;
exit;
#退出
设置vim编码格式
vim /etc/vim/vimrc
#末尾添加
set fileencodings=utf-8,ucs-bom,gb2312,gbk,gb18030,cp936
set termencoding=utf-8
set fileformats=unix
set encoding=utf-8
如果要配置其他项目,请参考:
https://www.jianshu.com/p/1b609dda308d
后续步骤参考上一节:包括生成镜像,退出 ,重启等步骤
报错处理
启动mysql 报错 No directory, logging in with HOME=/
https://blog.csdn.net/JOSENHUANG/article/details/53585280
进入mysql报错 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
- 修改mysql配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
下面#***
下行部分为要修改的地方
[mysqld_safe]
#***
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
#***
socket = /var/run/mysqld/mysqld.sock
port = 3306
# ...
# 末尾添加代码,功能为 登录mysql 跳过权限校验,并且关闭远程连接(mysql安全)
#***
skip-grant-tables
- 重启mysql
service mysql restart
- 进入mysql,并且修改密码,刷新权限
root@e670d9f7308c:/# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25-0ubuntu0.16.04.2 (Ubuntu)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 选择数据库
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update mysql.user set authentication_string=password('密码') where user='root';
Query OK, 0 rows affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 0 Warnings: 1
#查看表
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
# 刷新MYSQL权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
- 将/etc/mysql/mysql.conf.d/mysqld.cnf最后一行删除,并执行命令“service mysql restart”重启mysql。
重启后,mysql正常登录
Call to undefined function Think\simplexml_load_string()
安装php-xml
参考:https://blog.csdn.net/itxiaolong3/article/details/79555840