vagrant 里面不能运行 docker原理与架构,怎么回事

创建Windows 2016 TP5 Docker本地虚拟机_Docker_传送门
创建Windows 2016 TP5 Docker本地虚拟机
继之后,作者接着写了这篇创建本地虚拟机的文章,给出了Packer和Vagrant的用法,并详细说明了Packer的功能。越来越多的人开始试用Windows Docker容器,这太棒了。无论是想了解Windows上所运行的Docker引擎的当前状态,还是想亲身体验一下Windows容器来,最新的Windows Server 2016 Technical Preview 5都是一个很好的起点。不久就会有很容易上手的微软Azure模板。一旦这个补丁被合并,就意味着用户可以很容易地在Azure上创建Docker Machine。教程目前而言,创建本地的VM还是需要花费一点时间和精力的。有一些不错的教程可以指导你完成必要步骤。在Windows Server 2016 VirtualBox中创建Docker(http://blog.couchbase.com/2016/april/setup-docker-windows-server-2016),作者:Arun GuptaHyper-V中的Windows Docker容器(https://lostechies.com/gabrielschenker//windows-docker-containers/),作者:Gabriel Schenker Packer + Vagrant = Automation如果你不想全部采用手工方式完成创建工作,在你的计算机面前等待下一步操作提示,你也可以用Packer和Vagrant。Packer使用ISO文件作为输入,制作用于Vagrant环境的基本虚拟机。使用Vagrant,你可以启动一个或者多个这样的虚拟机,甚至可以形成一个Windows Docker Swarm集群。本文所使用的Packer模板可以用来创建含有Docker Engine的Windows 2016 TP5 虚拟机。这个模板已经用VirtualBox 5.0.20 和 VMware Fusion 8.1测试过。如果你用的是Windows系统,模板应该也可以在 VMware Workstation上使用。运行Packer使用Packer 0.10.0创建Vagrant基本虚拟机,只需要克隆下面的GitHub repo(https://github.com/StefanScherer/packer-windows)。git clone https://github.com/StefanScherer/packer-windows
cd packer-windows然后为VMware创建Vagrant基本虚拟机:packer build --only=vmware-iso windows_2016_docker.json或者为VirtualBox创建Vagrant基本虚拟机:packer build --only=virtualbox-iso windows_2016_docker.json这个过程大概要花上一个小时。上述步骤完成之后,当前路径中应该就会有一个box文件。将该文件添加到Vagrant:vagrant box add windows_2016_tp5_docker windows_2016_docker_vmware.box如果你既有VirtualBox环境,也有VMware环境,你也可以为这两种环境分别创建和添加基本虚拟机。你可以列出所有的base box:$ vagrant box list
windows_2016_tp5_docker (virtualbox, 0)
windows_2016_tp5_docker (vmware_desktop, 0)运行Vagrant现在你可以使用新的基本虚拟机来执行一些测试工作了。这里,我们需要访问另一个GitHub repo(https://github.com/StefanScherer/docker-windows-box)。第一步是克隆代码:git clone https://github.com/StefanScherer/docker-windows-box
cd docker-windows-box使用Vagrant 1.8.1,可以很容易地启动虚拟机,并让Docker在Windows 2016 TP5上运行:vagrant upVagrant启动VM,安装其它的Docker工具(如Machine和Compose)。同时也安装Git以便访问一些在Github(https://github.com/brogersyh/Dockerfiles-for-windows)上的Windows Dockerfile。你可以打开PowerShell来执行一些命令,例如:docker version
docker images恭喜你!你现在可以用Windows 2016 TP5上的全新Docker引擎开始工作了!Packer能做什么如果你想了解Packer在自动创建虚拟机的过程中做了什么,下面列出了Packer所运行的一些部署脚本。安装功能组件在脚本文件enable-winrm.ps1中,在打开WinRM端口让Packer登录和进行进一步准备之前,将启用一些Windows配置,如Container支持和Hyper-V(仅针对VMware)支持。安装Docker下一个脚本install-docker.ps1,用来安装Docker服务、Docker客户端和名为windowsservercore的Docker基础镜像。如果Hyper-V已启用,也会安装名为nanoserver的Docker基础镜像 。修补windowsservercore镜像因为TP5和相关的文件以及镜像很新,并且还是预发布版本,保不定哪儿还有点问题。目前我们需要这个脚本来为windowsservercore Docker镜像提速。脚本patch-boot-time-for-containers.ps1就是用来处理这个问题的。启用不安全的Docker端口2375在本地的测试环境,我们用脚本enable-docker-insecure.ps1打开不安全的Docker端口2375。你可以从运行该虚拟机的主机上远程控制Windows Docker引擎。平时使用Linux或者Mac的人更该尝试一下。一旦将来有了本地Windows VM的Docker Machine驱动程序,我更倾向于使用它来建立安全的TLS连接。添加Docker群组新的Windows Docker引擎会在一个Windows命名管道上监听消息,这与在Linux系统上监听 Unix套接字很相似。普通用户不能访问这一命名管道,所以需要使用管理员Shell来操控Docker引擎。脚本add-docker-group.ps1将选项-G docker添加到Docker引擎的启动命令,这样Windows用户组docker里的所有成员就都具有了访问命名管道的权限。该脚本还在用户vagrant添加到这个docker用户组。所以,在Vagrant虚拟机中你就可以打开一个普通的PowerShell窗口来操控Docker引擎了。删除 key.json最后一个脚本remove-docker-key-json.ps1负责删除初始安装的key.json文件。在第一次启动运行Docker引擎时,每个Vagrant虚拟机中都会创建这个文件,并且根据不同Docker引擎创建不同的ID。如果你想要构建一个Windows Docker Swarm集群,记得每个Docker引擎都需要一个不同的ID。结论由于Docker基础镜像和Docker引擎会持续更新,用Packer和Vagrant自动重建基本虚拟机就简单多了,不再需要执行那些手工操作的步骤。如果这篇文章对你有用,请分享给朋友和同事。如果你有问题或更好的建议,请留下评论。你还可以在推特@stefscherer(https://twitter.com/stefscherer)关注我。感谢滕启明对文章的审校。本文为翻译文章,点击阅读原文链接,查看原文。
觉得不错,分享给更多人看到
Docker 微信二维码
分享这篇文章
6月8日 1:21
Docker 最新文章Vagrant用户不用sudo运行docker命令常见错误及解决方法
使用的vagrant用户安装docker使运行docker相关命令时如果不加sudo会报以以下错误:
Got permission denied while trying to connect to the Docker daemon socket
at unix:///var/run/docker.sock:
Get https://%2Fvar%2Frun%2Fdocker.sock/v1.37/images/json:
dial unix /var/run/docker.sock: connect: permission denied
执行以下命令重连后解决以上问题:
sudo gpasswd -a vagrant docker使用Vagrant 在Virtual Box 上安装Docker--(补充九步构建自己的hello world Docker镜像)
使用Vagrant 在Virtual Box 上安装Docker--(补充九步构建自己的hello world Docker镜像)
利用Virtual Box和 Vagrant 两个工具的便利性,我们可以简单的就完成虚拟机镜像的管理及Docker的安装、创建及其他控制。Docker 对 vmware 的支持需要特殊的扩展支持,比较繁琐,对于学习和实验阶段来说Virtual Box是最好的选择,当然还有Hyper-v。
安装Virtual Box
Virtual Box 是和, Hyper-v 一样的虚拟软件。Virtual Box 下载地址
;因在Windows,故选择下载下来直接安装即可。
安装Vagrant
Vagrant 是一款可以结合 Virtual Box 进行虚拟机安装、 管理的软件,基于 Ruby ,因为已经编译为应用程序,所以可以不用安装 Ruby 环境。Vagrant 下载地址:在页面上选择对应平台及架构, 我选择, 安装过程没有要注意的,可一直下一步。
通过 Vagrant 安装 centos7
以下操作都在 git bash 中进行,如果不是 git bash,自行手动进行或者通过CMD/PowerShell构建。
在大空间磁盘上的某个目录中执行如下代码。
$ mkdir VM && cd VM && mkdir Vagrant
-rw-r--r-- 1 Guzho 5 5月
9 08:41 Vagrantfile
安装CentOS7
$ vagrant init centos:7
通过此命令会在 Vagrant目录下生成一个 Vagrantfile 目录,这个目录记录了通过 Vagrant 安装的镜像的名称和版本。大致内容如下, 对于我们有用的也就是没注释的那两行。
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "centos/7"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
# config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "1024"
# View the documentation for the provider you are using for more
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: &&-SHELL
apt-get update
apt-get install -y apache2
Bringing machine 'default' up with 'virtualbox' provider...
==& default: Box 'centos/7' could not be found. Attempting to find and install..
default: Box Provider: virtualbox
default: Box Version: &= 0
==& default: Loading metadata for box 'centos/7'
default: URL: https://vagrantcloud.com/centos/7
==& default: Adding box 'centos/7' (v1803.01) for provider: virtualbox
default: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/1803.
01/providers/virtualbox.box
==& default: Box download is resuming from prior download progress
default: Download redirected to host: cloud.centos.org
==& default: Successfully added box 'centos/7' (v1803.01) for 'virtualbox'!
==& default: Importing base box 'centos/7'...
==& default: Matching MAC address for NAT networking...
==& default: Checking if box 'centos/7' is up to date...
==& default: Setting the name of the VM: Vagrant_default_5_31478
==& default: Clearing any previously set network interfaces...
==& default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==& default: Forwarding ports...
default: 22 (guest) =& 2222 (host) (adapter 1)
==& default: Booting VM...
==& default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==& default: Machine booted and ready!
==& default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host on
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default: This is
everything may continue to work prope
default: in which case you may ignore this message.
==& default: Rsyncing folder: /cygdrive/c/VM/Vagrant/ =& /vagrant
$ vagrant box list
centos/7 (virtualbox, 1803.01)
启动centos7
$ vagrant up
$ vargant status
Current machine states:
running (virtualbox)
The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.
在centos上安装Docker
通过 vagrant 链接到刚才安装的centos,因为只有一个,所以命令行中可以不加此centos的名称。默认用户名和密码都是vagrant
$ vagrant ssh
Last login: Wed May
9 00:48:14 2018 from 10.0.2.2
[vagrant@localhost ~]$
清楚旧版本的Docker
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-selinux
No Match for argument: docker-engine-selinux
No Match for argument: docker-engine
No Packages marked for removal
添加Docker所需依赖
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror
(1/4): extras/7/x86_64/primary_db
(2/4): base/7/x86_64/group_gz
(3/4): base/7/x86_64/primary_db
(4/4): updates/7/x86_64/primary_db
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
Package yum-utils-1.1.31-42.el7.noarch already installed and latest version
Package device-mapper-persistent-data-0.7.0-0.1.rc6.el7_4.1.x86_64 already installed and latest version
Package 7:lvm2-2.02.171-8.el7.x86_64 already installed and latest version
Nothing to do
添加Docker源
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
安装最新的 Docker-ce
$ sudo yum install docker-ce
# 安装期间提示所有的都选择y,回车即可
Installed:
docker-ce.x86_64 0:18.03.1.ce-1.el7.centos
Dependency Installed:
audit-libs-python.x86_64 0:2.7.6-3.el7
checkpolicy.x86_64 0:2.5-4.el7
container-selinux.noarch 2:2.42-1.gitad8f0f7.el7
libcgroup.x86_64 0:0.41-13.el7
libsemanage-python.x86_64 0:2.5-8.el7
libtool-ltdl.x86_64 0:2.4.2-22.el7_3
pigz.x86_64 0:2.3.3-1.el7.centos
policycoreutils-python.x86_64 0:2.5-17.1.el7
python-IPy.noarch 0:0.75-6.el7
setools-libs.x86_64 0:3.3.8-1.1.el7
启动Docker
sudo systemctl start docker
解决权限问题
$ sudo groupadd docker
groupadd: group 'docker' already exists
$ sudo gpasswd -a vagrant docker
Adding user vagrant to group docker
Connection to 127.0.0.1 closed.
$ vagrant ssh
Last login: Wed May
9 01:43:12 2018 from 10.0.2.2
$ docker version
18.03.1-ce
API version:
Go version:
Git commit:
Thu Apr 26 07:20:16 2018
linux/amd64
Experimental: false
Orchestrator: swarm
18.03.1-ce
API version:
1.37 (minimum version 1.12)
Go version:
Git commit:
Thu Apr 26 07:23:58 2018
linux/amd64
Experimental: false
看到 Client 和 Server 都有显示,说明Docker启动正常。
运行 hello-world
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f6fdcebde73361e77
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 client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker 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 ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
看到有 Hello from Docker! 输出即可证明 Docker 安装正确并能运行。
利用Virtual Box和 Vagrant 两个工具的便利性,我们可以简单的就完成虚拟机镜像的管理及Docker的安装、创建及其他控制。Docker 对 vmware 的支持需要特殊的扩展支持,比较繁琐,对于学习和实验阶段来说Virtual Box是最好的选择,当然还有Hyper-v。如果有Hyper-v,也可以使用docker-machine 来管理Docker。
用云栖社区APP,舒服~
【云栖快讯】诚邀你用自己的技术能力来用心回答每一个问题,通过回答传承技术知识、经验、心得,问答专家期待你加入!&&
提供了高性能可伸缩的容器应用管理服务,支持在一组云服务器上通过Docker容器来进行应用生命...
提供一种性能卓越、稳定、安全、便捷的计算服务,帮助您快速构建处理能力出色的应用,解放计算给服...
兼容Jenkins标准,可提供快速可靠的持续集成与持续交付服务。基于容器技术和阿里云基础服务...
为您提供简单高效、处理能力可弹性伸缩的计算服务,帮助您快速构建更稳定、安全的应用,提升运维效...
阿里云总监课正式启航使用 Vagrant 和 Docker 在一个 VM 中进行开发 - 技术翻译 - 开源中国社区
使用 Vagrant 和 Docker 在一个 VM 中进行开发
【已翻译100%】
英文原文:
推荐于 4年前 (共 9 段, 翻译完成于 10-09)
参与翻译&(4人)&: ,
1. 用Vagrant开发很酷-一个项目/组件一个VB
2. 用Vagrant开发很垃圾-缓慢的Chef/Puppet/Ansible,多个巨大的VM,遍地重复的软件。
3. Docker带来独立的仅有一个VM的VM盒子。
4. CoreOS内整合了docker,&产品发布时候会做得很完美。
5. &开发者开心!编码和发布太容易了。
像我,你可以(或不可以)喜欢用Vagrant发布。为一个项目存储使用多个VM是不可思议的: 像Ansibe之类的工具意味着你的VM将总是反映产品的环境。
假如你是揽活的人或者有许多项目,然而,可能是你有几十个Vagrant盒子在你的dev文件夹,慢慢吸收上亿磁盘空间。这是vagrant 垃圾的地方。。。提别是有多个小SSD的时候。
进入:. 一个从一个机器上管理容器的开源的工具。为所有我们的来自一个VM的项目,我们将使用容器作为“迷你vagrants".我假设你这里用的是Mac-我不了解windows.
让我们投入docker!&
&翻译得不错哦!
步骤一:设置CoreOS
我们要使用CoreOS和Vagrant来安装Docker, 取代Docker推荐的Ubuntu vagrant 文件安装。Screw的建议。
为什么用CoreOS?
CoreOS是一个雄心勃勃的旨在简单、可伸缩服务部署的linux发行版。它是轻量级的,并且自带Docker的预安装。它的目的是让服务Docker-based应用变得容易。这就是为什么选择该OS(系统)的原因-文件体积小、建议的安装方式都值得称赞!所以、我真的想去实测一下它。
Note:CoreOS在alpha中已被创建。这意味着它在SSH回话中,可能发生随机重启的现象,但从长远的角度来看,希望是有帮助的。这个是需要注意下的。
&翻译得不错哦!
你从CoreOS的Github的仓库中进行安装,CoreOS团队做了一个非常棒的工作。
你只需要按照下面的要求去做:
安装1.3.1版本以上的Vagrant和4.0版本以上的VirtualBox。 你可以通过vagrant --version命令检查你的vagrant版本,如果需要下载新的版本可以从vagrant的官网上去下载。
下载已经提供含有你开发使用根目录文件夹的CoreOS vagrant文件。在Vagrant中会安装CoreOS。
添加端口转发到Vagrant的web服务器: 命令是:config.vm.network :forwarded_port, guest: 80, host: 8080
需要注意的是默认情况下共享文件夹没有启用: 可以通过下面的命令开启你vagrant文件的共享文件夹: config.vm.network "private_network", ip: "10.1.2.3"&*config.vm.synced_folder ".",&& "/home/core/share", id: "core", :nfs =& true, :mount_options =& ['nolock,vers=3,udp']* 我们已经修改了IP地址,CoreOS提供了专用网络:他们使用的IP地址是在公共地址的范围内(即别人公开的可访问的机器)。整个10.X.X.X的IP地址段都是私有的,这样的话可以避免冲突。
你可能已经清楚了安装步骤:我们已经创建了一个vagrant文件,添加了连接CoreOS分布式的URL,设置了共享文件夹的网络。和其他Vagrant的配置步骤相似,只是没有其他的Chef/Puppet/Ansible。
CoreOS已经预先安装好了docker,所以不需要马上做一些配置和软件的安装。
&翻译得不错哦!
第二步: 设置Docker
Docker已经安装了,但是它需要一个“基础图像”来运行。&我们所有的容器都将会在这个OS中运行。 本质上, 是所有项目的OS虚拟机。 我们使用ubuntu:
& docker pull ubuntu
这下载了所有我们会用到的ubuntu基础图像(12.04, 12.10)。让我们来确认一下这个步骤创建了一个新的容器(说明如下):
& docker run -name="test" -t -i ubuntu /bin/bash
下面我们要做的依次是:
让Docker创建开始并且运行一个新的容器(docker run)
命名新的容器为“test”(name="test"). 这让我们操作容器变得更简单,并且当我们列出容器时,我们就知道哪个是哪个了。
创建一个违终端,并让其保持打开(-t -i)
让ubuntu成为新容器的基础图像(ubuntu)
在新容器中运行/bin/bash.
Docker需要一个程序来运行一个容器. 更重要的。这包括两层意思: 容器不能脱离程序而运行,&&&&并且当程序结束时容器也将结束. 我们以后将继续讨论这个问题.
你现在在CoreOS的一个Ubuntu容器中.一个小型的Ubuntu虚拟机就可以用了。
&翻译得不错哦!
第三步: 创建开发环境
现在我们可以离开Docker了. 我们要设置一个基础的LAMP堆栈, 这是很容易安装的. 根据你自己的需要调整这个堆栈也是很重要的.
我们将通过命令行来操作容器, 而不是通过Docker文件. 这是对docker如何工作的介绍.
我们已经在Ubuntu容器中了。 如果不是, 重新运行上面的命令来启动一个Ubuntu容器.
Ubuntu是一个很小的容器. 其中有很多我们需要的东西都没有装.基本操作如下:
增加&universe/multiverse&到apt源: & echo "$(cat /etc/apt/sources.list) universe multiverse" & /etc/apt/sources.list 这是增加&' universe multiverse' 到apt-get的源列表. 正如之前所说, 这是一个准Ubuntu系统的安装,并且在默认时是不具备的.
& apt-get update
安装&curl, wget, vim, build-essential, git: & apt-get install curl wget vim-tiny
我们基本上完成了环境的搭建.首先,将这些改变提交给新的Docker容器。这样我们就不用每次都这么做了(注: 这也是你使用Dockerfiles文件的原因.)
&翻译得不错哦!
试想想Docker当做是git.&&我们已经对Ubuntu做了一些修改, 必须承认这减少了我们的工作量.
和Git一样, Docker减少了每个容器的差别,而不是整个系统. 这意味着我们至于要保存我们安装的软件以及我们改变的文件. 多厉害!
退出Ubuntu容器: & ctrl-d 这将使容器消失. 我们用the/bin/bash程序开始容器 (& docker run -name="test" -t -i ubuntu /bin/bash), 并且当这个开始程序结束时这个容器也就消失了.
列出所有Docker容器: & docker ps -a -a选项列出了所有的容器.docker ps列出了运行的容器.
我们在列表中可以看见自己的容器:
CONTAINER&ID&&&&&&&&IMAGE&&&&&&&&&&&&&&&COMMAND&&&&&&&&&&&&&CREATED&&&&&&&&&&&&&STATUS&&&&&&&&&&&&&&PORTS&&&&&&&&&&&&&&&NAMES
4bf2ba69c69c&&&&&&&&ubuntu:12.04&&&&&&&&/bin/bash&&&&&&&&&&&5&seconds&ago&&&&&&&Exit&0&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&test
提交改变给新的容器: & docker commit test custom/base 我们已经使用ID而不是名字写了docker commit 4bf2b custom/base 来只是我们改变的那个容器.
这创建了一个叫做custom/base的新容器,这个新容器保存了所有已经做过的修改.和Ubuntu一样我们可以启动这个容器docker run [...] custom/base.这就好了.
可以通过键入docker images查看可用的容器. 你会看见新的Ubuntu图像,以及新的custom/base图像.
这是基础: 创建一个包含部分修改的新容器(用命令行也行, 但最好使用文件),并且提交和运行.
&翻译得不错哦!
建立协议栈
我们将安装一个基于我们创建的容器的LAMP协议栈. 这不是必须的,安装 python, ruby, golang可以由你自己来选择.
首先,用下列步骤来创建一个新的容器:
& docker run -name="lamp" -t -i custom/base /bin/bash
这个shell已经装载了我们刚才修改的那个容器.再为我们的基础协议栈安装mysql、apache和PHP.
& apt-get install apache2 mysql-server php5 libapache2-mod-php5
厉害. 跳过这些服务的配置,因为其中有很简单的向导. 如果失败了就加入头.
软件安装和配置完成了, 将这些修改提交给新的容器. 按ctrl-d回到CoreOS, 然后按照如下方法提交容器:
& docker commit lamp custom/lamp
&翻译得不错哦!
运行协议栈并且转发端口
我们已经做到了可以开始使用Docker容器这一步. 不过有几个前提条件: 转发端口, 并且是数据库和网络服务可以自动运行.
幸运的, 端口可以通过命令行轻松设置(用dockerfiles文件设置更简单):
& docker run -t -i -p 80:80 -p
-v /home/core/vagrant/project:/var/www/project custom/lamp /bin/bash
接下来我们要做:
再次使用伪shell运行容器(-t -i)
将容器端口80和3306设置的和CoreOS相同的端口 (-p 80:80 -p )
从CoreOS 安装一个卷到容器, 同时这个卷也被安装在Vagrant上. 这是装在我们机器上的开发文件(-v /from:/to)
现在, 我们可以通过localhost:8080(由Vagrant转发的端口)在容器中运行的网络服务了. 整理一下环境,现在可以开始开发我们的应用了.
&翻译得不错哦!
从这里开始
你应该熟悉docker的高级功能,如提交、运行、图像以及通过向导创建新的工作开发环境。
通过docker可以做很多事情. 以下一些你可以参考:
&- 需要一个在容器中运行的程序来保持它处于活动状态. Supervisord 是一个可以再前台运行的管理程序. 在supervisord.conf文件中设置你的服务并且通过docker启动supervisord来保持你的容器处于活动状态.
在你的机构里面分享容器和图像.保持你的开发环境健全,使开发更简单.
的数据库管理 - 在Docker中数据存储(storage in general, actually)是较难管理的. 在docker中有一个相关的向导. 更多信息,, and .
文件 -这将使你不必手动创建容器.
&翻译得不错哦!
我们的翻译工作遵照 ,如果我们的工作有侵犯到您的权益,请及时联系我们
@小猪猪0406 修改下:)

我要回帖

更多关于 docker运行内存不足 的文章

 

随机推荐