SlideShare a Scribd company logo
1 of 41
Download to read offline
Developing in Docker
YipitData is not endorsed by, directly affiliated with, maintained,
authorized, or sponsored by Docker Inc.
Disclaimer
● Brief terminology
● Running containers
● Dockerfiles & Images
● Tips for development
General Outline
● Dockerfile: Defines the instructions to create an image
● Image: An executable package that contains the resources
needed to run a container
● Container: The result (a process) of executing an image. A
new container is made each time an image is executed
Dockerfile, Images, Containers, .. ?
● An easy way to create a container is by using “docker run”
docker run -it --rm <IMAGE:TAG> <COMMAND>
● Example:
docker run -it --rm python:3.6.5-jessie python
OK, but how do I even container ?
● An easy way to create a container is by using “docker run”
docker run -it --rm <IMAGE:TAG> <COMMAND>
OK, but how do I even container ?
Exposes STDIN to the container and
emulates a terminal session. It lets you run
commands within the container
● An easy way to create a container is by using “docker run”
docker run -it --rm <IMAGE:TAG> <COMMAND>
OK, but how do I even container ?
Deletes the container after you exit
the process, helps keep disk space
under control
● There is no concept of “SSH” in docker. But you can access a
shell in a running container using docker exec:
docker exec -it <CONTAINER ID> bash
● You can find the container ID by running:
docker ps
So what about SSH ..
Live Demo
Exec into a container
● Exec is helpful during development to debug a container’s state
● When debugging production, you should try to recreate the
error using a fresh container locally
○ Exec is not supported in production
○ “Show Docker CLI” in YAWS is your friend
○ Enable logging to see more details
Don’t exec unless you have to.
Check out this sweet Dockerfile ..
FROM python:3.6.7-jessie
COPY app /app
RUN pip install Flask
EXPOSE 8000
CMD ["python", "/app/__init__.py"]
FROM python:3.6.7-jessie
COPY app /app
RUN pip install Flask
EXPOSE 8000
CMD ["python", "/app/__init__.py"]
Check out this sweet Dockerfile ..
FROM loads a published
image as a starting point for
your application
FROM python:3.6.7-jessie
COPY app /app
RUN pip install Flask
EXPOSE 8000
CMD ["python", "/app/__init__.py"]
Check out this sweet Dockerfile ..
COPY takes files in the host file system
and moves them into the image
FROM python:3.6.7-jessie
COPY app /app
RUN pip install Flask
EXPOSE 8000
CMD ["python", "/app/__init__.py"]
Check out this sweet Dockerfile ..
RUN allows you to execute
commands inside the image
EXPOSE defines a
port that can be
accessed outside of
the container
FROM python:3.6.7-jessie
COPY app /app
RUN pip install Flask
EXPOSE 8000
CMD ["python", "/app/__init__.py"]
Check out this sweet Dockerfile ..
FROM python:3.6.7-jessie
COPY app /app
RUN pip install Flask
EXPOSE 8000
CMD ["python", "/app/__init__.py"]
Check out this sweet Dockerfile ..
CMD defines a
default command
the container will
run
docker build -t <NAME>:<TAG> <PATH>
“docker build” translates a Dockerfile into an image
docker build -t <NAME>:<TAG> <PATH>
Important to tag a readable
name for your image
“docker build” translates a Dockerfile into an image
docker build -t <NAME>:<TAG> <PATH>
Specifying a version will pin
changes of the images you
create
“docker build” translates a Dockerfile into an image
docker build -t <NAME>:<TAG> <PATH>
Path to your Dockerfile
and application code
“docker build” translates a Dockerfile into an image
● Each instruction is a
layer, a change in the
image state
● Only FROM, RUN, and
COPY create layers
● The R/W layer is created
when running a container
An image is a series of “layers”
● Ephemeral: Containers are created / destroyed with ease, and
any setup is handled by the image
● Few in Layers: More layers lead to larger image size and longer
build time
● Ordered for caching: The instructions in the Dockerfile are
sequenced to leverage caching. Least likely to change or
longest running instructions should be higher up
The best Dockerfiles are:
Live Demo
Caching in action
● Base images can have unnecessary packages installed that
inflate your image size
FROM python:3.6.7-slim-jessie (157 MB)
FROM python:3.6.7-jessie (691 MB)
● Use a versioned base image, or your image will be built on the
latest base image (unstable)
Use the right base image
● A common technique is to chain shell commands using the &&
operator
RUN apt-get update
RUN apt-get install -y cron
vs.
RUN apt-get update 
&& apt-get install -y cron
Combine layers as much as possible
● Linux by default will install many “recommended” packages you
do not need. You can disable this behavior:
RUN apt-get update 
&& apt-get install -y --no-install-recommends 
cron
Install only what you need
● Packages may have extraneous files once installed, best
practice is to remove them
RUN curl s3://yipit/my_pkg.deb > my_pkg.deb 
&& dpkg -i my_pkg.deb 
&& rm -rf my_pkg.deb
Delete temporary files after installation
● The demo images were small to begin with, production image
sizes can decrease 60 - 70%
Significant reductions in image size
Absolute file path in the host
machine you want to mount
● Volumes mount external (host) files to a container
● You can continue to modify these files and your running
container will be up to date
docker run --rm -it -v <HOST PATH:CONTAINER PATH> 
<IMAGE:TAG>
Use volumes to speed up app development
● Volumes mount external (host) files to a container
● You can continue to modify these files and your running
container will be up to date
docker run --rm -it -v <HOST PATH:CONTAINER PATH> 
<IMAGE:TAG>
Destination file path in the
container for the mounted file(s)
Use volumes to speed up app development
Live Demo
Using volumes
● Two ways to set variables in the Dockerfile, ARG and ENV
● ARG defines a build-time variable that is out of scope once the
image is built
○ Good for secrets only used in setup (ex: localshop)
● ENV sets an environment variable that is in scope during and
after the image is built
Environment variables
● Both variables can be set via the CLI. They will override values
in the Dockerfile
● ARG:
docker build --build-arg <NAME=VALUE> -t
<IMAGE:TAG> .
● ENV:
docker run --rm -it -e <NAME=VALUE> <IMAGE:TAG>
Environment variables in the CLI
● You will want to end your Dockerfile with a CMD and/or
ENTRYPOINT (or inherit from your base image)
● An ENTRYPOINT executes code right at a container’s runtime
○ Establish background processes / services
○ Wrap additional context around commands
○ A CMD is passed as an argument to the entrypoint
CMD or ENTRYPOINT?
Live Demo
Entrypoint
● Docker is a large platform and there is so much more to learn
● Best ways to get started:
○ Documentation: https://docs.docker.com/
○ Read Dockerfiles for base images (usually on github)
○ Build some images!
Tip of the iceberg ..
● Containers improves parity of local development to production
○ The image you build is the image you deploy
○ Far easier to reproduce bugs
● Increases flexibility in your application architecture
○ OS packages easier to manage (no need for brew or chef)
○ Python versioning is simplified (no virtualenv)
But it pays off !
Questions?
● Official Docker Documentation
● Best Practices for Writing Dockerfiles
● Docker Container Layers
● XKCD on Containers
● XKCD on Compiling
References

