Docker
View running containers
docker ps
View all containers
docker ps -a
View container configuration
docker inspect container-name
View container logs
docker logs container-name
Display all images
docker image ls
Remove a container
docker rm container-name
Remove an image
docker rmi imagename
removes any unused containers
docker system prune -a
removes any unused volumes
docker volume prune
docker-compose
cd into the directory where contains docker-compose.yml first!
docker-compose up -d
docker-compose down
Mysql
- You can then connect to the server using
mysql
, just as you connect to any Mysql instance:mysql -h ip -u username -p
- If you don’t have mysql installed locally, you can run it from the Docker container:
docker exec -it mysql_container bash
- check version:
mysql> SELECT VERSION();
Redis
- If you have redis-cli installed locally,you can then connect to the server using
redis-cli
, just as you connect to any Redis instance:redis-cli -h ip -a <password>
- To specify a different host name or an IP address, use the
-h
option - To set a different port, use
-p
-a
- To specify a different host name or an IP address, use the
- If you don’t have redis-cli installed locally, you can run it from the Docker container:
$ docker exec -it redis_container bash
- check server info:
info server
- check module:
module list
docker-compose.yml
services:
mysql:
image: mysql:latest
container_name: mysql_container
environment:
MYSQL_ROOT_PASSWORD: <password>
MYSQL_DATABASE: database_name
MYSQL_USER: username
MYSQL_PASSWORD: <password>
ports:
- "3306:3306"
command: --default-authentication-plugin=mysql_native_password --bind-address=0.0.0.0
volumes:
- mysql_data:/var/lib/mysql
restart: always
redis:
image: redis/redis-stack:latest
container_name: redis_container
command: ["redis-stack-server", "--requirepass", "<password>", "--bind", "0.0.0.0"]
ports:
- "6379:6379"
- "8001:8001" # RedisInsight web UI 默认端口
volumes:
- redis_data:/data
restart: always
volumes:
mysql_data:
redis_data: