You want to create an example of a docker compose file. How do you use docker-compose?
i. This assumes you have Docker installed and running. If you need assistance, see this posting.
ii. This assumes that you have installed docker-compose. If you need assistance, see this posting.
iii. This assumes the Docker host has access to the internet.
iv. Port 8080 is not being used (e.g., any containers that use this port are turned off). If you need to keep port 8080 open for another purpose, change the "8080" in the directions below.
1. Run these three commands:
mkdir dockercompose && cd dockercompose
echo "<h2>It worked\!</h2>" > webapp/index.html
2.a. Create a Dockerfile in the webapp directory. (You may want to run vi webapp/Dockerfile.)
2.b. This is the content for the Dockerfile:
RUN apt-get update \
&& apt-get install -y apache2
COPY index.html /var/www/html/
CMD ["apachectl", "-D", "FOREGROUND"]
3.a. Create a docker-compose.yml file. (You may want to run vi docker-compose.yml.)
3.b. This is the content of the docker-compose.yml file:
4. Run these commands:
echo "Welcome to Docker Compose Tutorial" >> webapp/index.html
docker-compose up -d
5. Open a web browser. Go to x.x.x.x:8080 where x.x.x.x is the external IP address of the server (or the result of "curl icanhazip.com on the back-end).
6. You should see these:
Welcome to Docker Compose Tutorial "
You are now done. (Remember that modifications to the index.html command will require you to use "docker-compose build" once again. New containers may conflict on port 8080 if you do not change the docker-compose.yml file or stop the containers from running.)
The above directions were adapted (but mostly copied) from Tecadmin.net.