STEPS INVOLVED RUNNING REDIS AS DOCKER IMAGE
First the run redis as docker image we need to search for appropriate docker image. To do the same just type command docker search redis at the terminal
By default docker will run the latest version available. If a particular version was required we can specify “that as a tag suppose we require to run 3.2 the command would be
docker run –d redis:3.2.
So the launched redis container is running in the background same can be check using the command docker ps command lists all running containers,the image used to start the container and uptime.
Further the command docker logs <friendly-name | container-id> will display messages the container has written to standard error or standard out.
Now as the REDIS container is running but we can’t still access the redis the reason is a service needs to accessible by a process not running in a container , then the ports needs to be exposed via the HOST.
To resolve it we will give a friendly name to the redis container and will bound it to port using –p <host-port>:<container-port> option.
The command will be :-
docker run –d –name redisHostPort –p 6379:6379 redis:latest
By default, the port on the host is mapped to 0.0.0.0, which means all IP addresses. Us can specify a particular IP address when us define the port mapping, for example, -p 127.0.0.1:6379:6379
Containers are designed to be stateless. Binding directories (also known as volumes) is done using the option -v <host-dir>:<container-dir>. When a directory is mounted, the files which exist in that directory on the host can be accessed by the container and any data changed/written to the directory inside the container will be stored on the host. This allows us to upgrade or change containers without losing usr data
Any data which needs to be saved on the Docker Host, and not inside containers, should be stored in /opt/docker/data/redis.
docker allows us to use $PWD as a placeholder for the current directory.