Skip to content

Latest commit

 

History

History
93 lines (81 loc) · 3.74 KB

04-Docker.md

File metadata and controls

93 lines (81 loc) · 3.74 KB

Part IV: Docker

Objectives:

By the end of this module, the SRE will:

  • Describe the directives from a sample dockerfile
  • Explain layers and the docker cache
  • Start a docker container that runs ubuntu linux
  • Describe the following container concepts:
    • base image
    • single pid
    • CMD vs ENTRYPOINT
    • logs
    • volumes
    • layers and ordering
    • caching
    • build
    • push

Deliverables

Complete the project described below. Answer the questions, then schedule a time to meet with your mentor and discuss the what you've built.

Docker

  1. Setup
  1. Create new Dockerfile from ubuntu:16.04

  2. run apt-get update and apt-get upgrade --yes on separate lines in the Dockerfile

  3. Build the docker file.

    • docker build -t intro_to_docker .
    • How many steps were there?
  4. Build again

  5. Use docker history <image> to see each step and its layer id

    • Count the number of lines by using | wc -l
    • docker history d57d088b85d1 | wc -l
    • 9 lines!
  6. Replace the two lines with apt-get update && apt-get upgrade --yes and build again

    • How many steps were there?
    • What is &&?
    • Use wc -l here
    • Why were there fewer steps?

More with Docker

Start a docker container that runs ubuntu linux

  • docker run -it <image_id> bash
  1. Using the ADD and RUN directives, add one of the scripts from before to the image and build the image.

  2. Move the ADD directive so it is above the RUN directive and build the image

    • Is cached used this time?
    • Why not?
  3. Use the CMD and ENTRYPOINT directives in turn the Dockerfile to make the script run by default

  4. Rewrite the Dockerfile using ADD and CMD to add the script and run the command.

  • Create a container using your latest image docker run -it <image_id> bash
    • How is this different than docker run -it <image> bash?
    • Run the docker image as a daemon with sleep 3600 as the main process docker run -d <image_id> sleep 3600
    • exec into the running container and run ps -ef to view the running processes
    • docker exec -it <container_id> bash
      • What is the pid of the sleep process?
      • What happens if you kill that pid

Learning Resources: