{"id":22962127,"url":"https://github.com/actionanand/docker_multi-container","last_synced_at":"2026-05-06T20:33:55.670Z","repository":{"id":214250767,"uuid":"736060854","full_name":"actionanand/docker_multi-container","owner":"actionanand","description":"It's all about multi-Container Applications with Docker (Docker Compose included)","archived":false,"fork":false,"pushed_at":"2023-12-31T17:43:09.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T18:17:36.262Z","etag":null,"topics":["docker","docker-compose"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/actionanand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-26T21:56:57.000Z","updated_at":"2023-12-26T22:06:56.000Z","dependencies_parsed_at":"2023-12-31T18:29:03.495Z","dependency_job_id":null,"html_url":"https://github.com/actionanand/docker_multi-container","commit_stats":null,"previous_names":["actionanand/docker_multi-container"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actionanand%2Fdocker_multi-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actionanand%2Fdocker_multi-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actionanand%2Fdocker_multi-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actionanand%2Fdocker_multi-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/actionanand","download_url":"https://codeload.github.com/actionanand/docker_multi-container/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246748443,"owners_count":20827311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose"],"created_at":"2024-12-14T19:15:24.660Z","updated_at":"2026-05-06T20:33:50.625Z","avatar_url":"https://github.com/actionanand.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multi-Container Applications with Docker (Docker Compose included) (section 4)\r\n\r\n## Without Docker compose\r\n\r\n1. Create a network\r\n\r\n```bash\r\ndocker network create goals-net\r\n```\r\n\r\n2. Run MongoDB Container\r\n\r\n```shell\r\ndocker run -d --rm -v mongo-vol:/data/db --name mongodb -e MONGO_INITDB_ROOT_USERNAME=anand -e MONGO_INITDB_ROOT_PASSWORD=secret --network goals-net mongo:7.0\r\n```\r\n\r\n```python\r\ndocker run --name mongodb \\\r\n  -e MONGO_INITDB_ROOT_USERNAME=anand \\\r\n  -e MONGO_INITDB_ROOT_PASSWORD=secret \\\r\n  -v data:/data/db \\\r\n  --rm \\\r\n  -d \\\r\n  --network goals-net \\\r\n  mongo\r\n```\r\n\r\n3. Build Node API Image (backend)\r\n   \r\n    - Navigate to `backend` folder where `Dockerfile` exists and build the image\r\n\r\n```bash\r\ndocker build . -t actionanand/docker_multi-container_node\r\n```\r\n\r\n4. Run Node API Container\r\n\r\n```shell\r\ndocker run -d --rm --name docker_multi-container_node -e MONGODB_USERNAME=anand -e MONGODB_PASSWORD=secret -v logs:/app/logs -v /app/node_modules -v \"D:\\AR_extra\\rnd\\docker\\docker_multi-container\\backend:/app:ro\" --network goals-net -p 3002:80 actionanand/docker_multi-container_node\r\n```\r\n\r\nbelow command for mac, linux and wsl2\r\n\r\n```shell\r\ndocker run -d --rm --name docker_multi-container_node -e MONGODB_USERNAME=anand -e MONGODB_PASSWORD=secret -v logs:/app/logs -v /app/node_modules -v $(pwd)/backend:/app:ro --network goals-net -p 3002:80 actionanand/docker_multi-container_node\r\n```\r\n\r\n```python\r\ndocker run --name docker_multi-container_node \\\r\n  -e MONGODB_USERNAME=anand \\\r\n  -e MONGODB_PASSWORD=secret \\\r\n  -v logs:/app/logs \\\r\n  -v /Users/actionanand/development/docker/docker_multi-container/backend:/app:ro \\\r\n  -v /app/node_modules \\\r\n  --rm \\\r\n  -d \\\r\n  --network goals-net \\\r\n  -p 3002:80 \\\r\n  actionanand/docker_multi-container_node\r\n```\r\n\r\n5. Build React SPA Image\r\n\r\n   - Navigate to `frontend` folder where `Dockerfile` exists and build the image\r\n\r\n```bash\r\ndocker build . -t actionanand/docker_multi-container_react\r\n```\r\n\r\n6. Run React SPA Container\r\n\r\n```shell\r\ndocker run -d --rm -it --name docker_multi-container_react -p 3001:3000 -v \"D:\\AR_extra\\rnd\\docker\\docker_multi-container\\frontend\\src:/app/src:ro\" actionanand/docker_multi-container_react\r\n```\r\n\r\nbelow command for mac, linux and wsl2\r\n\r\n```shell\r\ndocker run -d --rm -it --name docker_multi-container_react -p 3001:3000 -v $(pwd)/frontend/src:/app/src:ro actionanand/docker_multi-container_react\r\n```\r\n\r\n```python\r\ndocker run --name docker_multi-container_react \\\r\n  -v /Users/actionanand/development/docker/docker_multi-container/frontend/src:/app/src:ro \\\r\n  --rm \\\r\n  -d \\\r\n  -p 3001:3000 \\\r\n  -it \\\r\n  actionanand/docker_multi-container_react\r\n```\r\n\r\n- `-it` should be added for frontend apps. They're for **interactive tty**. If not added, process will exit.\r\n\r\n7. You can visit at `http://localhost:3001/` to view the app.\r\n\r\n8. Stopping all Containers\r\n\r\n```shell\r\ndocker stop mongodb docker_multi-container_node docker_multi-container_react\r\n```\r\n\r\n## Docker compose\r\n\r\nDocker Compose is an **additional tool**, offered by the Docker ecosystem, which helps with **orchestration / management** of multiple Containers. It can also be used for single Containers to simplify building and launching.\r\n\r\n### Why?\r\n\r\nConsider this example:\r\n\r\n```shell\r\ndocker network create shop\r\ndocker build -t shop-node .\r\ndocker run -v logs:/app/logs --network shop --name shope-web shop-node\r\ndocker build -t shop-database\r\ndocker run -v data:/data/db --network shop --name shop-db shop-database\r\n```\r\n\r\nThis is a very simple (made-up) example - yet you got **quite a lot of commands** to execute and memorize to bring up all Containers required by this application.\r\n\r\nAnd you have to run (most of) these commands whenever you change something in your code or you need to bring up your Containers again for some other reason.\r\n\r\nWith Docker Compose, this gets much easier.\r\n\r\nYou can put your Container configuration into a `docker-compose.yaml` or `docker-compose.yml` file and then use just one command to bring up the entire environment: `docker-compose up`.\r\n\r\n### Docker Compose Files\r\n\r\nA `docker-compose.yaml` file looks like this:\r\n\r\n```yaml\r\nversion: \"3.8\" # version of the Docker Compose spec which is being used\r\nservices: # \"Services\" are in the end the Containers that your app needs\r\n  web:\r\n    build: # Define the path to your Dockerfile for the image of this container\r\n      context: .\r\n      dockerfile: Dockerfile-web\r\n    volumes: # Define any required volumes / bind mounts\r\n      - logs:/app/logs # will create volume as `docker_multi-container_logs`\r\n  db: # will create container name as `docker_multi-container_db_1`\r\n    build:\r\n      context: ./db\r\n      dockerfile: Dockerfile-web\r\n    container_name: containerName # custom name\r\n    volumes:\r\n      - data:/data/db\r\n    environment: \r\n      - MONGO_INITDB_ROOT_PASSWORD=secret\r\n      - MONGO_INITDB_ROOT_USERNAME=anand\r\n    networks:\r\n      - networkName # automatically ceated network name will be `docker_multi-container_default`, if not mentioned here\r\nvolumes: \r\n  data: # named valume should be declared at the end separately\r\n  logs:\r\n```\r\n\r\ndocker compose will automatically create `network` for all the services whichever defined under one file. We can also manually create if needed the deferent one.\r\n\r\nYou can conveniently edit this file at any time and you just have a short, simple command which you can use to bring up your Containers:\r\n\r\n```bash\r\ndocker-compose up\r\n```\r\n\r\n```bash\r\ndocker-compose up -d\r\n```\r\n\r\nYou can find the full (possibly intimidating - you'll only need a small set of the available options though) **list of configurations** [here](https://docs.docker.com/compose/compose-file/)\r\n\r\n**Important to keep in mind**: When using Docker Compose, you **automatically get a Network for all your Containers** - so you don't need to add your own Network unless you need multiple Networks!\r\n\r\n### Docker Compose Key Commands\r\n\r\nThere are two key commands:\r\n\r\n* `docker-compose up` : **Start all containers / services** mentioned in the Docker Compose file\r\n    * `-d` : Start in **detached mode**\r\n    * `--build` : **Force Docker Compose** to re-evaluate / **rebuild all images** (otherwise, it only does that if an image is missing. That means it'll serve the cached image only)\r\n\r\n* `docker-compose build` is used to just build the docker image\r\n\r\n* `docker-compose down` : **Stop and remove** all containers / services\r\n    * `-v` : **Remove all Volumes** used for the Containers - otherwise they stay around, even if the Containers are removed\r\n\r\n  So, to remove all generated named volums along with container, below command will help:\r\n\r\n  ```shell\r\n  docker-compose down -v\r\n  ```\r\n\r\nOf course, there are **more commands**. We see more commands in other sections (e.g. the \"Utility Containers\" and \"Laravel Demo\" sections) but you can of course also already dive into the [official command reference](https://docs.docker.com/compose/reference/)\r\n\r\n### Docker Images\r\n\r\n![image](https://github.com/actionanand/docker_multi-container/assets/46064269/b34b01c2-c3ba-4bb5-b634-c41c4db740fe)\r\n\r\n### Docker Containers\r\n\r\n![image](https://github.com/actionanand/docker_multi-container/assets/46064269/1d5a3965-50e0-43f1-bf58-9a4f8373c00f)\r\n\r\n### Docker Volumes\r\n\r\n![image](https://github.com/actionanand/docker_multi-container/assets/46064269/9eb1b2b7-229a-4141-a27f-3db0bd5c1e53)\r\n\r\n### Docker Networks\r\n\r\n![image](https://github.com/actionanand/docker_multi-container/assets/46064269/b0d12cc5-e1de-474b-8155-f6320c7c3f28)\r\n\r\n### Docker-compose - Shell commands\r\n\r\n![image](https://github.com/actionanand/docker_multi-container/assets/46064269/395db00c-36e0-4288-a68f-f934d7114bb2)\r\n\r\n\u003e The displayed localhost port `3000` is to access it inside the docker. This port will be exposed at port `3001` for our host machine. Please refer the `docker-compose.yaml` file for more details.\r\n\r\n![image](https://github.com/actionanand/docker_multi-container/assets/46064269/f710a030-7264-453e-9333-afe391dea013)\r\n\r\n## Output\r\n\r\nPoint your browser to `http://localhost:3001/`\r\n\r\n![image](https://github.com/actionanand/docker_multi-container/assets/46064269/702739dd-96d3-4736-9abe-1379e2238b11)\r\n\r\n### Docker Image's public URL\r\n\r\n* [actionanand/docker_multi-container_node](https://hub.docker.com/r/actionanand/docker_multi-container_node)\r\n* [actionanand/docker_multi-container_react](https://hub.docker.com/r/actionanand/docker_multi-container_react)\r\n\r\n## Associated repos:\r\n\r\n1. [Docker Basics](https://github.com/actionanand/docker_playground)\r\n2. [Managing Data and working with volumes](https://github.com/actionanand/docker_data_volume)\r\n3. [Docker Communication](https://github.com/actionanand/docker_communication)\r\n4. [Docker Multi-container with docker-compose](https://github.com/actionanand/docker_multi-container)\r\n5. [Docker Utility Containers \u0026 Executing Commands](https://github.com/actionanand/node-util)\r\n6. [Laravel with Docker](https://github.com/actionanand/laravel_with_docker)\r\n7. [Angular with Docker](https://github.com/actionanand/angular_with_docker)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factionanand%2Fdocker_multi-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factionanand%2Fdocker_multi-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factionanand%2Fdocker_multi-container/lists"}