Docker installation and Redis container
Docker installation, environment: VM CentOS 8; Ali Cloud image acceleration; Redis container created.
CentOS 7 installation will not be demonstrated here
Connect the CENTOS
Ensure that the VMS and physical servers are on the same network segment
Use the bridge network, select the appropriate network card
$IP addr # Query the VM IP addressCopy the code
Use the IP address, root account, and password 123456 to connect to CentOS
DOCKER installation
- Viewing the CentOS Version
$uname -r # Docker requires a CentOS kernel version later than 3.10Copy the code
- Upgrade software packages and kernels; (optional)
$ yum update
Copy the code
- Install the docker
$yum install docker $docker -vCopy the code
To confirm, enter Y and press Enter
- Start the docker
$ systemctl start docker
Copy the code
- Set the Docker service to boot
$ systemctl enable docker
Copy the code
- Stop the docker
$ systemctl stop docker
Copy the code
mirror
- retrieve
$docker search keywordCopy the code
- pull
$docker pull Image name :tagCopy the code
If you pull the mirror too slow, can consider is to use a mirror image of domestic developers need to open the ali developers account, then use the ali speed up service Ali developer account after login, cr.console.aliyun.com/undefined/i… View your exclusive accelerator address, like xxxxxx.mirror.aliyuncs.com; Run the following command
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Copy the code
- View all local mirrors
$ docker images
Copy the code
- Example Delete a local mirror
$ docker rmi image-id
Copy the code
Container operation
- run
$docker run --name container-name -d image-name #-name -d: background running. Image-name: specifies an image templateCopy the code
- View a list of containers
$docker ps # view running containers; Add -a to view all containersCopy the code
- Stops the currently running container
docker stop container-name/container-id
Copy the code
- Start the
$ docker start container-name/container-id
Copy the code
- delete
docker rm container-id
Copy the code
- Port mapping
-p 6379:6379
# eg: docker run -p 6379:6379 --name myredis docker.io/redis
Copy the code
- Container log
docker logs container-name/container-id
Copy the code
Take installing REDIS as an example
- Pull the mirror
$ docker pull redis
Copy the code
You can refer to Github for the configuration of docker redis containers, and the links are from the list of Supported tags and respective Dockerfile links of DockerHub
- Create a Redis container; -d Background running; -p Port mapping; – requirePass redis Specifies the password. It must come after the image name
$ docker run -d --name redis-6379 -p 6379:6379 redis --requirepass "123456"
Copy the code
The client tool can now connect to Redis remotely
- Enter the Redis container
$ docker exec -it redis-6379 bash
Copy the code
- Enter the Redis client of the Redis container
$ docker exec -it redis-6379 redis-cli
Copy the code