用shell写一份可以在centos7部署docker并用docker部署nginx
时间: 2023-11-09 21:52:29 浏览: 49
Sure, I can provide you with a shell script to deploy Docker on CentOS 7 and deploy Nginx within Docker.
Here's the script:
```
#!/bin/bash
# Install Docker
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io -y
sudo systemctl start docker
sudo systemctl enable docker
# Download Nginx Docker image
sudo docker pull nginx
# Create a new Docker container for Nginx
sudo docker run --name my-nginx-container -p 80:80 -d nginx
```
This script will:
1. Install Docker on CentOS 7 using the official Docker repository.
2. Pull the latest Nginx Docker image from Docker Hub.
3. Create a new Docker container named `my-nginx-container`, which maps host port 80 to container port 80 (Nginx's default HTTP port), and runs it in detached mode.
To run this script, simply copy and paste it into a new file (e.g. `deploy-nginx.sh`), make it executable with `chmod +x deploy-nginx.sh`, and run it with `./deploy-nginx.sh`.
I hope this helps! Let me know if you have any questions.