/etc/ssh/sshd_config文件vagrant用户是看不到的,需要使用sudo vi /etc/ssh/sshd_config命令去编辑
修改完成后,重启sshd服务:sudo systemctl restart sshd
即可通过账户密码登录
虚拟机ip: (通过ip addr查) 账户:root 密码:vagrant
注意:VirtualBox 会与包括但不限于如下软件冲突,需要卸载这些软件,然后重启电脑; 冲突的软件:红蜘蛛,360,净网大师(有可能)等
1)、备份原 yum 源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2)、使用新 yum 源
Curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
3)、生成缓存
yum makecache
(建议Oracle VM VirtualBox让专门的人去管理,防止误删虚拟机)
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
阿里云,容器镜像服务
针对 Docker 客户端版本大于 1.10.0 的用户
可以通过修改 daemon 配置文件/etc/docker/daemon.json 来使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
docker pull mysql:5.7
docker run --restart=always -p 3307:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7
参数说明
--restart=always 开机启动
-p 3307:3306:将容器的 3306 端口映射到主机的 3307 端口
-v /mydata/mysql/conf:/etc/mysql:将配置文件夹挂载到主机
-v /mydata/mysql/log:/var/log/mysql:将日志文件夹挂载到主机
-v /mydata/mysql/data:/var/lib/mysql/:将配置文件夹挂载到主机
-e MYSQL_ROOT_PASSWORD=123456:初始化 123456 用户的密码
vi /mydata/mysql/conf/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
注意:解决 MySQL 连接慢的问题 在配置文件中加入如下,并重启 mysql [mysqld] skip-name-resolve 解释: skip-name-resolve:跳过域名解析
docker exec -it mysql mysql -uroot -p123456
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; flush privileges
docker exec -it mysql /bin/bas
docker pull redis
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf
docker run --restart=always -p 6379:6379 --name redis -v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf
docker pull nginx
docker run --restart=always -d -p 8088:80 --name nginx -v /mydata/nginx/html:/usr/share/nginx/html -v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /mydata/nginx/logs:/var/log/nginx nginx
部署nginx具体参考:https://www.cnblogs.com/zhangwuxuan/p/12672172.html
添加新的映射端口参考:https://www.cnblogs.com/chengshuai5421/p/13544614.html
配置项目路径时要用容器绝对路径参考:https://www.cnblogs.com/chengshuai5421/p/13544652.html
docker build -t mchcgen:v0.1 .
docker run --name mchcgen -d -p 9988:9988 mchcgen:v0.1 -v /mydata/java/dev/application-dev.yml:/application-dev.yml
由于容易的配置文件application-dev.yml和/mydata/java/dev/下的配置文件做映射,可以直接修改/mydata/java/dev/下的配置文件然后重启mchcgen
删除镜像报错: image is being used by stopped container 0d4ae078c085
执行一下命令
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker stop
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker rm
docker images|grep none|awk '{print $3 }'|xargs docker rmi
(如果公司有自己的镜像仓库,可以把构建的镜像仓库推送到镜像仓库中,需要哪个版本直接拉取,无须重新构建)