The compose file defines an application with one service `angular`. The image for the service is built with the Dockerfile inside the `angular` directory (build parameter).
When deploying the application, docker-compose maps the container port 4200 to the same port on the host as specified in the file.
When deploying the application, dockercompose maps the container port 4200 to the same port on the host as specified in the file.
Make sure port 4200 is not being used by another container, otherwise the port should be changed.
## Deploy with docker-compose
## Deploy with dockercompose
```
$ docker-compose up -d
$ dockercompose up -d
Creating network "angular_default" with the default driver
Building angular
Step 1/7 : FROM node:10
@ -63,5 +63,5 @@ After the application starts, navigate to `http://localhost:4200` in your web br
The compose file defines an application with two services `web` and `db`. The image for the web service is built with the Dockerfile inside the `app` directory (build parameter).
When deploying the application, docker-compose maps the container port 80 to port 80 of the host as specified in the file.
When deploying the application, dockercompose maps the container port 80 to port 80 of the host as specified in the file.
Make sure port 80 on the host is not being used by another container, otherwise the port should be changed.
> ℹ️**_INFO_**
@ -36,10 +36,10 @@ Make sure port 80 on the host is not being used by another container, otherwise
> You still can use the MS SQL Server image by uncommenting the following line in the Compose file
> `#image: mcr.microsoft.com/mssql/server`
## Deploy with docker-compose
## Deploy with dockercompose
```
$ docker-compose up -d
$ dockercompose up -d
Creating network "aspnet-mssql_default" with the default driver
Building web
Step 1/13 : FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
@ -71,5 +71,5 @@ After the application starts, navigate to `http://localhost:80` in your web brow
@ -4,11 +4,11 @@ This example defines a basic setup for a Minecraft server. More details on the M
Project structure:
```
.
├── docker-compose.yaml
├── compose.yaml
└── README.md
```
[_docker-compose.yaml_](docker-compose.yaml)
[_compose.yaml_](compose.yaml)
```
services:
minecraft:
@ -20,15 +20,15 @@ services:
- "~/minecraft_data:/data"
```
When deploying this setup, docker-compose maps the Minecraft server port 25565 to
When deploying this setup, dockercompose maps the Minecraft server port 25565 to
the same port of the host as specified in the compose file. The Minecraft client application can connect to this port directly.
This example maps the Minecraft data folder holding all game storage to ~/minecraft_data on the host.
## Deploy with docker-compose
## Deploy with dockercompose
```
$ mkdir -p ~/minecraft_data
$ docker-compose up -d
$ dockercompose up -d
WARNING: Some services (minecraft) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
Creating network "minecraft_default" with the default driver
Creating minecraft_minecraft_1 ... done
@ -49,7 +49,7 @@ CONTAINER ID IMAGE COMMAND CREATED
After running `docker-compose up`, the minecraft server takes a bit of time to initialize Minecraft world. You can follow the progress:
The compose file defines a stack with two services `prometheus` and `grafana`.
When deploying the stack, docker-compose maps port the default ports for each service to the equivalent ports on the host in order to inspect easier the web interface of each service.
When deploying the stack, dockercompose maps port the default ports for each service to the equivalent ports on the host in order to inspect easier the web interface of each service.
Make sure the ports 9090 and 3000 on the host are not already in use.
## Deploy with docker-compose
## Deploy with dockercompose
```
$ docker-compose up -d
$ dockercompose up -d
Creating network "prometheus-grafana_default" with the default driver
Creating volume "prometheus-grafana_prom_data" with default driver
...
@ -61,5 +61,5 @@ Navigate to `http://localhost:9090` in your web browser to access directly the w
Stop and remove the containers. Use `-v` to remove the volumes if looking to erase all data.
- **Dev as close to prod as you can**. docker-compose builds a local development image that is just like production image except for the below dev-only features needed in image. Goal is to have dev env be as close to test and prod as possible while still giving all the nice tools to make you a happy dev.
- **Dev as close to prod as you can**. dockercompose builds a local development image that is just like production image except for the below dev-only features needed in image. Goal is to have dev env be as close to test and prod as possible while still giving all the nice tools to make you a happy dev.
- **Prevent needing node/npm on host**. Installs `node_modules` outside app root in container so local development won't run into a problem of bind-mounting over it with local source code. This means it will run `npm install` once on container build and you don't need to run npm on host or on each docker run. It will re-run on build if you change `package.json`.
- **One line startup**. Uses `docker-compose up` for single-line build and run of local development server.
- **Edit locally while code runs in container**. docker-compose uses proper bind-mounts of host source code into container so you can edit locally while running code in Linux container.
- **Use nodemon in container**. docker-compose uses nodemon for development for auto-restarting node in container when you change files on host.
- **Enable debug from host to container**. opens the inspect port 9229 for using host-based debugging like chrome tools or VS Code. Nodemon enables `--inspect` by default in docker-compose.
- **Edit locally while code runs in container**. dockercompose uses proper bind-mounts of host source code into container so you can edit locally while running code in Linux container.
- **Use nodemon in container**. dockercompose uses nodemon for development for auto-restarting node in container when you change files on host.
- **Enable debug from host to container**. opens the inspect port 9229 for using host-based debugging like chrome tools or VS Code. Nodemon enables `--inspect` by default in dockercompose.
- **Provides VSCode debug configs and tasks for tests**. for Visual Studio Code fans, `.vscode` directory has the goods, thanks to @JPLemelin.
- **Small image and quick re-builds**. `COPY` in `package.json` and run `npm install`**before**`COPY` in your source code. This saves big on build time and keep container lean.
- **Bind-mount package.json**. This allows adding packages in realtime without rebuilding images. e.g. `dce node npm install --save <package name>`
@ -18,19 +18,19 @@
### Production-minded Features
- **Use Docker build-in healthchecks**. uses Dockerfile `HEALTHCHECK` with `/healthz` route to help Docker know if your container is running properly (example always returns 200, but you get the idea).
- **Proper NODE_ENV use**. Defaults to `NODE_ENV=production` in Dockerfile and overrides to `development` in docker-compose for local dev.
- **Don't add dev dependencies into production image**. Proper `NODE_ENV` use means dev dependencies won't be installed in container by default. Using docker-compose will build with them by default.
- **Proper NODE_ENV use**. Defaults to `NODE_ENV=production` in Dockerfile and overrides to `development` in dockercompose for local dev.
- **Don't add dev dependencies into production image**. Proper `NODE_ENV` use means dev dependencies won't be installed in container by default. Using dockercompose will build with them by default.
- **Enables proper SIGTERM/SIGINT for graceful exit**. Defaults to `node index.js` rather then npm for allowing graceful shutdown of node. npm doesn't pass SIGTERM/SIGINT properly (you can't ctrl-c when running `docker run` in foreground). To get `node index.js` to graceful exit, extra signal-catching code is needed. The `Dockerfile` and `index.js` document the options and links to known issues.
- **Use docker-stack.yml example for Docker Swarm deployments**.
### Assumptions
- You have Docker and Docker-Compose installed (Docker for Mac, Docker for Windows, get.docker.com and manual Compose installed for Linux).
- You have Docker and docker compose installed (Docker for Mac, Docker for Windows, get.docker.com and manual Compose installed for Linux).
- You want to use Docker for local development (i.e. never need to install node/npm on host) and have dev and prod Docker images be as close as possible.
- You don't want to loose fidelity in your dev workflow. You want a easy environment setup, using local editors, node debug/inspect, local code repo, while node server runs in a container.
- You use `docker-compose` for local development only (docker-compose was never intended to be a production deployment tool anyway).
- The `docker-compose.yml` is not meant for `docker stack deploy` in Docker Swarm, it's meant for happy local development. Use `docker-stack.yml` for Swarm.
- The `compose.yaml` is not meant for `docker stack deploy` in Docker Swarm, it's meant for happy local development. Use `docker-stack.yml` for Swarm.
### Getting Started
@ -46,7 +46,7 @@ If this was your Node.js app, to start local development you would:
- Compose should detect if you need to rebuild due to changed package.json or Dockerfile, but `docker-compose build` works for manually building.
- Be sure to use `docker-compose down` to cleanup after your done dev'ing.
If you wanted to add a package while docker-compose was running your app:
If you wanted to add a package while dockercompose was running your app: