Skip to content
Permalink
Browse files

Add aliases. Add nodejs example.

  • Loading branch information...
marcomontalbano committed Jun 7, 2019
1 parent bd50459 commit c9e40d72074622e6a41ccef2e2891a841fdb8d83
@@ -1,6 +1,13 @@
# Docker Bootcamp


## Topic

1. [Get Started](#get-started)
1. [Volumes](#volumes)
1. [Dockerfile](#dockerfile)
1. [Tips & Tricks](#tips--tricks)

## Get Started

Common commands:
@@ -36,6 +43,9 @@ Common `docker run` arguments are:
#### PHP + Apache

```sh
# interactive shell
docker run --rm -ti php:7.1-cli
docker run --rm -ti -p 8080:80 -v $(pwd)/example/apache-php/public:/usr/src/myapp -w /usr/src/myapp php:7.1-cli -S 0.0.0.0:80
docker run --rm -ti -p 8080:80 -v $(pwd)/example/apache-php/public:/usr/src/myapp -w /usr/src/myapp php:7.2-cli -S 0.0.0.0:80
docker run --rm -ti -p 8080:80 -v $(pwd)/example/apache-php/public:/usr/src/myapp -w /usr/src/myapp php:7.3-cli -S 0.0.0.0:80
@@ -46,16 +56,26 @@ docker stop my-apache-php-app
docker run --rm -ti -p 80:80 -v $(pwd)/example/apache-php/public:/var/www/html php:7.3-apache
```

#### Node.js

```sh
# iteractive shell
docker run --rm -ti node
docker run --rm -ti -v $(pwd)/example/nodejs:/www -w /www node npm install
docker run --rm -ti -v $(pwd)/example/nodejs:/www -w /www -p 3000:3000 node npm start
```

#### Jenkins + BlueOcean

```sh
docker run -u root --rm -d -p 49990:8080 -p 50000:50000 -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean
docker run -u root --rm -d -p 49990:8080 -p 50000:50000 --name jenkinsci -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean
# show containers
docker ps -a
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 2f76b46560bd jenkinsci/blueocean "/sbin/tini -- /usr/…" 10 minutes ago Up 10 minutes 0.0.0.0:50000->50000/tcp, 0.0.0.0:49990->8080/tcp nervous_dirac
# 2f76b46560bd jenkinsci/blueocean "/sbin/tini -- /usr/…" 10 minutes ago Up 10 minutes 0.0.0.0:50000->50000/tcp, 0.0.0.0:49990->8080/tcp jenkinsci
# execute bash command interactively in container ID '2f76b46560bd'
docker exec -it 2f76b46560bd bash
@@ -96,10 +116,33 @@ docker run --rm -it --privileged --pid=host justincormack/nsenter1
## Tips & Tricks


### Git
### Aliases

Instead of installing `git` you can use this alias.
Here a list of useful aliases:

```sh
alias git="docker run -ti --rm -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"
# git
alias git="docker run --rm -ti -v $(pwd):/git -v $HOME/.ssh:/root/.ssh alpine/git"
# node
export DOCKER_TAG_NODE=latest
alias node="docker run --rm -ti -v $(pwd):/www -w /www node:$DOCKER_TAG_NODE node"
alias npm="docker run --rm -ti -v $(pwd):/www -w /www node:$DOCKER_TAG_NODE npm"
node () {
docker run --rm -ti -v $(pwd):/www -w /www node:$1 node ${@:2};
}
npm () {
docker run --rm -ti -v $(pwd):/www -w /www node:$1 npm ${@:2};
}
# php
export DOCKER_TAG_PHP=latest
alias php="docker run --rm -ti -v $(pwd):/www -w /www php:$DOCKER_TAG_PHP php"
alias php-server="docker run --rm -ti -v $(pwd):/www -w /www -p 8080:8080 php:$DOCKER_TAG_PHP php -S 0.0.0.0:8080"
php () {
docker run --rm -ti -v $(pwd):/www -w /www php:$1 php ${@:2};
}
```
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
@@ -0,0 +1 @@
/node_modules
@@ -0,0 +1,16 @@
FROM node

WORKDIR /www

COPY package*.json ./

RUN npm install

# If you are building your code for production
# RUN npm ci --only=production

COPY . .

EXPOSE 3000

CMD ["npm", "start"]
@@ -0,0 +1,15 @@
# nodejs

```sh
# build image
docker build -t marcomontalbano/nodejs .
# show available images
docker images
# create container from an image
docker run --rm -d --name container-nodejs -p 3000:3000 marcomontalbano/nodejs
# stop container
docker stop container-nodejs
```
@@ -0,0 +1,19 @@
// Require the framework and instantiate it
const fastify = require('fastify')({ logger: true })

// Declare a route
fastify.get('/', async (request, reply) => {
return { hello: 'world' }
})

// Run the server!
const start = async () => {
try {
await fastify.listen(3000, '0.0.0.0')
fastify.log.info(`server listening on ${fastify.server.address().port}`)
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}
start()

0 comments on commit c9e40d7

Please sign in to comment.
You can’t perform that action at this time.