Last active
May 26, 2020 14:48
-
-
Save tonysm/fd49af9f5524da66939f97b6f931ad30 to your computer and use it in GitHub Desktop.
12-factors-with-docker-code-samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = express() | |
const port = 3000 | |
-app.get('/', (req, res) => res.send('Hello World!')) | |
+app.get('/', (req, res) => res.send('Hello World 2.0.0!')) | |
app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:13.3.0 | |
WORKDIR /app | |
RUN apt-get update && apt-get install -y git | |
COPY package.json package-lock.json /app/ | |
RUN npm ci | |
COPY . /app | |
EXPOSE 3000 | |
CMD ["npm", "run", "serve"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ make build | |
docker build -t tonysm/node-app-docker:2.0.0 . | |
Sending build context to Docker daemon 2.065MB | |
Step 1/8 : FROM node:13.3.0 | |
---> 2af77b226ea7 | |
Step 2/8 : WORKDIR /app | |
---> Using cache | |
---> 07c5be8e9cde | |
Step 3/8 : RUN apt-get update && apt-get install -y git | |
---> Using cache | |
---> 9285fc2a80c2 | |
Step 4/8 : COPY package.json package-lock.json /app/ | |
---> Using cache | |
---> b5fb084d0c2a | |
Step 5/8 : RUN npm ci | |
---> Using cache | |
---> 19482a7d821a | |
Step 6/8 : COPY . /app | |
---> e1e469c7e35c | |
Step 7/8 : EXPOSE 3000 | |
---> Running in 3f19795b571f | |
Removing intermediate container 3f19795b571f | |
---> ad14d5378b2d | |
Step 8/8 : CMD ["npm", "run", "serve"] | |
---> Running in dfa2ff542a49 | |
Removing intermediate container dfa2ff542a49 | |
---> 280c53c0f03d | |
Successfully built 280c53c0f03d | |
Successfully tagged tonysm/node-app-docker:2.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
app: | |
build: tonysm/myapp:1.0.0 | |
ports: | |
- "80:80" | |
environment: | |
APP_NAME: "Laravel" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --rm -e "APP_NAME=Laravel" tonysm/myapp:1.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: myapp-deploy | |
spec: | |
selector: | |
matchLabels: | |
app: myapp-pod | |
template: | |
metadata: | |
labels: | |
app: myapp-pod | |
spec: | |
imagePullSecrets: | |
- name: regcred | |
containers: | |
- envFrom: | |
- secretRef: | |
name: myapp-secrets | |
name: myapp-app | |
image: tonysm/myapp:1.0.0 | |
ports: | |
- containerPort: 80 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Secret | |
metadata: | |
name: myapp-secrets | |
type: Opaque | |
stringData: | |
APP_NAME: "Laravel" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = express() | |
const port = 3000 | |
app.get('/', (req, res) => res.send('Hello World!')) | |
app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --rm -it -p "3000:3000" tonysm/myapp:1.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
EXPOSE 3000 | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: myapp-svc | |
spec: | |
ports: | |
- port: 80 | |
targetPort: 3000 | |
selector: | |
app: myapp-pod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.7' | |
services: | |
web: | |
image: tonysm/laravel-app:1.0.0 | |
ports: | |
- "80:80" | |
deploy: | |
replicas: 2 | |
worker: | |
image: tonysm/laravel-app:1.0.0 | |
command: php artisan queue:work --tries=3 | |
deploy: | |
replicas: 4 | |
scheduler: | |
image: tonysm/laravel-app:1.0.0 | |
command: php artisan scheduler:run | |
deploy: | |
replicas: 1 | |
update_config: | |
order: stop-first # we don't want 2 schedulers running | |
delay: 60s # it tells Swarm to try running it every minute | |
restart_policy: | |
condition: any # since the command exists, it should keep restarting it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment