Docker入门

目录

  • 概念

    • Docker

    • Image

    • Container

    • Containers-vs.-virtual-machines

  • 安装

    • 系统源

    • 官方源

    • 加速器

  • 实战Nginx

    • 下载Image

    • 创建Container

    • 登录Container

    • 删除Container

    • Expose-Port

    • Copy-File

    • Use-Volume

  • 实战WordPress

    • 下载Image

    • 创建Container

  • 下一步

概念

Docker

Docker is the world's leading software container platform

更多参考What is Docker

Image

An image is a lightweight, stand-alone, executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries, environment variables, and config files

互动: Windows镜像和Windows系统有何关系和区别?

Container

A container is a runtime instance of an image—what the image becomes in memory when actually executed. It runs completely isolated from the host environment by default, only accessing host files and ports if configured to do so.

更多参考Get Started, Part 1: Orientation and setup

Containers vs. virtual machines

  • Virtual Machine diagram
Docker入门_第1张图片
dcoker-01.png
  • Container diagram
Docker入门_第2张图片
dcoker-02.png

互动: Docker能否运行在Windows系统? 如何做到的?

安装

系统源

sudo apt install -y docker.io

sudo docker run hello-world

官方源

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt update

sudo apt install -y docker-ce

更多参考Get Docker CE for Ubuntu

加速器

更多参考Docker 加速器

实战Nginx

下载Image

docker images

docker search nginx

docker pull nginx

更多参考Docker CLI

创建Container

docker ps # docker ps --all

docker run --name nginx-demo -d nginx

登录Container

docker exec -it nginx-demo /bin/bash

删除Container

docker rm -f nginx-demo

Expose Port

docker run --name nginx-demo -p 8001:80 -d nginx

curl http://localhost:8001/

Copy File

vim index.html



    Copy File



docker cp ./index.html nginx-demo:/usr/share/nginx/html

curl http://localhost:8001/

Use Volume

docker run --name nginx-demo -p 8001:80 -v ~/docker/nginx-demo:/usr/share/nginx/html -d nginx

更多参考Use volumes

实战WordPress

下载Image

docker pull mysql && docker pull wordpress

创建Container

docker run --name mysql-demo -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql

docker run --name wordpress-demo -p 8002:80 --link mysql-demo:mysql -d wordpress

更多参考docker run

下一步

  • Dockerfile

更多文章, 请支持我的个人博客

你可能感兴趣的:(Docker入门)