The functions implemented in this article
Resolve the startup and failure of the redis container when starting redis.conf
Brief understanding of some configurations of redis.conf
Understanding Parameters of the docker run command
You will see a lot of useless information after opening redis.conf
We use the grep command to simply process it, and then you can see all the configuration information of redis.conf, but the command entered now cannot be edited
Execute the command: cat redis.conf | grep -v "#" | grep -v "^$"
Although the above will get all the configuration information of redis.conf It comes out, but it cannot be modified. We can output this content to another file. At this time, you can see a redis-test.conf file under redis.
Execute the command: cat redis. conf | grep -v "#" | grep -v "^$" ->redis-test.conf
At this time, it can be in redis-test.conf Modify some configuration information
#Here we first understand a few configurations, and the subsequent configurations will be written out sequentially in subsequent files
daemonize no: redis is not used as a daemon process by default, which is why if you use redis-server /redis/redis.conf directly without modifying the configuration file, starting redis will directly display a service. There is no way to operate this terminal. You can only open a new terminal to connect to redis
requirepass foobared: redis does not have a password to connect by default, but the password still needs to be set for security
bind 127.0.0.1: This configuration item is usually commented out directly. After this configuration is turned on, only the local machine can connect to redis
The above The configuration information is the three configuration information you need to know in this article
The docker run command is to create a new container
The following It is a command I use to create a container `docker run -itd --restart="always" --name redis -v /usr/local/docker/data:/data -v /usr/local/docker/redis.conf: /etc/redis.conf --net mynetwork -p 6380:6379 --ip 172.10.0.2 redis:4.0 redis-server /etc/redis.conf`
i : Open STDIN , used for console interaction
t: Allocate tty devices, which can support terminal login, the default is false
d: Specify the container to run Whether in the foreground or the background, the default is false
v: Mount the storage volume to the container and mount it to a directory in the container
- -net: The container uses its own customized network
-p: It is the port number
--restart: Specifies the restart after the container is stopped. Policy no: Do not restart when the container exits on-failure: Restart when the container fails to exit (return value is non-zero) always: Always restart when the container exits
After we know several parameters of redis.conf and several common parameters of docker run, we will solve the problem of direct failure when using redis.conf to start.
Then start creating the container. Some partners will find an error `WARNING: IPv4 forwarding is disabled. Networking will not work.`
Let’s solve it first This problem
Execute the command `vim /usr/lib/sysctl.d/00-system.conf`
Add the following code `net.ipv4.ip_forward=1`
Restart the network command `systemctl restart network`
There will be no problem if you execute it
Then enter the container and you will find our problem , exited directly after creating the container
Are you very depressed at this time, why did you exit directly. This is why in the above, we proposed some configuration information of redis.conf and docker run command parameters.
At this time, we are reviewing whether there is a `daemonize no` in redis.conf. This parameter is whether to execute as a daemon process. During the development process, we will turn on this configuration and configure it to yes.
Then let’s review that there is a parameter `-d` in the docker run command. This parameter is also executed as a daemon process.
It should be clear now that redis.conf conflicts with docker configuration
Open the configuration file and change the daemon process to no
#Then delete the redis container just created, execute the above command here, you can see that the container has now been created Successful and in the open state
At this time, when entering the container `docker exec -it redis /bin/bash`, you can see that we need to enter a password when connecting to redis-cli, which is also It is configured in redis.conf.
The above is Kaka’s solution to solve the problem of failure to start the Redis container using redis.conf
The above is the detailed content of Solve the problem of failure to start the Redis container using redis.conf. For more information, please follow other related articles on the PHP Chinese website!