forked from Fascinated/docs
55 lines
983 B
Markdown
55 lines
983 B
Markdown
---
|
|
title: How to use Docker Compose
|
|
description:
|
|
published: true
|
|
date: 2023-06-26T13:38:49.025Z
|
|
tags: docker, ubuntu, containerization, container, linux, server
|
|
editor: markdown
|
|
dateCreated: 2023-06-26T13:38:49.025Z
|
|
---
|
|
|
|
# How to use Docker Compose
|
|
|
|
Examples for using Docker Compose, specifically tested on Ubuntu 22.04.
|
|
|
|
## Prerequisites
|
|
|
|
- Docker installed on your system
|
|
- A user account with sudo privileges
|
|
|
|
## Examples
|
|
|
|
Base docker-compose.yml file:
|
|
|
|
```bash
|
|
version: "3"
|
|
services:
|
|
<service_name>:
|
|
image: <image>
|
|
container_name: <container_name>
|
|
restart: <restart-policy>
|
|
ports:
|
|
- "<host>:<container>"
|
|
volumes:
|
|
- <host>:<container>
|
|
environment:
|
|
- <key>=<value>
|
|
```
|
|
|
|
Nginx docker-compose.yml example:
|
|
|
|
```bash
|
|
version: "3"
|
|
services:
|
|
nginx:
|
|
image: nginx:latest
|
|
container_name: nginx
|
|
restart: always
|
|
ports:
|
|
- "80:80"
|
|
volumes:
|
|
- /home/nginx:/var/www/html
|
|
environment:
|
|
- TZ=Europe/London
|
|
```
|