0%

Docker Compose

简介

docker compose来轻松高效的管理容器,定义运行多个容器。

官方介绍

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. To learn more about all the features of Compose, see the list of features.

阅读全文 »

DockerFile

DockerFile 介绍

dockerfile 是用来构建docker镜像的文件!命令参数脚本!

构建步骤:

  1. 编写一个 dockerfile 文件
  2. docker build 构建成为一个镜像
  3. docker run 运行镜像
  4. docker push 发布镜像 ( DockerHub、阿里云镜像仓库!)
阅读全文 »

容器数据卷

什么是容器数据卷

数据?如果数据都在容器中,那么容器删除,数据就会丢失!==需求:数据持久化==

MySQL,容器删除了,删库跑路! ==需求:MySQL可以存储在本地!==

容器之间可以有一个数据共享的技术! Docker容器中产生的数据,同步在本地!
这就是卷技术!目录的挂载,将我们容器内的目录挂载在Linux上!

阅读全文 »

Docker 安装Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 1. 搜索镜像
[root@baohua ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 13951 [OK]

# 2. 下载镜像
docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
bb79b6b2107f: Pull complete
111447d5894d: Pull complete
a95689b8e6cb: Pull complete
1a0022e444c2: Pull complete
32b7488a3833: Pull complete
Digest: sha256:ed7f815851b5299f616220a63edac69a4cc200e7f536a56e421988da82e44ed8
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

# 3. 运行测试

# -d 后台运行
# --name 给容器命名
# -p 宿主机端口,容器内部端口
[root@baohua ~]# docker run -d --name nginx01 -p 3344:80 nginx
7da41ee1789c912de270afdf481683fecd6be97ec4d2990595a9c3845f3e58a1
[root@baohua ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7da41ee1789c nginx "/docker-entrypoint.?? 4 seconds ago Up 3 seconds 0.0.0.0:3344->80/tcp nginx01
[root@baohua ~]# curl localhost:3344

# 进入容器
[root@baohua ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7da41ee1789c nginx "/docker-entrypoint.?? 8 minutes ago Up 8 minutes 0.0.0.0:3344->80/tcp nginx01
[root@baohua ~]# docker exec -it nginx01 /bin/bash
root@7da41ee1789c:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@7da41ee1789c:/# cd /etc/nginx

端口暴露的概念

1604325264690

思考:每次改动nginx配置文件,都需要进入容器内部。十分麻烦,要可以在外部提供一个映射路径,达到容器外部修改文件,容器内部自动修改。 -v 数据卷

阅读全文 »

Docker 镜像原理

镜像概念

镜像是一种轻量级、可执行的独立软件包,用来打包软件运行环境和基于运行环境开发的软件,它包含运行某个软件所需的所有内容,包括代码、运行时、库、环境变量和配置文件

如何得到镜像

  • 从仓库下载
  • 朋友拷贝
  • 自己制作
阅读全文 »