docker笔记

一、docker:

1. 容器采用的是沙盒机制,相互之间没有任何接口。

二、docker能够做什么?

1\. 能够做虚拟机能做的所有事情,但是比虚拟机需要的资源要少。

2. 没有虚拟机需要操作系统,只需要一个docker引擎。

三、镜像和容器:

1. 镜像只是一个只读的模板,一个镜像里面包含着代码和代码需要的运行环境。一个镜像可以创建很多的容器。

2. 容器是docker来运行应用的,是镜像创建的运行实例,它可以被启动、暂停、停止、删除。每个容器之间是相互独立的,可以把容器看成一个简易版的linux环境(包括Root用户权限,进程空间、用户空间和网络空间等等)和运行在其中的应用程序。

下面有图解释容器和镜像的关系。

四、docker安装:

1\. win10版本大于1058, 64位;

2. 开启虚拟化(任务管理器->性能(右下角有虚拟化))。

3. Hyper-v (在程序和功能面板,左边有一个启用或关闭windows功能,找到hyper-v,全部勾选,重新启动)

五、docker仓库: hub.docker.com

image.png

容器和镜像的关系

image.png

docker run 命令详解

image.png

docker容器和外部电脑的通信,通过映射端口,外部电脑才能访问。

image.png

docker创建容器并且进入交互模式

image.png

docker显示输出信息; 进入已经运行的容器中

image.png

docker容器和外部机器之间数据的交换

image.png

数据卷

image.png

数据卷语法以及原理,保证主机该目录的修改,能够反映到容器中。

image.png

需要依赖一个linux环境,然后,可以配置软件和软件需要的环境。

步骤:

1.直接pull一个centos,然后,进入容器中,进行项目的配置。

2.执行commit。

3.在阿里云仓库中,创建仓库,然后,根据提示的docker命令,push镜像到远程仓库。
image.png

导成本地镜像文件。

前言:

docker官网有很详细的安装教程,建议按照官网的步骤进行安装。

Install Docker on Ubuntu:https://docs.docker.com/engine/installation/linux/ubuntulinux/

docker需要3.10或者更高版本的内核支持,通过uname -r查看内核版本。

步一:更新apt源

$ sudo apt-get update

$ sudo apt-get install apt-transport-https ca-certificates

步二:添加新的GPG密钥

$ sudo apt-key adv \

--keyserver hkp://ha.pool.sks-keyservers.net:80 \

--recv-keys 58118E89F3A912897C070ADBF76221572C52609D

步三:通过lsb_release -a命令查看系统的版本,Ubuntu14.04

Trusty 14.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-trusty main

步四:设置源

$ echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list

步五:更新APT

$ sudo apt-get update

步六:确认APT已经更新,正常会输出结果

$ apt-cache policy docker-engine

docker-engine:

Installed: 1.12.2-0~trusty

Candidate: 1.12.2-0~trusty

Version table:

*** 1.12.2-0~trusty 0

500https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages

100 /var/lib/dpkg/status

1.12.1-0~trusty 0

https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages

1.12.0-0~trusty 0
https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages

步七:再次更新源

$ sudo apt-get update

步八:安装增强包

sudo apt-get install linux-image-extra-(uname -r) linux-image-extra-virtual

步九:再次更新源

$ sudo apt-get update

步十:安装Docker

$ sudo apt-get install docker-engine

步十一:启动Docker守护进程

$ sudo service docker start

步十二:确认安装成功,这个命令会下载一个测试镜像。

$ sudo docker run hello-world

看到这个界面意味着成功了:

$ docker run hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

535020c3e8ad: Pull complete

af340544ed62: Pull complete

Digest: sha256:a68868bfe696c00866942e8f5ca39e3e31b79c1e50feaee4ce5e28df2f051d5c

Status: Downloaded newer image for hello-world:latest

Hello from Docker.

This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

1. The Docker Engine CLI client contacted the Docker Engine daemon.

2. The Docker Engine daemon pulled the "hello-world" image from the Docker Hub.

3. The Docker Engine daemon created a new container from that image which runs the

executable that produces the output you are currently reading.

4. The Docker Engine daemon streamed that output to the Docker Engine CLI client, which sent it

to your terminal.

To try something more ambitious, you can run an Ubuntu container with:

$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:

https://[hub.docker.com](http://hub.docker.com/)

For more examples and ideas, visit:

https://[docs.docker.com/userguide/](http://docs.docker.com/userguide/)

步十三:查看所有的容器

$ docker ps -a

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

推荐阅读更多精彩内容