Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a redis image in docker

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to create a redis image in docker. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Direct pull redis Mirror

There are several ways to create an image of redis, which can be pulled directly from the repository.

First, let's talk about the life cycle of docker.

There are two ways to create a 1.docker:

1) you can run directly and skip the above steps. Take a chestnut:

When building a mirror, the port to be accessed is provided, and-p is the port-mapped

1. Create and start, set up port mapping

Docker run-p 127.0.0.1 6379 redis

Docker run

Note: docker run command: recreate a container and run the command, syntax:

Docker run [OPTIONS] IMAGES [COMMAND] [ARG]

The commonly used OPTIONS is:

-t assign a pseudo-input terminal to the container

-I run the container in interactive mode

-name specifies a name for the container

-d runs in background mode

-p port mapping

[root@vm000949] # docker run-p 127.0.0.1 it-- name= "my-redis-server"-d redis d66037100bddcd230e0c9955bdfb9b0dbae8ce4028a81534e1693ab95737c90a [root@vm000949 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESd66037100bdd redis "docker-entrypoint.sh" 6 seconds ago Up 5 seconds 127.0.1 seconds 6379-> 6379/tcp my-redis-server [root@vm000949 ~ ] # docker exec-it d66037100bdd redis-cli127.0.0.1:6379 > exit

Check the port mapping, where e24b3e0a7df0 is the container of redis.

[root@vm000949 ~] # docker port e24b3e0a7df06379/tcp-> 127.0.0.1 purl 6379

two。 Enter the redis container

Docker exec-it e24b3e0a7df0 redis-cli127.0.0.1:6379 > set day newDayOK127.0.0.1:6379 > get day "newDay" 127.0.0.1 set day newDayOK127.0.0.1:6379 6379 > exit

This is a simple creation process. A direct run is one that is created and started.

It's exhilarating to enter the familiar interface.

First of all, let's take a good look at how to use the docker exec command:

Docker exec [OPTIONS] CONTAINER COMMAND [ARG]

Among them, OPTIONS includes:

This way is to pull directly to the warehouse.

Further, by looking at the port mapping on the current virtual machine:

[root@vm000949 ~] # netstat-apn | grep 6379tcp 00 127.0.0.1 apn 6379 0.0.0.0 LISTEN 2270/docker-proxy-c

2) the run method is directly adopted above, and a more correct life cycle should be:

Create- > start- > exec

If the container has stopped, start directly, and then exec. Using run will create another docker according to the command

For example, to start over, you need to delete the current container.

[root@vm000949 ~] # docker rm 695d5f6afc27

Error response from daemon: You cannot remove a running container 695d5f6afc27415126a40384a868c751ba635df2d4d7fb578424bc1bd9167166. Stop the container before attempting removal or use-f

Prompt cannot delete a running container.

[root@vm000949 ~] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES695d5f6afc27 redis "docker-entrypoint.sh" 14 minutes ago Up 8 minutes 127.0.0.1 docker-entrypoint.sh 6379-> 6379/tcp ecstatic_lamarr

Sure enough, this container is running, stop the container and delete the container again

[root@vm000949 ~] # docker stop 695d5f6afc27695d5f6afc27

(2) docker create

1. Create it first, with a syntax similar to run

[root@vm000949] # docker create-p 127.0.0.1 it-- name= "my-redis-server"-d redisunknown shorthand flag:'d'in-dSee 'docker create-- help'.

I'll just change run to create. But it is conceivable that create still does not have this option, and how can there be-d if it is not running?

b. Try to create again. Remove-d

[root@vm000949] # docker create-p 127.0.0.1 it 6379-name= "my-redis-server" redisError response from daemon: Conflict. The name "/ my-redis-server" is already in use by container d66037100bddcd230e0c9955bdfb9b0dbae8ce4028a81534e1693ab95737c90a. You have to remove (or rename) that container to be able to reuse that name.

Well, what was created by run last time hasn't been deleted.

[root@vm000949 ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@vm000949 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESd66037100bdd redis "docker-entrypoint.sh" 3 minutes ago Exited (0) About a minute ago my-redis-server [root@vm000949 ~] # docker rm d66037100bddD66037100bdd

Delete and recreate:

[root@vm000949] # docker create-p 127.0.0.1 it-- name= "my-redis-server" redis2596bd8886b4095dc80e23315a5e073addb50fc9aa959456e026e6ca31676d28 [root@vm000949] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2596bd8886b4 redis "docker-entrypoint.sh" 8 seconds ago Created my-redis-server

Start the container:

[root@vm000949 ~] # docker start my-redis-servermy-redis-server [root@vm000949 ~] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2596bd8886b4 redis "docker-entrypoint.sh" About a minute ago Up 3 seconds 127.0.0.1 docker-entrypoint.sh 6379-> 6379/tcp my-redis-server enters the container: [root@vm000949 ~] # docker exec-it my-redis-server redis-cli127.0.0.1:6379 > exit

Remember that redis is divided into server side and client side. If you are installing redis-server, you need to run twice, one is server, the other is client, stop, start again, and then exec in.

[root@vm000949 ~] # docker stop my-redis-servermy-redis-server [root@vm000949 ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2596bd8886b4 redis "docker-entrypoint.sh" 7 minutes ago Exited (0) 5 seconds ago my-redis-server [root@vm000949 ~] # docker start my-redis-servermy-redis-server [root@vm000949 ~] # docker exec-it my -redis-server redis-cli127.0.0.1:6379 >

From the above two ways, we can see that the life cycle comparison of create- > start- > exec is intuitive. Among them, the Docker run command includes two life cycles: create and start.

Finally: docker log files are placed under / var/lib/docker/containers/, each docker has a corresponding file, cat its-json.log file to get the log file.

In disk space, log files may take up a lot of space and need to be cleaned up.

After reading the above, do you have any further understanding of how to create a redis image in docker? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report