slides.com/axelmonroy/docker-workshop/live
git
$ git
$ docker
$ docker-compose
$ docker run -p 8080:3000 axelmonroyx/hello:1
An image is a filesystem and parameters to use at runtime. It doesn’t have state and never changes.
$ docker images
Containers include the application and all of its dependencies, running as isolated processes in user space on the host operating system. they run on any computer, on any infrastructure, and in any cloud.
$ docker ps --all
$ docker pull node:6
$ docker run -it --rm node:6 /bin/bash
-i interactive keep container attach
-t tty shows console inside container
-rm remove the container when it exits
$ echo "console.log('Hello from container'); " >> hello.js
$ node hello.js
$ node -v
docker pull [IMAGE]:[VERSION]
$ docker run -it --name SuperContainer node:6 /bin/bash
$ docker ps
$ docker stop SuperContainer
$ docker ps --all
$ docker start SuperContainer
$ docker exec -it SuperContainer /bin/bash
$ git clone https://github.com/AxelMonroyX/workshop-docker-meetup.git
$ cd workshop-docker-meetup
https://github.com/AxelMonroyX/workshop-docker-meetup
FROM node:6
MAINTAINER Axel Monroy <xaxelmonroyx@gmail.com>
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
ENV DEBUG myapp:*
COPY . /usr/src/app
EXPOSE 3000
CMD [ "npm", "start" ]
$ docker build -t user/imageName .
$ docker push axelmonroyx/myapp
$ docker run -it --name Express-app axelmonroyx/express-app /bin/bash
$ exit
$ docker ps --all
$ docker start -i Express-app
$ exit
Directories (or files) that are outside of containers and exist as normal directories and files on the host filesystem.
Changes are reflected immediately as the directory on the container is simply
$ docker run -d --name SuperContainerWithVolume -v $PWD:/usr/src/app -w /usr/src/app -p 8080:3000 node:6 npm start
$ docker run -d --name SuperContainerWithVolume -v /Users/<path>:/usr/src/app -w /usr/src/app -p 8080:3000 node:6 npm start
$ docker run -d --name SuperContainerWithVolume -v //c/<path>:/usr/src/app -w /usr/src/app -p 8080:3000 node:6 npm start
$ echo "<h1>Hello from container, using volumes :D <h1>" >> public/html/index.html
Or change public/html/index.html and check enter here
$ git clone https://github.com/AxelMonroyX/workshop-docker-meetup.git
$ cd workshop-docker-meetup
https://github.com/AxelMonroyX/workshop-docker-meetup
$ docker run -d --name mongodb -p 27017 mongo:3.0
$ docker run -it --rm --link mongodb:db -v $PWD:/usr/src/app -w /usr/src/app -p 80:3000 node:6 npm start
$ docker run -d --name mongodb -p 27017 mongo:3.0
$ docker run -it --rm --link mongodb:db -v /Users/<path>:/usr/src/app -w /usr/src/app -p 80:3000 node:6 npm start
$ docker run -d --name mongodb -p 27017 mongo:3.0
$ docker run -it --rm --link mongodb:db -v //c/<path>:/usr/src/app -w /usr/src/app -p 80:3000 node:6 npm start
var MongoClient = require('mongodb').MongoClient
MongoClient.connect('mongodb://db', function (err, db) {
if (err) throw err
console.log("DB: CONNECTED TO THE DATABASE")
})
var MongoClient = require('mongodb').MongoClient
MongoClient.connect('mongodb://<dbuser>:<dbpassword>@127.0.1.1:27017/database', function (err, db) {
if (err) throw err
console.log("DB: CONNECTED TO THE DATABASE")
})
version: '2'
services:
node:
image: node:6
ports:
- "3000:3000"
environment:
- DEBUG=myapp:*
volumes:
- ./:/usr/src/app
working_dir: /usr/src/app
depends_on:
- mongo
links:
- mongo:db
command: /bin/bash -c "npm install && npm start"
mongo:
image: mongo:3
ports:
- "27017:27017"
volumes:
- ./docker/develop/data:/data/db
$ docker-compose up