SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Primi passi con Docker
Alessandro Mignogna
Hi!
My name is Alessandro.
I am a Java/PHP dev.
I come from Biccari (Fg).
linkedin.com/in/alessandromignogna
info@alessandromignogna.com
Summary
1. What is Docker?
2. Virtual Machine vs Container
3. Docker images
4. Docker commands
5. Let’s code!
6. Dockerfile
7. Let’s code!
8. Docker compose
9. Let’s code!
10.Useful links
What is Docker?
What is a Container? A container is a completely isolated
environemnt.
It is a standard unit of software that packages up code and all its
dependencies so the application runs quickly and reliably from one
«The only independent container platform
that enables organizations to seamlessly build,
share and run any application,
anywhere—from hybrid cloud to the edge.»
What is a container?
• A container is a completely isolated environment
• it is a standard unit of software that packages up code and all its
dependencies so the application runs quickly and reliably from one
computing environment to another
• Every container has their own processes or services, their or
network interfaces
• They all share the same OS kernel (responsible for interacting with
the underlyng hardware)
Why Docker? What problems does it solve?
• Compatibility with the version of OS
• Compatibility between services and libraries
• Long setup time (ex: new developer in the team)
• Different Dev/Test/Prod environments
What can Docker do?
• Containerize Applications
• Run each service with its own dependencies in separate containers
Virtual Machines vs Containers
Docker images
• https://hub.docker.com/search?q=&type=image
Docker images
• A Docker image is a file, composed of multiple layers, used to
execute code in a Docker container
• An instance of an image is called a container
• Once the task is complete, the container exits
• A container only lives as long as
the process inside it is alive
How to install
Community Edition vs Enterprise Edition
Desktop version
Mac, Windows, Linux
Cloud providers
AWS & Azure
Server
Windows Server, CentOs, Fedora, Oracle Linux, Ubuntu,…
https://docs.docker.com/
First release made. Soon
available
Docker commands
docker --help
Show docker guides
Ex: docker –help
docker version
Show docker version
Ex: docker version
Docker commands
docker images
Show all images downloaded
Ex: docker images
docker pull [imageName]
Download a particular image
Ex: docker pull ubuntu
Docker commands
docker rmi [imageName]
Remove an image
Ex: docker rmi ubuntu
docker image prune
Remove all dangling images
Ex: docker image prune
Docker commands
docker ps
List only active containers
Ex: docker ps
docker ps --all
List all containers
Ex: docker ps --all | docker ps -a
Docker “run” command
The basic docker run command takes this form:
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
• The docker run command first creates a writeable container layer
over the specified image, and then starts it using the specified
command in foreground mode
• The docker run command must specify an image to derive the
container from
• With the docker run [OPTIONS] an operator can add to or override
the image defaults set by a developer
• Tag is used to specify the version (ex: redis:4.0)
https://docs.docker.com/engine/reference/run/
Docker “run” command
docker run --name [containerName] [imageName]
If you specify a name, you can use it when referencing the container
Ex: docker run --name myContainer ubuntu
Ex: docker run –-name myRedis redis:4.0
docker run [imageName] [commandName] [parameters]
Run a container from the imageName and execute the specified
command
Ex: docker run docker/whalesay cowsay ciao!
Ex: docker run ubuntu sleep 10
Docker “run” command
docker run -d [imageName]
Run a container in “detached” mode (a container runs in the
background of your terminal)
Ex: docker run -d ubuntu sleep 1500
docker run -it [imageName]
Run a container in “interactive” mode. –i for mapping the standard
input of your host to the docker container. –t basically makes the
container start look like a terminal connection session
Ex: docker run -it ubuntu
$ cd /home
Docker “run” command – port mapping
docker run –p [port]:[containerPort] [imageName]
Run a container with a particular port mapping
Ex: docker run –p 3307:3306 mysql
Docker “run” command – volume mapping
docker run –v [path]:[insideContainerPath] [imageName]
Run a container with a particular volume mapping
Ex: docker run –v /myFolder:/var/lib/mysql mysql
Other Docker commands
docker attach
Attach local standard input, output and errors streams to a running
container
Ex: docker attach 028e
docker exec [containerId] [command] [parameters]
Run a command in a running container
Ex: docker exec 27bj378 cat /logs/log.txt
Other Docker commands
docker stop [containerId]
Stop one or more running containers
Ex: docker stop 028d23e
docker rm [containerId]
Remove one or more containers
Ex: docker rm 27bj378
Other Docker commands
docker inspect [containerId/containerName]
Show all the container details in a JSON format
Ex: docker inspect myUbuntu
docker logs [containerId/containerName]
Show all the container logs
Ex: docker logs myUbuntu
Let’s code!
Dockerfile and docker-compose
Dockerfile
A Dockerfile is a text document that
contains all the commands a user could
call on the command line to assemble an
image
Docker-compose
Compose is a tool for defining and
running multi-container Docker
applications
Dockerfile
Using docker build users can create an automated build that executes
several command-line instructions in succession.
FORMAT
Here is the format of the Dockerfile:
# Comment
INSTRUCTION arguments
Dockerfile instructions
FROM [imageName]
The FROM instruction initializes a new build stage and sets the Base
Image for subsequent instructions
RUN […]
The RUN instruction will execute any commands in a new layer on top
of the current image and commit the results
EXPOSE […]
The EXPOSE instruction informs Docker that the container listens on
the specified network ports at runtime
Dockerfile instructions
ADD [src] [dest]
The ADD instruction copies new files, directories or remote file URLs
from <src> and adds them to the filesystem of the image at the
path <dest>
COPY [src] [dest] (preferred)
The COPY instruction copies new files or directories from <src> and
adds them to the filesystem of the container at the path <dest>. Same
as 'ADD', but without the tar and remote URL handling.
ENV [key]=[value]
The ENV instruction sets the environment variable <key> to the
value <value>
Dockerfile instructions
CMD [command] (also json array format supported)
The main purpose of a CMD is to provide defaults for an executing
container.
These defaults can include an executable, or they can omit the
executable, in which case you must specify
an ENTRYPOINT instruction as well.
If a Dockerfile has multiple CMDs, it only applies the instructions from
the last one.
ENTRYPOINT [command]
The ENTRYPOINT specifies a command that will always be executed
when the container starts.
The CMD specifies arguments that will be fed to the ENTRYPOINT.
Dockerfile example
FROM ubuntu
RUN apt-get update
RUN apt-get -y install wget
RUN apt-get -y install sudo
RUN cd /
RUN sudo wget http://www.domain.com/file.jpg
# arguments
CMD ["15"]
ENTRYPOINT ["sleep"]
In console
$ docker build . –t [ImageName]
Let’s code!
Docker compose
• Compose is a tool for defining and running multi-container
Docker applications.
• With Compose, you use a YAML file to configure your application’s
services.
• Then, with a single command, you create and start all the services
from your configuration.
Using Compose is basically a three-step process:
1. Define your app’s environment with a Dockerfile so it can be
reproduced anywhere.
2. Define the services that make up your app in docker-
compose.yml so they can be run together in an isolated
environment.
3. Run docker-compose up and Compose starts and runs your
Docker compose
docker-compose up
Builds, (re)creates, starts, and attaches to containers for a service.
docker-compose down
Stops containers and removes containers, networks, volumes, and
images created by up.
https://docs.docker.com/compose/reference/overview/
Docker compose keywords
services
The beginning of a docker-compose file
image
Specify the image to start the container from.
Can either be a repository/tag or a partial image ID.
build
Configuration options that are applied at build time.
Docker compose keywords
volumes
Mount host paths or named volumes, specified as sub-options to a
service.
If you want to reuse a volume across multiple services, then define a
named volume in the top-level volumes key.
links
Express dependency between services.
ports
Expose ports.
https://docs.docker.com/compose/compose-file/compose-file-v3/
Docker compose example
version: "3.9"
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- /opt/data:/var/lib/mysql
depends_on:
- redis
redis:
image: redis
Let’s code!
Useful links
https://docs.docker.com/get-started/
Official documentation
https://www.udemy.com/course/learn-docker/
A very clear Udemy course about Docker
https://labs.play-with-docker.com/
Play with Docker! A simple, interactive and fun playground to learn
Docker
https://awesome-docker.netlify.com/
A curated list of Docker resources and projects
Thanks!
https://www.linkedin.com/in/alessandromignogna/
info@alessandromignogna.com

