Slide 1

Slide 1 text

DOCKER CHIT-CHAT Davide Academy Pills

Slide 2

Slide 2 text

2 AGENDA ● Docker? ● docker vs docker-compose ● Useful commands ● Q&A

Slide 3

Slide 3 text

DOCKER IS NOT A VM ● Virtualize software, not hardware ● It’s faster! At least mom told my so... ● It’s Schrödinger simple

Slide 4

Slide 4 text

IMAGES vs CONTAINERS ● An image is a template, containing a series of instruction ● A container is the executable instance, result such instructions IMAGE CONTAINER CONTAINER CONTAINER

Slide 5

Slide 5 text

IMAGES vs CONTAINERS ● An image is a template, containing a series of instruction ● A container is the executable instance, result such instructions ● Images can be extended BASE_IMAGE IMAGE_ONE IMAGE_TWO FROM utnaf/BASE_IMAGE FROM utnaf/IMAGE_ONE

Slide 6

Slide 6 text

HOW TO DOCKER IMAGE?

Slide 7

Slide 7 text

HOW TO DOCKERFILE? https://github.com/utnaf/practical-docker

Slide 8

Slide 8 text

HOW TO DOCKERFILE? FROM node:14.15.0 WORKDIR /var/www COPY package*.json ./ RUN npm install COPY . ./ EXPOSE 3000 CMD ["npm", "start"]

Slide 9

Slide 9 text

HOW TO DOCKERFILE? FROM node:14.15.0 WORKDIR /var/www COPY package*.json ./ RUN npm install COPY . ./ EXPOSE 3000 CMD ["npm", "start"] Starting image

Slide 10

Slide 10 text

HOW TO DOCKERFILE? FROM node:14.15.0 WORKDIR /var/www COPY package*.json ./ RUN npm install COPY . ./ EXPOSE 3000 CMD ["npm", "start"] Starting image Set the base workdir

Slide 11

Slide 11 text

HOW TO DOCKERFILE? FROM node:14.15.0 WORKDIR /var/www COPY package*.json ./ RUN npm install COPY . ./ EXPOSE 3000 CMD ["npm", "start"] Starting image Set the base workdir Copy the files for dependencies installation

Slide 12

Slide 12 text

HOW TO DOCKERFILE? FROM node:14.15.0 WORKDIR /var/www COPY package*.json ./ RUN npm install COPY . ./ EXPOSE 3000 CMD ["npm", "start"] Starting image Set the base workdir Copy the files for dependencies installation Install dependencies

Slide 13

Slide 13 text

HOW TO DOCKERFILE? FROM node:14.15.0 WORKDIR /var/www COPY package*.json ./ RUN npm install COPY . ./ EXPOSE 3000 CMD ["npm", "start"] Starting image Set the base workdir Copy the files for dependencies installation Install dependencies Copy the rest of the files

Slide 14

Slide 14 text

HOW TO DOCKERFILE? FROM node:14.15.0 WORKDIR /var/www COPY package*.json ./ RUN npm install COPY . ./ EXPOSE 3000 CMD ["npm", "start"] Starting image Set the base workdir Copy the files for dependencies installation Install dependencies Copy the rest of the files Expose the port that the app is listening to

Slide 15

Slide 15 text

HOW TO DOCKERFILE? FROM node:14.15.0 WORKDIR /var/www COPY package*.json ./ RUN npm install COPY . ./ EXPOSE 3000 CMD ["npm", "start"] Starting image Set the base workdir Copy the files for dependencies installation Install dependencies Copy the rest of the files Expose the port that the app is listening to Entrypoint command

Slide 16

Slide 16 text

HOW TO DOCKERFILE? FROM node:14.15.0 WORKDIR /var/www COPY package*.json ./ RUN npm install COPY . ./ EXPOSE 3000 CMD ["npm", "start"] Starting image Set the base workdir Copy the files for dependencies installation Install dependencies Copy the rest of the files Expose the port that the app is listening to Entrypoint command docker build --tag my-image:1.0.0 . docker run -p "3000:3000" my-image:1.0.0

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j \ -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 19

Slide 19 text

docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j \ -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 20

Slide 20 text

docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j \ -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 21

Slide 21 text

docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j \ -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 22

Slide 22 text

docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 23

Slide 23 text

docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 24

Slide 24 text

docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 25

Slide 25 text

docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 26

Slide 26 text

docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

DOCKER COMPOSE TO THE RESCUE ● Tool for multi-container application ● YAML based ● Single command ● Works in all environments: dev, prod, CI, etc...

Slide 29

Slide 29 text

DOCKER COMPOSE TO THE RESCUE version: "2" services: frontend: image: my-image:1.0.0 networks: - myApp neo4j: image: neo4j:4.2 networks: - myApp ports: - 7474:7474 - 7687:7687 environment: - NEO4J_AUTH=neo4j/password - NEO4JLABS_PLUGINS=["apoc","graph-data-science"] volumes: - neo4j:/data networks: myApp: volumes: neo4j:

Slide 30

Slide 30 text

DOCKER COMPOSE TO THE RESCUE version: "2" services: frontend: image: my-image:1.0.0 networks: - myApp neo4j: image: neo4j:4.2 networks: - myApp ports: - 7474:7474 - 7687:7687 environment: - NEO4J_AUTH=neo4j/password - NEO4JLABS_PLUGINS=["apoc","graph-data-science"] volumes: - neo4j:/data networks: myApp: volumes: neo4j: docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2

Slide 31

Slide 31 text

DOCKER COMPOSE TO THE RESCUE docker run -d --network myApp --name frontend my-image:1.0.0 docker run -d --name neo4j -p "7474:7474" -p "7687:7687" \ -e NEO4J_AUTH='neo4j/password' \ -e NEO4JLABS_PLUGINS='["apoc","graph-data-science"]' \ -v 'neo4j-data:/data' \ --network myApp \ neo4j:4.2 docker-compose up -d

Slide 32

Slide 32 text

IMAGE Dockerfile docker build . docker run [IMAGE] CONTAINER CONTAINER CONTAINER CONTAINER docker-compose.yml docker-compose up

Slide 33

Slide 33 text

Relax Time + Questions

Slide 34

Slide 34 text

34 USEFUL COMMANDS

Slide 35

Slide 35 text

DOCKER # build the image from the given dockerfile docker build . docker build -t [image_name]:[version] # tag the image docker build -t [username]/[image_name]:[version] # add a DockerHub repository # run the image docker run [...options] [image_name]:[version] # DockerHub commands docker login docker push [username]/[image_name] docker pull [username]/[image_name]

Slide 36

Slide 36 text

DOCKER HUB

Slide 37

Slide 37 text

DOCKER HUB docker push utnaf/myApp docker pull utnaf/myApp docker pull utnaf/myApp docker pull utnaf/myApp docker pull utnaf/myApp docker pull utnaf/myApp

Slide 38

Slide 38 text

PROS ● Docker-based deploy ● Avoid passing the Dockerfile around ● Avoid building the image on every machine ● Has webhooks

Slide 39

Slide 39 text

DOCKER COMPOSE # start and stop the containers docker-compose up docker-compose up -d # start the container in detached mode docker-compose stop # stop the containers docker-compose down # stop **and remove** the containers # debug containers docker-compose logs # print the last logs docker-compose logs -f # print logs in follow mode docker-compose logs [container] # print the logs of the specified container docker-compose exec [container] [command] # run the command in the container docker-compose exec myApp bash # enter a bash session on the myApp container docker-compose ps # show the current status of the containers

Slide 40

Slide 40 text

DOCKER COMPOSE # start and stop the containers docker-compose up docker-compose up -d # start the container in detached mode docker-compose stop # stop the containers docker-compose down # stop **and remove** the containers # debug containers docker-compose logs # print the last logs docker-compose logs -f # print logs in follow mode docker-compose logs [container] # print the logs of the specified container docker-compose exec [container] [command] # run the command in the container docker-compose exec myApp bash # enter a bash session on the myApp container docker-compose ps # show the current status of the containers Available on docker command as well

Slide 41

Slide 41 text

Questions?

Slide 42

Slide 42 text

THANKS FOR YOUR ATTENTION Davide