Introduction
Create a file called compose.yaml
Here is a sample compose.yaml
services:
web:
build: .
ports:
- "8000:5000"
redis:
image: "redis:alpine"
Services:
Required Syntax. This is called a top level element. There are a few of these including (Services, Network, Volumnes, Configs, Secrets)
The commands available are documented here: https://docs.docker.com/compose/compose-file/05-services/ but the commands I use are listed below.
Web, Redis:
We are building 2 docker containers. One named Web, the other named Redis.
Build, Ports, Image:
There are instructions (or commands) used to help define the containers being constructed. These are described in detail below.
Docker File Commands
Build
Build is used to specify a docker file used to build the container.
Build .
Means to look for a file named ‘Dockerfile’ and use that as the basis of the build.
Build DockerFileWebsite.txt
Means to look for a file named ‘DockerFileWebsite.txt’ and use that as the basis of the build of the container.
Image
Image is a docker image you want to base your container on. You’ll do this if the image contains all you need.
Typically I start with a basic image and add files, variables, etc. I put all this information into a dockerfile instead. Then I would use the Build command rather than Image command.
Ports
Ports are used to map the ports you want to use to communicate with the container, vs the ports the process in the container needs to work with
ports:
-p 8088:80
This means we are going to have a port 8088. When information is passed to this container in port 8088, we will direct that information to port 80 inside the container.