目录
概念
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.
Containers vs. virtual machines
- Virtual Machine diagram
- Container diagram
互动: 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
加速器
更多参考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
下一步
更多文章, 请支持我的个人博客