docker命令
安装docker
- yum -y install docker
- docker开机自动启动:systemctl enable docker
- 启动docker服务: systemctl start docker
- 停止docker服务: systemctl stop docker
- 重启docker服务:systemctl restart docker
- 查看docker服务状态:systemctl status docker
安装docker-compose
- curl -L “https://github.com/docker/compose/releases/download/1.28.3/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
拉取镜像
docker pull xxx
显示所有镜像
docker images
创建容器
docker pull rabbitmq:management
docker run -d --name "jt_rabbitmq" -p 5672:5672 -p 15672:15672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=886291 rabbitmq:management
docker pull redis
docker run -d --name "redis01" -p 6379:6379 redis:latest --requirepass "1234qwer" --appendonly yes
docker pull mysql:5.7
docker run -d --name "jt_mysql" -p 3308:3306 -e MYSQL_ROOT_PASSWORD=886291 mysql:5.7
参数讲解:
- docker run - 创建一个容器
- -d 后台运行
- -p 端口映射 (格式: 主机(宿主)端口:容器端口)
- rabbitmq:management (格式 REPOSITORY:TAG),如果不指定tag,默认使用最新的
- –name “xxx” 为容器指定一个名称
列举当前运行的容器
docker ps
列举所有容器
docker ps -a
进入后台运行的容器
docker exec -it apache /bin/bash
检查容器内部信息
docker inspect 容器名称
删除镜像
docker rmi 镜像ID
启动某个容器
docker start 容器ID
停止某个容器
docker stop 容器ID
删除某个容器
docker rm 容器ID
查看容器日志
docker logs 容器ID
docker-compose命令
一键安装基础软件
version: '2'
services:
mysql:
image: mysql:5.7
container_name: mysql
restart: always
privileged: true
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=886291
volumes:
- /data/mysql/log:/var/log/mysql
- /data/mysql/data:/var/lib/mysql
- /data/mysql/conf:/etc/mysql
redis:
image: redis
container_name: redis
restart: always
privileged: true
ports:
- 6379:6379
volumes:
- /data/redis/data:/data
- /data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf
rabbitmq:
image: rabbitmq:management
container_name: rabbitmq
restart: always
privileged: true
environment:
- RABBITMQ_DEFAULT_USER=admin
- RABBITMQ_DEFAULT_PASS=886291
hostname: rabbitmq1
ports:
- 5672:5672
- 15672:15672
volumes:
- /data/rabbitmq/rabbitmq:/var/lib/rabbitmq
minio:
image: minio/minio:RELEASE.2021-04-22T15-44-28Z
#image: minio/minio:RELEASE.2021-06-17T00-10-46Z
container_name: minio
restart: always
privileged: true
ports:
- 9000:9000
command: server /data
environment:
- MINIO_ACCESS_KEY=jianda
- MINIO_SECRET_KEY=jianda123
volumes:
- /data/minio/data:/data
- /data/minio/config:/root/.minio