Docker
View running containers
docker psView all containers
docker ps -aView container configuration
docker inspect container-nameView container logs
docker logs container-nameDisplay all images
docker image lsRemove a container
docker rm container-nameRemove an image
docker rmi imagenameremoves any unused containers
docker system prune -aremoves any unused volumes
docker volume prune
docker-compose
cd into the directory where contains docker-compose.yml first!
docker-compose up -ddocker-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
-hoption - 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: