Skip to main content

Use vagrant to quickly create linux, and docker to install redis and mysql

Use vagrant to quickly create linux, and docker to install redis and mysql

1. Use vagrant to quickly create linux

1. Download virtualbox , Oracle VM VirtualBox

Use vagrant to quickly create linux, and docker to install redis and mysql

2. Download & install Vagrant

Official image warehouse: https://app.vagrantup.com/boxes/search

Vagrant download: https://www.vagrantup.com/downloads.html

After the installation is complete, enter the command

    vagrant

If the following interface appears, the installation is successful.

Use vagrant to quickly create linux, and docker to install redis and mysql

Open the window cmd window and run Vagrant init centos/7 to initialize a centos7 system.

    Vagrant init centos/7

run

    vagrant up

The virtual machine is now started.

The password of the system root user is vagrant

    su root

Use vagrant to quickly create linux, and docker to install redis and mysql

  • Other commonly used commands in vagrant:

vagrant ssh: Automatically use the vagrant user to connect to the virtual machine.

vagrant upload source [destination] [namelid]: Upload files https://www.vagrantup.com/docs/cli/init.html Vagrant command line

2. Modify virtual machine network settings

The default IP address of the virtual machine is not a fixed IP, and it is inconvenient for developers to modify the Vagrantfile file.

The default address of the Vagrantfile file: C:\Users\Administrator

Use vagrant to quickly create linux, and docker to install redis and mysql

After saving, restart the virtual machine

    vagrant reload

Ping each other to see if they can communicate with each other.

Use vagrant to quickly create linux, and docker to install redis and mysql

Use vagrant to quickly create linux, and docker to install redis and mysql

3. Install docker

Refer to the official documentation: Installing the Docker engine on CentOS | Docker documentation

1. Uninstall the previously installed docker

    
2. docker-client \

3. docker-client-latest \

4. docker-common \

5. docker-latest \

6. docker-latest-logrotate \

7. docker-logrotate \

8. docker-engine



2. Install the package (provides utilities) and set up the repository.yum-utils``yum-config-manager

    
2. sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo



3. Install Docker Engine, containerd and Docker Compose:

    sudo yum install docker-ce docker-ce-cli containerd.io

4. Start Docker.

    sudo systemctl start docker

5. View

    docker -v

6. Set up auto-start at boot

    sudo systemctl enable docker

Use vagrant to quickly create linux, and docker to install redis and mysql

7. Configure Alibaba Cloud image acceleration

Alibaba Cloud path: Container Image Service (aliyun.com)

Use vagrant to quickly create linux, and docker to install redis and mysql

4. Docker install mysql

Reference: Docker installation mysql5.7 detailed tutorial_docker installation mysql5,7-CSDN blog

5. Install redis with docker

1. Pull the image

    docker pull redis

2.Create files

    
2. touch /mydata/redis/ conf/redis.conf



3. Create a container

    
2. -v /mydata/redis/data:/data \

3. -v /mydata/mysql/conf/redis/redis.conf:/etc/redis/redis.conf \

4. -d redis redis-server /etc/redis/redis.conf



4. Test

    docker exec -it redis redis-cli

5. Modify the redis.conf file and make redis persistent

Use vagrant to quickly create linux, and docker to install redis and mysql

Use vagrant to quickly create linux, and docker to install redis and mysql

6. Restart redis

    docker restart redis

7. Set up auto-start at boot

    docker update redis --restart=always