Book Image

Learn Docker - Fundamentals of Docker 18.x

By : Dr. Gabriel N. Schenker
Book Image

Learn Docker - Fundamentals of Docker 18.x

By: Dr. Gabriel N. Schenker

Overview of this book

Docker containers have revolutionized the software supply chain in small and big enterprises. Never before has a new technology so rapidly penetrated the top 500 enterprises worldwide. Companies that embrace containers and containerize their traditional mission-critical applications have reported savings of at least 50% in total maintenance cost and a reduction of 90% (or more) of the time required to deploy new versions of those applications. Furthermore they are benefitting from increased security just by using containers as opposed to running applications outside containers. This book starts from scratch, introducing you to Docker fundamentals and setting up an environment to work with it. Then we delve into concepts such as Docker containers, Docker images, Docker Compose, and so on. We will also cover the concepts of deployment, orchestration, networking, and security. Furthermore, we explain Docker functionalities on public clouds such as AWS. By the end of this book, you will have hands-on experience working with Docker containers and orchestrators such as SwarmKit and Kubernetes.
Table of Contents (21 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Chapter 4


Here are possible answers to the questions:

  1. Dockerfile:
FROM ubuntu:17.04
RUN apt-get update
RUN apt-get install -y ping
ENTRYPOINT ping
CMD 127.0.0.1
  1. To achieve the result you can execute the following steps:
$ docker container run -it --name sample \
    alpine:latest /bin/sh
/ # apk update && \
    apk add -y curl && \
    rm -rf /var/cache/apk/*
/ # exit
$ docker container commit sample my-alpine:1.0
$ docker container rm sample
  1. As a sample here is the Hello World in C:
    1. Create a file hello.c with this content:
#include <stdio.h>
int main()
{
   printf("Hello, World!");
   return 0;
}
    1. Create a Dockerfile with this content:
FROM alpine:3.5 AS build
RUN apk update && \
    apk add --update alpine-sdk
RUN mkdir /app
WORKDIR /app
COPY hello.c /app
RUN mkdir bin
RUN gcc -Wall hello.c -o bin/hello 

FROM alpine:3.5
COPY --from=build /app/bin/hello /app/hello
CMD /app/hello
  1. Some characteristics of a Docker image are:
    • It is immutable
    • It is composed of immutable layers
    • Each layer contains only what has changed (the delta) in regard to the lower lying layers
    • An image is a (big) tarball of files and folders
    • an image is a template for containers
  2. Option 3 is correct. First we need to make sure we're logged in and then we tag the image and finally push it. Since it is an image we're using docker image ... and not docker container ... (as in number 4).