Docker入门

目录

概念

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
dcoker-01.png
  • Container diagram
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
<html>

<body>
    Copy File
</body>

</html>
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

下一步

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容