安装 docker-ce
// https://docs.docker.com/install/linux/docker-ce/centos/
$ 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 docker run hello-world
$ sudo systemctl enable docker
- Docker启动Get Permission Denied
sudo groupadd docker #添加docker用户组
sudo gpasswd -a $USER docker #将登陆用户加入到docker用户组中
newgrp docker #更新用户组
docker ps #测试docker命令是否可以使用sudo正常使用
安装 docker compose
// https://docs.docker.com/compose/install/
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
把 SonarQube 服务从一台服务器迁移到另一台服务器
// on source host
docker commit db mydb
docker commit sq mysq
docker save mydb -o ./tmp/mydb.tar
docker save mysq -o ./tmp/mysq.tar
scp -r tmp <user>@<dest_ip>:/target/path
// on destination host
docker load -i ./tmp/mydb.tar
docker load -i ./tmp/mysq.tar
// 启动镜像却发现没有数据
docker network create sonar
docker run -d --name db --network sonar -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar mydb
docker run -d --name sq --network sonar -p 9000:9000 -p 9092:9092 -e SONARQUBE_JDBC_USERNAME=sonar -e SONARQUBE_JDBC_PASSWORD=sonar -e SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar mysq
只能从原数据库导出数据,往新数据库导入数据
// on the source host
docker exec -it db sh
# su - postgres
# pg_dump -U sonar sonar > /tmp/mysq.sql
# exit
# exit
docker cp <container_id>:/tmp/mysq.sql ~/tmp/
scp ~/tmp/mysq.sql <user>@<dest_ip>:/target/path
// on destination host
docker cp /target/path/mysq.sql <container_id>:/tmp/
docker exec -it db sh
# su - postgres
# dropdb -U sonar sonar
# createdb -U sonar sonar
# psql -d sonar -U sonar -f /tmp/mysq.sql
# exit
# exit
检验
经过以上步骤,我可以 admin 账户之外的原自定义 chenjo 账户登录。证明数据迁移成功。