docker_intro
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
- docker info: show Docker information
- docker run: run a container
docker run [OPTIONS] IMAGE [COMMAND] [ARG...] - docker ps: list containers
docker ps [OPTIONS]
When network_mode: host is used, PORTS is not shown. - -a, --all: list all containers, including stopped ones.
- -q, --quiet: show only container IDs.
Used like this: docker stop $(docker ps -q) - -l, --latest: show the most recently created container.
- -n, --last: show the n most recently created containers.
- -s, --size: also show container size.
- -f, --filter: filter the containers shown.
Labels are specified in the docker-compose.yml file. - --format: show selected fields.
docker ps -a --format "{{.Names}}: {{.Image}} {{.Networks}} Status={{.Status}}"| sort - 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 - 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 - 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. - 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
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
💻 Terminal
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
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
net.ipv4.ip_forward = 1
You do not need to forward each port individually with firewall-cmd.
| Docker-compose >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
