docker-compose.yml¶
This is a YAML file defining services, networks, and volumes for multi-container
Docker applications. In other words, all the parameters you have used with
docker run you could specify in a docker-compose.yml file. Then, with a
single command, create and start all the services with your configurations.
In this example, we will launch just one image, but keep in mind that a
docker-compose.yml file could specify more than one image at the same time.
Tip
For more information, see the Compose File Version 3 Reference
Move the default docker-compose.yml from shellhttpd.disabled to your folder:
mv ../shellhttpd.disabled/docker-compose.yml .
Read the docker-compose.yml file:
cat docker-compose.yml
docker-compose.yml:
version: '3.2'
services:
httpd:
image: hub.foundries.io/<factory>/shellhttpd:latest
restart: always
ports:
- 8080:${PORT-8080}
environment:
MSG: "${MSG-Hello world}"
Most of the parameters were already used in the previous commands. The only thing you need to change is the image parameter.
In the next tutorial, you will build and deploy the image with
FoundriesFactory and there the image with hub.foundries.io will be necessary.
For now, because you are still developing locally, you need to edit the image parameter to use the image you have built in the previous steps.
Change the image parameter to the name and tag we built locally shellhttpd:1.0:
gedit docker-compose.yml
docker-compose.yml:
version: '3.2'
services:
httpd:
# image: hub.foundries.io/<factory>/shellhttpd:latest
image: shellhttpd:1.0
restart: always
ports:
- 8080:${PORT-8080}
environment:
MSG: "${MSG-Hello world}"
Notice that the MSG variable is configured to use Hello world as default.
To run your docker-compose application, execute the docker-compose up --detach command.
docker-compose up --detach
- Where:
--detachor-d- Run containers in the background.
To verify the running containers:
docker ps
Example Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dbc969a5487d shellhttpd:1.0 "/usr/local/bin/http…" 3 minutes ago Up 3 minutes 0.0.0.0:8080->8080/tcp shellhttpd_httpd_1
Test the container with curl:
curl 127.0.0.1:8080
Example Output:
Hello world