More Related Content

What's hot

Docker at Monoco.jp (LinkedIn)
Docker at Monoco.jp (LinkedIn)Docker at Monoco.jp (LinkedIn)
Docker at Monoco.jp (LinkedIn)
Akhmad Fathonih
 

What's hot (20)

Vagrant and docker
Vagrant and dockerVagrant and docker
Vagrant and docker
 
Docker orchestration
Docker orchestrationDocker orchestration
Docker orchestration
 
Docker at Monoco.jp (LinkedIn)
Docker at Monoco.jp (LinkedIn)Docker at Monoco.jp (LinkedIn)
Docker at Monoco.jp (LinkedIn)
 
Deployment Automation with Docker
Deployment Automation with DockerDeployment Automation with Docker
Deployment Automation with Docker
 
Docker presentasjon java bin
Docker presentasjon java binDocker presentasjon java bin
Docker presentasjon java bin
 
Vagrant to-aws-flow
Vagrant to-aws-flowVagrant to-aws-flow
Vagrant to-aws-flow
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Vagrant
VagrantVagrant
Vagrant
 
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3 Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
 
DCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best PracticesDCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best Practices
 
Provisioning & Deploying with Docker
Provisioning & Deploying with DockerProvisioning & Deploying with Docker
Provisioning & Deploying with Docker
 
Rapid Development With Docker Compose
Rapid Development With Docker ComposeRapid Development With Docker Compose
Rapid Development With Docker Compose
 
Build service with_docker_in_90mins
Build service with_docker_in_90minsBuild service with_docker_in_90mins
Build service with_docker_in_90mins
 
Automating Docker Containers with Puppet 2014 10-13
Automating Docker Containers with Puppet 2014 10-13Automating Docker Containers with Puppet 2014 10-13
Automating Docker Containers with Puppet 2014 10-13
 
Deploying an application with Chef and Docker
Deploying an application with Chef and DockerDeploying an application with Chef and Docker
Deploying an application with Chef and Docker
 
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGHDeploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
 
Austin - Container Days - Docker 101
Austin - Container Days - Docker 101Austin - Container Days - Docker 101
Austin - Container Days - Docker 101
 
