Awesome Docker Compose Examples
i created a docker compose example on github
Docker-compose, two container example. Can you explain to me why this works?
I think other people have hit most of our questions directly so I'm not going to recover that ground.
Instead, I would offer a different way of thinking about your Dockerfile and Docker-Compose. Your Dockerfile dictates the setup of your container (what goes in the image), and some defaults for its behavior (things like a default CMD, or an entrypoint file).
Docker-Compose is more akin to a user-friendly interface for running complex docker container run [... options] <container_name> commands.
Instead of having to run containers commands inundated with option flags, you run them through docker-compose, and your compose file fills in the options for you. So you can do things like connect to different networks, mount volumes, send secrets, create ENV vars, etc. But none of these things influences your images themselves; at most you might override some defaults otherwise defined in you Dockerfile.
Your question about CMD is a great example. Outside of compose you could run a container from your image and Docker would use the CMD from your Dockerfile. But called through compose, you can override this setting. It's super useful for things like overriding the CMD your containers start with when developing locally. You might want to run a dev-server as your default start command with compose, but leave the image built so it defaults to a production server startup.
More on reddit.comDocker Compose Tutorial
Thanks. That's good. The official documentation is too dense for a beginner (but excellent once you break the initial barrier). Your blog helps on these initial steps.
More on reddit.comVideos
Hi r/selfhosted,
since my last post I've cleaned my repository on GitHub with various Docker Compose examples. I've added a clean readme, issue templates and also short descriptions for each currently available compose project (aligned to the popular awesome-selfhosted repo).
I'll update the repository regularly if I come across bugs or something note-worthy. For example, if a cool project does not yet provide a docker-compose.yml or if the setup is a bit more complicated, combining various docker images with required config files etc. (like traefik or a grafana monitoring stack combining multiple images like promtail, influxdb, telegraf and so on).
Feel free to check it out if you haven't yet:
https://github.com/Haxxnet/Compose-Examples
If you have any missing compose examples that are not easily publicly available or already documented well enough by the project maintainer, feel free to issue PRs or open an issue with a request for a missing compose example. Happy to help out and extend the examples.
Cheers!
I created a docker compose example just for fun - it has a full stack of frontend, backend and database just as a way to learn more about docker compose.
I have no idea if anything is interested but posting it anyway (just my shout in the void I guess). If anyone has problems to compile it, just write.
https://github.com/sashoalm/docker-compose-example
This project shows how to create a full stack - Angular frontend (folder my-frontend), C# backend (folder my-backend), and MySQL database (folder my-database), and wire them together using Docker compose. There is an nginx reverse proxy (folder my-proxy) which routes traffic to the frontend and backend. To build and run it, just run "docker compose up" at the project's root folder. The server will be available at http://localhost:8080
When running, it shows just one table which displays numbers. You can add numbers. The frontend calls the backend, which stores the numbers in the database. The database is seeded with seed.sql.