docker环境部署nginx、tomcat、redis
centos7 部署docker###
官网部署地址
https://docs.docker.com/engine/install/centos/
1、移除旧版docker
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2、安装依赖包
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
3、配置阿里镜像源
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4、安装最新docker
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
5、运行hello-world镜像
docker run hello-world
6、配置阿里云加速
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://bmmh6qxh.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
7、如果docker命令无法自动补全安装bash-completion重新打开终端即可
yum install -y bash-completion
二、docker环境部署nginx###
1、进入docker hub,查看并下载相关镜像的版本,网址www.hub.docker.com;
docker pull nginx:latest
2、创建nginx配置文件目录并运行容器
mkdir -p /usr/local/nginx/conf/conf.d
docker run --name nginx -d nginx:latest
拷贝容器内nginx配置日志文件到宿主机
docker cp nginx:/etc/nginx/conf.d/default.conf /usr/local/nginx/conf/conf.d
docker cp nginx:/usr/share/nginx/html /usr/local/nginx/
docker cp nginx:/var/log/nginx /usr/local/nginx/logs/
docker stop nginx
docker rm nginx
3、运行容器暴露端口,并将容器目录挂载至宿主机
docker run --name nginx -d -p 8002:80 \
-v /usr/local/nginx/html:/usr/share/nginx/html \
-v /usr/local/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /usr/local/nginx/logs/nginx:/var/log/nginx/ nginx
4、使用浏览器打开nginx
三、docker环境部署tomcat###
1、拉取镜像
docker pull tomcat:latest
2、运行tomcat容器,
docker run --name tomcat -d -p 8003:8080 tomcat:latest
3、使用浏览器打开
四、docker环境部署redis###
1、拉取镜像
docker pull redis:5.0.7
2、运行redis容器
docker run --name redis -d -p 36379:6379 redis:5.0.7
3、使用redis 连接工具测试
下一篇docekr环境部署mysql、kakka、mongodb和搭建私有redistry;