A very basic docker-compose.yml
looks like this:
version: '2'
services:
hello_world:
image: ubuntu
command: [/bin/echo, 'Hello world']
This file is making it so that there's a hello_world
service, that's initialized from the ubuntu:latest
image and that, when it's run, it just runs echo 'Hello world'
If you're on the folder
directory (and it contains this docker-compose.yml
file), you can do docker-compose up
and you should see
Creating folder_hello_world_1
Attaching to folder_hello_world_1
hello_world_1 | Hello world
folder_hello_world_1 exited with code 0
This created the container from the ubuntu image, and ran the command that was specified on the docker-compose.yml
Docker-Compose
uses the folder name as the project name to prefix containers and networks. To set another project name, you can either call docker-compose --project-name NAME {up|down|...}
or you suppy a file called .env
next to your docker-compose.yml
and write COMPOSE_PROJECT_NAME=name
in it.
Better avoid long project names with hyphens (-) because docker compose bahaves strange with this kind of names.
Note: docker-compose allows you to run multiple docker containers on a single host. If you want to run multiple containers on more than one node, please refer to solution such as swarm / kubernetes.