Docker 基本操作
Linux 中安装 Docker
yum update
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/dockerce.repo
yum install -y docker-ce
docker -v
Docker 进程相关命令
systemctl start docker
systemctl stop docker
systemctl restart docker
systemctl status docker
systemctl enable docker
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
配置镜像加速器
原因:Docker 默认的镜像下载速度很慢
采用阿里云的镜像加速器加速地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
每个用户的加速器地址都是不一样的
复制红框中的内容到 shell 终端中执行即可,配置后重启 docker
Docker 镜像相关命令
Docker 镜像查询网址:https://hub.docker.com/
docker images
docker images -q
docker search 镜像名称
docker pull 镜像名称
docker pull 镜像名称:版本号
docker rmi 镜像id
docker rmi `docker images -q`
Docker 容器相关命令
docker ps
docker ps -a
docker run 参数
docker exec -it 容器名称 /bin/bash
docker start 容器名称
docker start 容器id
docker stop 容器名称
docker stop 容器id
docker rm 容器名称
docker rm 容器id
docker inspect 容器名称
docker inspect 容器id
Docker 应用部署
安装 Tomcat
docker pull tomcat
docker run -id --name=my_tomcat \
-p 8080:8080 \
-v $PWD:/usr/local/tomcat/webapps \
tomcat
http://192.168.xxx.xxx:8080/test/index.html
安装 Nginx
docker search nginx
docker pull nginx
docker run -id --name=my_nginx \
-p 80:80 \
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html \
nginx
http://192.168.xxx.xxx
安装 MySQL
docker search mysql
docker pull mysql:5.6
docker run -id --name=my_mysql \
-p 3306:3306 \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:5.6
安装 Redis
docker search redis
docker pull redis:5.0
docker run -id --name=my_redis -p 6379:6379 redis:5.0
|