Home > Database > Redis > body text

How to successfully start redis in docker container and enter

王林
Release: 2021-03-16 10:03:19
forward
7998 people have browsed it

How to successfully start redis in docker container and enter

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
Copy after login

Then We download the Redis image source through Docker

docker pull redis
Copy after login

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 ~]#
Copy after login

Then create and start the Redis container

First start Docker

[root@localhost ~]# systemctl start docker
Copy after login

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
Copy after login

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 ~]#
Copy after login

(Learning video sharing: redis video tutorial)

Enter the Redis terminal

docker exec :在运行的容器中执行命令
# 语法
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
# OPTIONS说明:
-d :分离模式: 在后台运行
-i :即使没有附加也保持STDIN 打开
-t :分配一个伪终端
Copy after login

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 ~]#
Copy after login

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>
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template