Skip to content

Instantly share code, notes, and snippets.

Multi-Stage Build

In this exercise, we will learn to write a Dockerfile that describes multiple images and that can copy files from one image to the next.

Defining a multi-stage build

  1. Make a fresh folder ~/multi to do this exercise in, and cd into it.

  2. Add a file hello.c to the multi folder containing Hello World in C:

Creating Images with Dockerfiles 2

Setting Default Commands

  1. Add the following line to your Docker le from the last problem, at the bottom:
...
CMD ["ping", "127.0.0.1", "-c", "5"]

Creating Images with Dockefiles

Writing and Building a Dockerfile

  1. Create a folder called myimage, and a text file called Dockerfile within that folder. In Dockerfile, include the following instructions:
FROM centos:7
RUN yum update -y

Interactive Image Creation

Modifying a Container

  1. Start a bash terminal in a CentOS container:
$ docker container run -it centos:7 bash
  1. Install a couple pieces of software in this container - there’s nothing special

Starting, Stopping, Inspecting and Deleting Containers

Starting and Restarting Containers

  1. Start by running a container in the background, and check that it’s really running:
$ docker container run -d centos:7 ping 8.8.8.8
$ docker container ls

Detached Containers and Logging

Running a Container in the Background

  1. First try running a container as usual; the STDOUT and STDERR streams from whatever is PID 1 inside the container are directed to the terminal:
$ docker container run centos:7 ping 127.0.0.1 -c 2
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

Interactive Containers

Writing to Containers

  1. Create a container using the centos:7 image, and connect to its bash shell in interactive mode using the -i flag (also the -t flag, to request a TTY connection):
$ docker container run -it centos:7 bash

Running & Inspecting Containers

By the end of this exercise, you should be able to:

  • Start a container
  • List running and stopped containers

Running Containers

  1. First, let’s start a container, and observe the output:
$ docker container run centos:7 echo "hello world"

Running & Inspecting Containers

By the end of this exercise, you should be able to:

  • Start a container
  • List running and stopped containers

Running Containers

  1. First, let’s start a container, and observe the output:
$ docker container run centos:7 echo "hello world"

TODO List

  1. Create a simple HTTP services that responds with Hello world to every requests:
const http = require('http')
const port = 3000

let test = []