什么是Docker?

Page content

[TOC]

关于Docker。

What is docker?

1.1 Docker Images

2019-06-18-001

1.2 Container Isolation

2019-06-18-002

container id 可以简写前几个字母 只要唯一即可。

1.3 Terminology

  • Images - the file system and configuration of our application.

  • Containers - Running instances of Dokcer images. Containers run the actual applications. A container includes an application and all of its dependencies. It shares the kernel wiht other containers, and run as isolated process in user space on the host OS. docker container ls a list of running containers.

  • Docker caemon - the background service running on the host that manages building, running and distributing Docker containers.

  • Docker client - command line tool that allows the user to interact with the Docker daemon.

  • Docker Store - a directory of all availiable Docker images.

1.4 Image Creation

running an interative shell in a ubuntu container
docker container run -ti ubuntu bash

2019-06-18-003

新建一个文件 index.js

var os = require("os");
var hostname = os.hostname();
console.log("hello from " + hostname);

建立一个Dockerfile文件

FROM alpine
RUN apk update && apk add nodejs
COPY . /app
WORKDIR /app
CMD ["node","index.js"]

构建镜像

docker image build -t hello:v0.1 .

2019-06-18-005

启动容器

docker container run hello:v0.1

what just happend?

  1. FROM alpinespecifies a base image to pull FROM alpine image we used in earlier labs.

  2. RUN apk update && apk add nodejs RUN two commands(apk update and apk add) inside that container which installs the Node.js server.

  3. COPY . /app COPY files from our dircetory in to the container. e.g. index.js we just created.

  4. WORKDIR /app WORKDIR specify the WORKDIR the directory the container should use when it starts up.

  5. And finally, we gave our container a command(CMD) to run when the container starts.

With Dockerfile we can specify preceise commands to run for everyone who uses this container. Other users do not have to build the container themselves once you push your container up to a repository (which we will cover later) or even know what commands are used.

2019-06-18-006

Terminology

  • Layers - A Docker image is built up a series of layers.

  • Dockerfile - A text file contains all the commands, in order, needed to build a given image.

  • Volumes - A special Docker container layer that allows data to persist and be shared separately from container itself.