Weitere ähnliche Inhalte

Was ist angesagt?

[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안양재동 코드랩
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshopRuncy Oommen
 
Hands on introduction to docker security for docker newbies
Hands on introduction to docker security for docker newbiesHands on introduction to docker security for docker newbies
Hands on introduction to docker security for docker newbiesYigal Elefant
 
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3Binary Studio
 
docker installation and basics
docker installation and basicsdocker installation and basics
docker installation and basicsWalid Ashraf
 
Buildservicewithdockerin90mins
Buildservicewithdockerin90minsBuildservicewithdockerin90mins
Buildservicewithdockerin90minsYong Cha
 
Docker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandDocker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandPRIYADARSHINI ANAND
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Binary Studio
 
Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 4Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 4Binary Studio
 
dockerizing web application
dockerizing web applicationdockerizing web application
dockerizing web applicationWalid Ashraf
 
Docker fundamentals
Docker fundamentalsDocker fundamentals
Docker fundamentalsAlper Unal
 
Docker 101 - Intro to Docker
Docker 101 - Intro to DockerDocker 101 - Intro to Docker
Docker 101 - Intro to DockerAdrian Otto
 
Introduction to docker security
Introduction to docker securityIntroduction to docker security
Introduction to docker securityWalid Ashraf
 

Was ist angesagt? (20)

Docker
DockerDocker
Docker
 
A Hands-on Introduction to Docker
A Hands-on Introduction to DockerA Hands-on Introduction to Docker
A Hands-on Introduction to Docker
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안
 
How to _docker
How to _dockerHow to _docker
How to _docker
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshop
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Hands on introduction to docker security for docker newbies
Hands on introduction to docker security for docker newbiesHands on introduction to docker security for docker newbies
Hands on introduction to docker security for docker newbies
 
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3
 
docker installation and basics
docker installation and basicsdocker installation and basics
docker installation and basics
 
Buildservicewithdockerin90mins
Buildservicewithdockerin90minsBuildservicewithdockerin90mins
Buildservicewithdockerin90mins
 
Docker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandDocker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini Anand
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
 
Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 4Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 4
 
Docker Workshop
Docker WorkshopDocker Workshop
Docker Workshop
 
dockerizing web application
dockerizing web applicationdockerizing web application
dockerizing web application
 
Docker fundamentals
Docker fundamentalsDocker fundamentals
Docker fundamentals
 
Docker 101 - Intro to Docker
Docker 101 - Intro to DockerDocker 101 - Intro to Docker
Docker 101 - Intro to Docker
 
Exploring Docker Security
Exploring Docker SecurityExploring Docker Security
Exploring Docker Security
 
Introduction to docker security
Introduction to docker securityIntroduction to docker security
Introduction to docker security
 

Ähnlich wie Primi passi con Docker

Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers Will Hall
 
Running the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerRunning the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerGuido Schmutz
 
Docker for .NET Developers
Docker for .NET DevelopersDocker for .NET Developers
Docker for .NET DevelopersTaswar Bhatti
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s LifeGlobalLogic Ukraine
 
Docker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps DevelopmentDocker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps Developmentmsyukor
 
Deploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local BengaluruDeploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local BengaluruSwaminathan Vetri
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020CloudHero
 
Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday developmentJustyna Ilczuk
 
Powercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptxPowercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptxIgnacioTamayo2
 

Ähnlich wie Primi passi con Docker (20)

Docker
DockerDocker
Docker
 
Docker.pdf
Docker.pdfDocker.pdf
Docker.pdf
 
Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers
 
Docker introduction - Part 1
Docker introduction - Part 1Docker introduction - Part 1
Docker introduction - Part 1
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
 
Running the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerRunning the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker Container
 
Docker for .NET Developers
Docker for .NET DevelopersDocker for .NET Developers
Docker for .NET Developers
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Docker how to
Docker how toDocker how to
Docker how to
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s Life
 
Docker Presentation
Docker Presentation Docker Presentation
Docker Presentation
 
Docker 101
Docker 101Docker 101
Docker 101
 
Docker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps DevelopmentDocker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps Development
 
Deploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local BengaluruDeploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local Bengaluru
 
Docker intro
Docker introDocker intro
Docker intro
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020
 
Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday development
 
Docker toolbox
Docker toolboxDocker toolbox
Docker toolbox
 
Powercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptxPowercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptx
 

Kürzlich hochgeladen

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Kürzlich hochgeladen (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Primi passi con Docker

  • 1. Primi passi con Docker Alessandro Mignogna
  • 2. Hi! My name is Alessandro. I am a Java/PHP dev. I come from Biccari (Fg). linkedin.com/in/alessandromignogna info@alessandromignogna.com
  • 3. Summary 1. What is Docker? 2. Virtual Machine vs Container 3. Docker images 4. Docker commands 5. Let’s code! 6. Dockerfile 7. Let’s code! 8. Docker compose 9. Let’s code! 10.Useful links
  • 4. What is Docker? What is a Container? A container is a completely isolated environemnt. It is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one «The only independent container platform that enables organizations to seamlessly build, share and run any application, anywhere—from hybrid cloud to the edge.»
  • 5. What is a container? • A container is a completely isolated environment • it is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another • Every container has their own processes or services, their or network interfaces • They all share the same OS kernel (responsible for interacting with the underlyng hardware)
  • 6. Why Docker? What problems does it solve? • Compatibility with the version of OS • Compatibility between services and libraries • Long setup time (ex: new developer in the team) • Different Dev/Test/Prod environments
  • 7. What can Docker do? • Containerize Applications • Run each service with its own dependencies in separate containers
  • 8. Virtual Machines vs Containers
  • 10. Docker images • A Docker image is a file, composed of multiple layers, used to execute code in a Docker container • An instance of an image is called a container • Once the task is complete, the container exits • A container only lives as long as the process inside it is alive
  • 11. How to install Community Edition vs Enterprise Edition Desktop version Mac, Windows, Linux Cloud providers AWS & Azure Server Windows Server, CentOs, Fedora, Oracle Linux, Ubuntu,… https://docs.docker.com/ First release made. Soon available
  • 12. Docker commands docker --help Show docker guides Ex: docker –help docker version Show docker version Ex: docker version
  • 13. Docker commands docker images Show all images downloaded Ex: docker images docker pull [imageName] Download a particular image Ex: docker pull ubuntu
  • 14. Docker commands docker rmi [imageName] Remove an image Ex: docker rmi ubuntu docker image prune Remove all dangling images Ex: docker image prune
  • 15. Docker commands docker ps List only active containers Ex: docker ps docker ps --all List all containers Ex: docker ps --all | docker ps -a
  • 16. Docker “run” command The basic docker run command takes this form: docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] • The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command in foreground mode • The docker run command must specify an image to derive the container from • With the docker run [OPTIONS] an operator can add to or override the image defaults set by a developer • Tag is used to specify the version (ex: redis:4.0) https://docs.docker.com/engine/reference/run/
  • 17. Docker “run” command docker run --name [containerName] [imageName] If you specify a name, you can use it when referencing the container Ex: docker run --name myContainer ubuntu Ex: docker run –-name myRedis redis:4.0 docker run [imageName] [commandName] [parameters] Run a container from the imageName and execute the specified command Ex: docker run docker/whalesay cowsay ciao! Ex: docker run ubuntu sleep 10
  • 18. Docker “run” command docker run -d [imageName] Run a container in “detached” mode (a container runs in the background of your terminal) Ex: docker run -d ubuntu sleep 1500 docker run -it [imageName] Run a container in “interactive” mode. –i for mapping the standard input of your host to the docker container. –t basically makes the container start look like a terminal connection session Ex: docker run -it ubuntu $ cd /home
  • 19. Docker “run” command – port mapping docker run –p [port]:[containerPort] [imageName] Run a container with a particular port mapping Ex: docker run –p 3307:3306 mysql
  • 20. Docker “run” command – volume mapping docker run –v [path]:[insideContainerPath] [imageName] Run a container with a particular volume mapping Ex: docker run –v /myFolder:/var/lib/mysql mysql
  • 21. Other Docker commands docker attach Attach local standard input, output and errors streams to a running container Ex: docker attach 028e docker exec [containerId] [command] [parameters] Run a command in a running container Ex: docker exec 27bj378 cat /logs/log.txt
  • 22. Other Docker commands docker stop [containerId] Stop one or more running containers Ex: docker stop 028d23e docker rm [containerId] Remove one or more containers Ex: docker rm 27bj378
  • 23. Other Docker commands docker inspect [containerId/containerName] Show all the container details in a JSON format Ex: docker inspect myUbuntu docker logs [containerId/containerName] Show all the container logs Ex: docker logs myUbuntu
  • 25. Dockerfile and docker-compose Dockerfile A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image Docker-compose Compose is a tool for defining and running multi-container Docker applications
  • 26. Dockerfile Using docker build users can create an automated build that executes several command-line instructions in succession. FORMAT Here is the format of the Dockerfile: # Comment INSTRUCTION arguments
  • 27. Dockerfile instructions FROM [imageName] The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions RUN […] The RUN instruction will execute any commands in a new layer on top of the current image and commit the results EXPOSE […] The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime
  • 28. Dockerfile instructions ADD [src] [dest] The ADD instruction copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the image at the path <dest> COPY [src] [dest] (preferred) The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>. Same as 'ADD', but without the tar and remote URL handling. ENV [key]=[value] The ENV instruction sets the environment variable <key> to the value <value>
  • 29. Dockerfile instructions CMD [command] (also json array format supported) The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well. If a Dockerfile has multiple CMDs, it only applies the instructions from the last one. ENTRYPOINT [command] The ENTRYPOINT specifies a command that will always be executed when the container starts. The CMD specifies arguments that will be fed to the ENTRYPOINT.
  • 30. Dockerfile example FROM ubuntu RUN apt-get update RUN apt-get -y install wget RUN apt-get -y install sudo RUN cd / RUN sudo wget http://www.domain.com/file.jpg # arguments CMD ["15"] ENTRYPOINT ["sleep"] In console $ docker build . –t [ImageName]
  • 32. Docker compose • Compose is a tool for defining and running multi-container Docker applications. • With Compose, you use a YAML file to configure your application’s services. • Then, with a single command, you create and start all the services from your configuration. Using Compose is basically a three-step process: 1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere. 2. Define the services that make up your app in docker- compose.yml so they can be run together in an isolated environment. 3. Run docker-compose up and Compose starts and runs your
  • 33. Docker compose docker-compose up Builds, (re)creates, starts, and attaches to containers for a service. docker-compose down Stops containers and removes containers, networks, volumes, and images created by up. https://docs.docker.com/compose/reference/overview/
  • 34. Docker compose keywords services The beginning of a docker-compose file image Specify the image to start the container from. Can either be a repository/tag or a partial image ID. build Configuration options that are applied at build time.
  • 35. Docker compose keywords volumes Mount host paths or named volumes, specified as sub-options to a service. If you want to reuse a volume across multiple services, then define a named volume in the top-level volumes key. links Express dependency between services. ports Expose ports. https://docs.docker.com/compose/compose-file/compose-file-v3/
  • 36. Docker compose example version: "3.9" services: web: build: . ports: - "5000:5000" volumes: - /opt/data:/var/lib/mysql depends_on: - redis redis: image: redis
  • 38. Useful links https://docs.docker.com/get-started/ Official documentation https://www.udemy.com/course/learn-docker/ A very clear Udemy course about Docker https://labs.play-with-docker.com/ Play with Docker! A simple, interactive and fun playground to learn Docker https://awesome-docker.netlify.com/ A curated list of Docker resources and projects

Hinweis der Redaktion

  1. Cosa succede con kernel differenti (es: windows e linux) se spostiamo I container da una parte all’altra? Widnows 10 ha una linux machine intermedia
  2. Prima gli sviluppatori inviavano I war + I file di configurazione ai sistemisti e spesso c’erano problemi nel deploy per via di qualche dettaglio sfuggito. Ora si può inviare il war del Progetto con il dockerfile che contiene al suo interno tutte le configurazioni e non ci sono quindi più errori
  3. Ogni virtual machine ha il suo Sistema Operativo e quindi un alto consumo di risorse. Gigabyte vs megabyte Velocità di caricamento Docker però ha meno isolamento (il kernel è condiviso) mentre le virtual machine sono completamente isolate e possono girare facilmente su più sistemi operativi In grossi sistemi si usa una soluzione ibrida con più container in una macchina virtuale per sfruttuare i vantaggi di entrambe le soluzioni
  4. Le immagini sono template da cui creare più container.