docker-machine和docker-compose有什么区别? [英] What is the difference between docker-machine and docker-compose?

查看:371
本文介绍了docker-machine和docker-compose有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我不明白。首先,我创建了docker-machine:

I think I don't get it. First, I created docker-machine:

$ docker-machine create -d virtualbox dev
$ eval $(docker-machine env dev)

然后我写了Dockerfile和docker-compose.yml:

Then I wrote Dockerfile and docker-compose.yml:

FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/


version: '2'
services:
  db:
    image: postgres
  web:
    build: .
    restart: always
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    links:
      - db

最后,我建立并开始镜像:

Finally, I built and started the image:

$ docker-compose build --no-cache
$ docker-compose start

我检查了虚拟机的ip

I checked ip of my virtual machine

$ docker-machine ip dev

并成功在浏览器中打开了该站点。但是,当我对代码进行一些更改时,什么也没发生。因此,我登录了 dev计算机:

and successfully opened the site in my browser. But when I made some changes in my code - nothing happened. So I logged to the "dev" machine:

$ docker-machine ssh dev

,但是我找不到我的代码!所以我登录到docker web映像:

and I didn't find my code! So I logged to the docker "web" image:

$ docker exec -it project_web_1 bash

并且有一个代码,但未更改。

and there was a code, but unchanged.

什么是docker-机用?什么意思为什么docker更改后不同步文件?看起来docker + docker-machine + docker-compose在本地开发的痛苦中...:-)

What is the docker-machine for? What is the sense? Why docker doesn't syncing files after changes? It looks like docker + docker-machine + docker-compose are pain in the a...s for local development :-)

谢谢。

推荐答案

Docker 是使用容器化来管理多个映像以及容器和卷,例如-容器基本上是轻量级的虚拟机。有关大量文档,请参见 https://docs.docker.com/

Docker is the command-line tool that uses containerization to manage multiple images and containers and volumes and such -- a container is basically a lightweight virtual machine. See https://docs.docker.com/ for extensive documentation.

直到最近Docker尚未在本机Mac或Windows OS上运行,因此创建了另一个工具 Docker-Machine ,该工具创建了一个虚拟机(使用另一个工具,例如 Oracle VirtualBox ),在该VM上运行Docker,并帮助协调主机OS和Docker VM。

Until recently Docker didn't run on native Mac or Windows OS, so another tool was created, Docker-Machine, which creates a virtual machine (using yet another tool, e.g. Oracle VirtualBox), runs Docker on that VM, and helps coordinate between the host OS and the Docker VM.

由于Docker不在运行您的实际主机操作系统 docker-machine 需要处理IP地址,端口和卷等。其设置保存在环境变量中,这意味着您每次打开新的Shell时都必须运行以下命令:

Since Docker isn't running on your actual host OS, docker-machine needs to deal with IP addresses and ports and volumes and such. And its settings are saved in environment variables, which means you have to run commands like this every time you open a new shell:

eval $(docker-machine env default)
docker-machine ip default

Docker-Compose 本质上是Docker本身之上的一个更高级别的脚本接口,这使得(表面上)更易于管理同时启动多个容器。它的配置文件( docker-compose.yml )令人困惑,因为其某些设置被传递到了较低级别的docker进程,而有些仅在较高级别上使用

Docker-Compose is essentially a higher-level scripting interface on top of Docker itself, making it easier (ostensibly) to manage launching several containers simultaneously. Its config file (docker-compose.yml) is confusing since some of its settings are passed down to the lower-level docker process, and some are used only at the higher level.

我同意那是一团糟;我的建议是从单个Dockerfile开始,并使其通过 docker-machine 新的Beta本机Mac / Windows Docker ,并忽略 docker-compose 直到您对下层工具感到更满意为止。

I agree that it's a mess; my advice is to start with a single Dockerfile and get it running either with docker-machine or with the new beta native Mac/Windows Docker, and ignore docker-compose until you feel more comfortable with the lower-level tools.

这篇关于docker-machine和docker-compose有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