Docker Redis Introduction

Docker-compose >>

Getting started with Docker Redis

Installing Docker (CentOS)

💻 Terminal

Starting Docker

💻 Terminal

Checking the Docker version

💻 Terminal

Pulling the latest Redis image

💻 Terminal

Pulling a Redis image with a specific version

💻 Terminal

Checking Redis images

💻 Terminal

Running a Redis server

💻 Terminal

-d: run in the background

Connecting with redis-cli from Docker

💻 Terminal

Connecting with redis-cli on the host: use the mapped port 6379.

💻 Terminal

Connecting to the Docker Linux shell

💻 Terminal

redis.conf for Docker

Create the file /root/docker/redis-5.0.3/6001/redis.conf.
redis.conf example
📄 redis.conf

  • If you set daemonize yes, it will not start.
  • Set protected-mode no, and comment out bind.
  • Specify the working dir. Use "/data", a directory inside the Docker image.
  • When installing as Redis Cluster: specify cluster-announce-ip and port. If you do not specify cluster-announce-ip, CLUSTER NODES may show a different IP.

Run with a specified redis.conf file: specify a volume

💻 Terminal


Docker commands

  • docker version: show the Docker version
  • netstat -tnlp: check ports and processes
  • Uninstall old versions: remove previous versions
  • 💻 Terminal
  • docker info: show Docker information
  • 💻 Terminal
  • docker run: run a container
    docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
  • 💻 Terminal
  • docker ps: list containers
    docker ps [OPTIONS]
    When network_mode: host is used, PORTS is not shown.
  • 💻 Terminal
    • -a, --all: list all containers, including stopped ones.
    • -q, --quiet: show only container IDs.
      Used like this: docker stop $(docker ps -q)
    • 💻 Terminal
    • -l, --latest: show the most recently created container.
    • -n, --last: show the n most recently created containers.
    • 💻 Terminal
    • -s, --size: also show container size.
    • 💻 Terminal
    • -f, --filter: filter the containers shown.
      Labels are specified in the docker-compose.yml file.
    • 💻 Terminal
    • --format: show selected fields.
      docker ps -a --format "{{.Names}}: {{.Image}} {{.Networks}} Status={{.Status}}"| sort
    • 💻 Terminal
  • docker logs: show container logs.
    docker logs [OPTIONS] CONTAINER
    • docker logs redis6001
    • docker logs -f redis6001   -> same as tail -f
    • docker logs -t redis6001   -> show timestamps
    • journalctl -f -u docker.service   -> available on CentOS.
  • docker inspect: show container and image details.
    docker inspect [OPTIONS] NAME|ID [NAME|ID...]
  • docker top: show container process information.
    docker top CONTAINER
  • 💻 Terminal
  • docker kill: kill a container.
    docker kill [OPTIONS] CONTAINER [CONTAINER...]
  • docker cp: copy files from the container filesystem to the host OS filesystem, or copy host OS files into the container filesystem.
    docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH
    docker cp [OPTIONS] SRC_PATH CONTAINER:DEST_PATH
  • 💻 Terminal
  • docker port: show mapped port information.
    docker port CONTAINER [PRIVATE_PORT[/PROTO]]
    Not shown when network_mode=host.
  • docker restart: restart a container.
    docker restart [OPTIONS] CONTAINER [CONTAINER...]
  • docker stop: stop a container.
    docker stop [OPTIONS] CONTAINER [CONTAINER...]
  • docker start: start a container.
    docker start [OPTIONS] CONTAINER [CONTAINER...]
  • docker stats: continuously update and show container usage, like the Linux top command.
    docker stats [OPTIONS] [CONTAINER...]
    docker stats: in this case IDs are shown, so it is hard to tell which container is which.
  • 💻 Terminal
    docker stats redis6001 redis6002: specify container names.
    💻 Terminal
    docker stats $(docker ps -a --format "{{.Names}}" | sort): extract container names, sort them, and pass them in.
    💻 Terminal
  • docker rename: rename a container.
    docker rename CONTAINER NEW_NAME
  • docker pause: pause (suspend/freeze) a container. This uses the cgroups freezer. When paused, process state and contents are preserved, but CPU scheduling does not run. docker ps shows Status as Paused, and stats shows CPU usage as 0.00%.
    docker pause CONTAINER [CONTAINER...]
  • docker unpause: unpause (unsuspend/unfreeze) a paused container.
    docker unpause CONTAINER [CONTAINER...]
  • docker rm: remove a container.
    docker rm [OPTIONS] CONTAINER [CONTAINER...]
    docker rm $(docker ps -a -q --filter 'exited!=0')
  • docker save: save an image as a tar file.
    docker save [OPTIONS] IMAGE [IMAGE...]
    docker save -o redis2.tar redisgate/redis:5.0.3
  • docker load: load a tar file into the image store.
    docker load [OPTIONS]
    docker load -i redis2.tar

Other useful commands

  • Connect to a container shell
    docker exec -it redis6001 /bin/bash
  • Check ports
    netstat -tnlp
    lsof -i -nP | grep LISTEN | awk '{print $(NF-1)" "$1}' | sort -u
  • View port forwarding information when Network_mode=bridge
    iptables -t nat -L -n
  • Port forwarding settings when Network_mode=bridge
  • [root]# cat /proc/sys/net/ipv4/ip_forward
    0
    [root]# sysctl -w net.ipv4.ip_forward=1       set  
    net.ipv4.ip_forward = 1
    [root]# cat /proc/sys/net/ipv4/ip_forward       verify  
    1

    Edit sysctl.conf so the changed value still applies after reboot.

    [root]# vi /etc/sysctl.conf
    net.ipv4.ip_forward = 1

    You do not need to forward each port individually with firewall-cmd.


Docker-compose >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.