linux配置docker和docker-compose
时间: 2023-12-18 19:29:48 浏览: 143
docker-compose-linux
以下是Linux配置Docker和Docker Compose的步骤:
1. 安装Docker:
```shell
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
docker --version
```
2. 将当前用户添加到docker组(可选):
```shell
sudo usermod -aG docker ${USER}
su - ${USER}
```
3. 安装Docker Compose:
```shell
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
```
4. 验证Docker和Docker Compose安装:
```shell
docker run hello-world
```
5. 创建docker-compose.yml文件并定义服务配置,例如:
```yaml
version: '3'
services:
web:
image: nginx:alpine
ports:
- "8080:80"
```
6. 使用docker-compose启动容器:
```shell
docker-compose up -d
```
7. 停止并移除容器:
```shell
docker-compose down
```
阅读全文