The following are the steps to start redis in docker and enter:
First, you need to search for the image source related to redis through docker
docker search redis
Then We download the Redis image source through Docker
docker pull redis
If the version is not set here, the latest image source will be downloaded by default.
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/tomcat latest aeea3708743f 9 days ago 529 MB docker.io/rabbitmq latest 2b5cda43d345 2 weeks ago 151 MB docker.io/elasticsearch 7.6.0 5d2812e0e41c 2 weeks ago 790 MB docker.io/redis latest 44d36d2c2374 2 weeks ago 98.2 MB docker.io/mysql latest 791b6e40940c 2 weeks ago 465 MB [root@localhost ~]#
Then create and start the Redis container
First start Docker
[root@localhost ~]# systemctl start docker
Start Redis in Docker
Here we do not set the alias of the container, -d Represents background startup.
[root@localhost ~]# docker run -d redis da45019bf760304a66c3dd96b8847a50eddd8c73ff77cd3b3f37a46d7f016834
You can also start Redis like this, where -p represents port mapping, mapping 6379 in the container to port 6379 in the machine running Docker, --name represents a custom container name
[root@localhost ~]# docker run -d -p 6379:6379 --name="myredis" redis 249dd65794b32310dea5e094f41df845d971b623382ddc1179c404402f576750 [root@localhost ~]#
(Learning video sharing: redis video tutorial)
Enter the Redis terminal
docker exec :在运行的容器中执行命令 # 语法 docker exec [OPTIONS] CONTAINER COMMAND [ARG...] # OPTIONS说明: -d :分离模式: 在后台运行 -i :即使没有附加也保持STDIN 打开 -t :分配一个伪终端
The container ID in Docker can be viewed with docker -ps
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 249dd65794b3 redis "docker-entrypoint..." 3 minutes ago Up 3 minutes 0.0.0.0:6379->6379/tcp myredis da45019bf760 redis "docker-entrypoint..." 18 minutes ago Up 18 minutes 6379/tcp naughty_pasteur [root@localhost ~]#
redis-cli means running a redis client.
[root@localhost ~]# docker exec -it da45019bf760 redis-cli 127.0.0.1:6379> 127.0.0.1:6379> set msg "Hello World Redis" OK 127.0.0.1:6379> get msg "Hello World Redis" 127.0.0.1:6379>
Related recommendations: redis database tutorial
The above is the detailed content of How to successfully start redis in docker container and enter. For more information, please follow other related articles on the PHP Chinese website!