IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> 2021-07-17 -> 正文阅读

[系统运维]2021-07-17

start

一、get startted

docker run -d -p 80:80 docker/getting-started

some flags:

  • -d detached mode分离模式
  • -p port 端口 主机:container

docker/getting-started 镜像image
combine single character flags to shorten the command:
什么是容器镜像
container: isolated filesystem
image: provide filesystem

image包含
all dependencies
configuration
scripts
binaries
environment variables
a default command to run
other metadata
image其他
layering
best practices

the docker dashboard

todo list manager

get the app

  1. docker build -t getting-started . tag
  2. docker run -dp 3000:3000 getting-started

二、application

dockerfile(创建镜像)

文件dockfile
位置与package.json同目录–
内容FROM RUN WORKDIR COPY COPY RUN CMD
命令docker build -t getting-started .

其中:

  • -t代表tag
  • . 代表在当前文件夹寻找dockerfile

start container(开启容器)

docker run -dp 3000:3000 getting-startted
其中:

  • -dp detached mode
  • -p port

三、update the application

update the source code

replace the old container

  1. get the coontainer ID
    ·docker ps
  2. docker stop <the-container-id>
  3. docker rm <the-container-id>
  4. docker build -t getting-started .
  5. docker run -dp 3000:3000 getting-started

四、share the application

create the repo

  • 重命名镜像 docker tag getting-started YOUR-USER-NAME/getting-started
  • docker push YOUR-USER-NAME/getting-started

五、persist the DB数据持久化

named volumes

  • 创建volumes
    docker volume create todo-db
  • 挂载mount
    docker run -dp 3000:3000 -v todo-db:/etc/todos getting-started
  • 查看named vollumes地址
    docker volume inspect todo-db

bind mounts(挂载点)

volume type comparisons

应用场景:

" With bind mounts, we control the exact mountpoint on the host. We can use this to persist data, but it’s often used to provide additional data into containers. When working on an application, we can use a bind mount to mount our source code into the container to let it see code changes, respond, and let us see the changes right away. "

创建dev container思路:

  • Mount our source code into the container
  • Install all dependencies, including the “dev” dependencies
  • Start nodemon to watch for filesystem changes

实现步骤:

  1. 挂载 创建
    docker run -dp 3000:3000 \ -w /app -v "$(pwd):/app" \ node:12-alpine \ sh -c "yarn install && yarn run dev"
  2. 查看logs
    docker logs -f <container-id>

五、Multi container apps多容器软件

each container should do one thing and do it well.
在这里插入图片描述

container networking(talking to each other)

There are two ways to put a container on a network:

  • Assign it at start or
  • connect an existing container.
  1. Create the network.
    docker network create todo-app
  2. 网络别名
    docker run -d \ --network todo-app --network-alias mysql \ -v todo-mysql-data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=secret \ -e MYSQL_DATABASE=todos \ mysql:5.7
    环境变量:
    -e Environment Variable

 - [ ] mysql 是什么意思

docker exec -it <mysql-container-id> mysql -u root -p
mysql> SHOW DATABASES;
  1. 连接mysql
    docker run -it --network todo-app nicolaka/netshoot
    dig mysql

六、Use Docker Compose

定义和分享多容器app
define and share multi-container applications

yaml文件define services
commandspin everything up or tear it all down

version

docker-compose version

Create the Compose file

docker-compose.yml

 version: "3.7"
 services:

Define the app service

define container

docker run -dp 3000:3000 \
  -w /app -v "$(pwd):/app" \
  --network todo-app \
  -e MYSQL_HOST=mysql \
  -e MYSQL_USER=root \
  -e MYSQL_PASSWORD=secret \
  -e MYSQL_DB=todos \
  node:12-alpine \
  sh -c "yarn install && yarn run dev"
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-07-28 00:20:46  更:2021-07-28 00:20:59 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/7 1:54:31-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码