Learn jobDSL for Jenkins
Learn jobDSL for JenkinsLearn jobDSL for Jenkins
Learn jobDSL for Jenkins
 
Using docker to develop NAS applications
Using docker to develop NAS applicationsUsing docker to develop NAS applications
Using docker to develop NAS applications
 
Docker for Java developers at JavaLand
Docker for Java developers at JavaLandDocker for Java developers at JavaLand
Docker for Java developers at JavaLand
 

Similar to Getting Started with Docker

PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize Django
Hannes Hapke
 

Similar to Getting Started with Docker (20)

IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
 
Learning Docker with Thomas
Learning Docker with ThomasLearning Docker with Thomas
Learning Docker with Thomas
 
Deliver Python Apps with Docker
Deliver Python Apps with DockerDeliver Python Apps with Docker
Deliver Python Apps with Docker
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2
 
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
 
DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline  DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline
 
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHPHands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
 
Docker in Action
Docker in ActionDocker in Action
Docker in Action
 
Docker Introduction.pdf
Docker Introduction.pdfDocker Introduction.pdf
Docker Introduction.pdf
 
[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101
 
Docker, c'est bonheur !
Docker, c'est bonheur !Docker, c'est bonheur !
Docker, c'est bonheur !
 
Docker basics 30_01_21.ppx
Docker basics 30_01_21.ppxDocker basics 30_01_21.ppx
Docker basics 30_01_21.ppx
 
How to write a Dockerfile
How to write a DockerfileHow to write a Dockerfile
How to write a Dockerfile
 
Continuous Integration & Development with Gitlab
Continuous Integration & Development with GitlabContinuous Integration & Development with Gitlab
Continuous Integration & Development with Gitlab
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
 
Introduction to Docker for NodeJs developers at Node DC 2/26/2014
Introduction to Docker for NodeJs developers at Node DC 2/26/2014Introduction to Docker for NodeJs developers at Node DC 2/26/2014
Introduction to Docker for NodeJs developers at Node DC 2/26/2014
 
PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize Django
 
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandCI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
 
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
 
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
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
Earley Information Science
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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?
 

Getting Started with Docker

  • 2. YipitData is not endorsed by, directly affiliated with, maintained, authorized, or sponsored by Docker Inc. Disclaimer
  • 3.
  • 4. ● Brief terminology ● Running containers ● Dockerfiles & Images ● Tips for development General Outline
  • 5. ● Dockerfile: Defines the instructions to create an image ● Image: An executable package that contains the resources needed to run a container ● Container: The result (a process) of executing an image. A new container is made each time an image is executed Dockerfile, Images, Containers, .. ?
  • 6. ● An easy way to create a container is by using “docker run” docker run -it --rm <IMAGE:TAG> <COMMAND> ● Example: docker run -it --rm python:3.6.5-jessie python OK, but how do I even container ?
  • 7. ● An easy way to create a container is by using “docker run” docker run -it --rm <IMAGE:TAG> <COMMAND> OK, but how do I even container ? Exposes STDIN to the container and emulates a terminal session. It lets you run commands within the container
  • 8. ● An easy way to create a container is by using “docker run” docker run -it --rm <IMAGE:TAG> <COMMAND> OK, but how do I even container ? Deletes the container after you exit the process, helps keep disk space under control
  • 9. ● There is no concept of “SSH” in docker. But you can access a shell in a running container using docker exec: docker exec -it <CONTAINER ID> bash ● You can find the container ID by running: docker ps So what about SSH ..
  • 10. Live Demo Exec into a container
  • 11. ● Exec is helpful during development to debug a container’s state ● When debugging production, you should try to recreate the error using a fresh container locally ○ Exec is not supported in production ○ “Show Docker CLI” in YAWS is your friend ○ Enable logging to see more details Don’t exec unless you have to.
  • 12.
  • 13. Check out this sweet Dockerfile .. FROM python:3.6.7-jessie COPY app /app RUN pip install Flask EXPOSE 8000 CMD ["python", "/app/__init__.py"]
  • 14. FROM python:3.6.7-jessie COPY app /app RUN pip install Flask EXPOSE 8000 CMD ["python", "/app/__init__.py"] Check out this sweet Dockerfile .. FROM loads a published image as a starting point for your application
  • 15. FROM python:3.6.7-jessie COPY app /app RUN pip install Flask EXPOSE 8000 CMD ["python", "/app/__init__.py"] Check out this sweet Dockerfile .. COPY takes files in the host file system and moves them into the image
  • 16. FROM python:3.6.7-jessie COPY app /app RUN pip install Flask EXPOSE 8000 CMD ["python", "/app/__init__.py"] Check out this sweet Dockerfile .. RUN allows you to execute commands inside the image
  • 17. EXPOSE defines a port that can be accessed outside of the container FROM python:3.6.7-jessie COPY app /app RUN pip install Flask EXPOSE 8000 CMD ["python", "/app/__init__.py"] Check out this sweet Dockerfile ..
  • 18. FROM python:3.6.7-jessie COPY app /app RUN pip install Flask EXPOSE 8000 CMD ["python", "/app/__init__.py"] Check out this sweet Dockerfile .. CMD defines a default command the container will run
  • 19. docker build -t <NAME>:<TAG> <PATH> “docker build” translates a Dockerfile into an image
  • 20. docker build -t <NAME>:<TAG> <PATH> Important to tag a readable name for your image “docker build” translates a Dockerfile into an image
  • 21. docker build -t <NAME>:<TAG> <PATH> Specifying a version will pin changes of the images you create “docker build” translates a Dockerfile into an image
  • 22. docker build -t <NAME>:<TAG> <PATH> Path to your Dockerfile and application code “docker build” translates a Dockerfile into an image
  • 23. ● Each instruction is a layer, a change in the image state ● Only FROM, RUN, and COPY create layers ● The R/W layer is created when running a container An image is a series of “layers”
  • 24. ● Ephemeral: Containers are created / destroyed with ease, and any setup is handled by the image ● Few in Layers: More layers lead to larger image size and longer build time ● Ordered for caching: The instructions in the Dockerfile are sequenced to leverage caching. Least likely to change or longest running instructions should be higher up The best Dockerfiles are:
  • 26. ● Base images can have unnecessary packages installed that inflate your image size FROM python:3.6.7-slim-jessie (157 MB) FROM python:3.6.7-jessie (691 MB) ● Use a versioned base image, or your image will be built on the latest base image (unstable) Use the right base image
  • 27. ● A common technique is to chain shell commands using the && operator RUN apt-get update RUN apt-get install -y cron vs. RUN apt-get update && apt-get install -y cron Combine layers as much as possible
  • 28. ● Linux by default will install many “recommended” packages you do not need. You can disable this behavior: RUN apt-get update && apt-get install -y --no-install-recommends cron Install only what you need
  • 29. ● Packages may have extraneous files once installed, best practice is to remove them RUN curl s3://yipit/my_pkg.deb > my_pkg.deb && dpkg -i my_pkg.deb && rm -rf my_pkg.deb Delete temporary files after installation
  • 30. ● The demo images were small to begin with, production image sizes can decrease 60 - 70% Significant reductions in image size
  • 31. Absolute file path in the host machine you want to mount ● Volumes mount external (host) files to a container ● You can continue to modify these files and your running container will be up to date docker run --rm -it -v <HOST PATH:CONTAINER PATH> <IMAGE:TAG> Use volumes to speed up app development
  • 32. ● Volumes mount external (host) files to a container ● You can continue to modify these files and your running container will be up to date docker run --rm -it -v <HOST PATH:CONTAINER PATH> <IMAGE:TAG> Destination file path in the container for the mounted file(s) Use volumes to speed up app development
  • 34. ● Two ways to set variables in the Dockerfile, ARG and ENV ● ARG defines a build-time variable that is out of scope once the image is built ○ Good for secrets only used in setup (ex: localshop) ● ENV sets an environment variable that is in scope during and after the image is built Environment variables
  • 35. ● Both variables can be set via the CLI. They will override values in the Dockerfile ● ARG: docker build --build-arg <NAME=VALUE> -t <IMAGE:TAG> . ● ENV: docker run --rm -it -e <NAME=VALUE> <IMAGE:TAG> Environment variables in the CLI
  • 36. ● You will want to end your Dockerfile with a CMD and/or ENTRYPOINT (or inherit from your base image) ● An ENTRYPOINT executes code right at a container’s runtime ○ Establish background processes / services ○ Wrap additional context around commands ○ A CMD is passed as an argument to the entrypoint CMD or ENTRYPOINT?
  • 38. ● Docker is a large platform and there is so much more to learn ● Best ways to get started: ○ Documentation: https://docs.docker.com/ ○ Read Dockerfiles for base images (usually on github) ○ Build some images! Tip of the iceberg ..
  • 39. ● Containers improves parity of local development to production ○ The image you build is the image you deploy ○ Far easier to reproduce bugs ● Increases flexibility in your application architecture ○ OS packages easier to manage (no need for brew or chef) ○ Python versioning is simplified (no virtualenv) But it pays off !
  • 41. ● Official Docker Documentation ● Best Practices for Writing Dockerfiles ● Docker Container Layers ● XKCD on Containers ● XKCD on Compiling References