2014-11-26 2 views
4

Vagrant VM 내부의 Redis를 실행하는 Docker 컨테이너를 갖고 싶습니다. 나는 가능한 한 간단 할 수있는 것들을 원하기 때문에 최소한의 구성이 필요합니다.Docker + Vagrant에 Redis를 설치하는 가장 간단한 방법은 무엇입니까

연구의 조금을 보여줍니다

그래서 설치가 정말 정직해야합니다 제공, 난 그냥에 미칠 것으로 예상 점들을 이으세요. 그래서 나는 이걸 가지고 다가왔다. Vagrantfile :

VAGRANTFILE_API_VERSION = "2" 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 
    config.vm.box = "chef/centos-6.5" 
    config.vm.provision "docker" do |docker| 
    docker.run "dockerfile/redis" 
    end 
end 

외모는 간단하다. 이제 vagrant up을 실행하면 다음과 같이 나타납니다.

  1. VM이 시작됩니다.
  2. Docker가 설치됩니다.
  3. Docker 데몬 dockerd이 시작되었습니다.
  4. Redis dockerfile/redis 용 Docker 컨테이너가 다운로드되어 설치됩니다.
  5. 컨테이너가 시작되었습니다. 이 Vagrantfile와 내가 얻을 이후

모두 3 단계를 제외하고 작동하는 것 같다 :

==> default: Verifying vmnet devices are healthy... 
==> default: Preparing network adapters... 
==> default: Starting the VMware VM... 
==> default: Waiting for machine to boot. This may take a few minutes... 
    default: SSH address: 192.168.249.190:22 
    default: SSH username: vagrant 
    default: SSH auth method: private key 
    default: Warning: Connection refused. Retrying... 
==> default: Machine booted and ready! 
==> default: Forwarding ports... 
    default: -- 22 => 2222 
==> default: Configuring network adapters within the VM... 
==> default: Waiting for HGFS kernel module to load... 
==> default: Enabling and configuring shared folders... 
    default: -- /Users/ernst/nikon/nikon-elk-vm2: /vagrant 
==> default: Running provisioner: docker... 
    default: Installing Docker (latest) onto machine... 
    default: Configuring Docker to autostart containers... 
==> default: Starting Docker containers... 
==> default: -- Container: dockerfile/redis 
The following SSH command responded with a non-zero exit status. 
Vagrant assumes that this means the command failed! 


      rm -f /var/lib/vagrant/cids/cc3cfcdebad9167099d85261c6311a0011838655 
      docker run --cidfile=/var/lib/vagrant/cids/cc3cfcdebad9167099d85261c6311a0011838655 -d --name dockerfile-redis dockerfile/redis 


Stdout from the command: 



Stderr from the command: 

2014/11/26 12:38:40 Cannot connect to the Docker daemon. Is 'docker -d' running on this host? 

내가 분명히 shell 제공자를 사용하여 되돌릴 수 있지만 내 Vagrantfile 간단한을 유지하기 위해 사랑하고를 사용합니다 Vagrant가 제공하는 docker 공급자.

그래서 나는 무엇을 놓치고 있습니까?

+0

레디 스의 offical 한 신뢰 구축이 (HTTPS 여기 그런데 : //registry.hub.docker

나는이 Vagrantfile 성공했다. co.kr/_/redis /)에 연결하십시오. 당신이 링크 한 것은 readme에서 신뢰할 수 있습니다. 소유자는 도커 아이콘을 사용했고 신뢰할 수없는 단어는 부적절하다고 생각합니다. dockerhub의 repo 이름과 "Official Repo"텍스트 뒤에 파란색 리본이 있는지 확인하십시오. –

+0

Usman : 감사합니다! 좀 더 손길을 피우지 만 실제 공식 빌드로 전환합니다. 사실 그것은 잠재적으로 불성실 한 것처럼 보입니다. –

+0

나는 당신의 질문에 대답 할 수 없으므로 항해자와 도커를 사용하지는 않았지만, 방황보다는 boot2docker를 실행하는 것이 더 나았습니다. 가능한 한 단순한 것을 원한다면 대신 사용할 수 있습니다. –

답변

2

귀하의 Vagrantfile가 올바른지.

이것은 chef/centos-6.5 상자의 문제인 것 같습니다.

이 상자에 먼저 device-mapper-libs을 업데이트해야합니다. VM의 내부

VAGRANTFILE_API_VERSION = "2" 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 
    config.vm.box = "chef/centos-6.5" 

    config.vm.provision "shell", 
    inline: "yum update -y device-mapper-libs" 

    config.vm.provision "docker" do |docker| 
    docker.run "redis" 
    end 
end 

:

[[email protected] ~]$ docker ps 
CONTAINER ID  IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES 
7d55185f859c  redis:2    "/entrypoint.sh redi 10 seconds ago  Up 9 seconds  6379/tcp   redis 
+0

감사합니다!이게 거의 ​​작동합니다. 이제 Redis가있는 Docker 컨테이너가 프로비저닝 중에 설치되고 시작됩니다. VM (''wagrant halt'' 다음에 또 다른''vagrant up''이 올 것임) Docker 컨테이너가 시작되지 않습니다. –

+0

@ErnstdeHaan 실제로 방글라데시 문서는 "부팅 할 때 특정 컨테이너를 구성하십시오."라고 말하면서 작동하지 않습니다. 내가 다른 방황 상자로도 노력했는데, 매번 프로비저닝을 수행하는 '방랑자 업 - 프로 비 저닝 (wagrant up-provision)'을 실행하는 것은 이상적이지 않습니다. o 부팅시 컨테이너를 시작하도록 수동으로 VM을 구성하려면 /etc/rc.local에'docker start redis'를 추가하십시오. 이 작업은 셸 환경에서 수행 할 수 있습니다. – Fedalto

+0

고마워. 사실, 나는 그런 식으로 의지해야 할 것 같아. 방랑하는 것은 좋지만 클라이언트 OS 전반에 걸쳐 개선 및 표준화의 기회가있는 것 같습니다. –

2

나는 공급자와 공급자를 혼동스럽게 생각합니다. 프로비저닝 프로그램은 VM 구성 환경을 제공합니다. Docker의 경우에는 docker-host에 컨테이너를 추가하여 어떤 식 으로든 VM을 "구성"할 수 있음을 의미합니다. 다른 공급자는 "쉘", "요리사"또는 "인형"입니다. 공급자는 VM 또는이 경우 컨테이너를 생성하는 도구입니다. 다른 공급자는 예를 들어 "VirtualBox"또는 "AWS"입니다.

은 여기가 시작하는 데 도움이 수있는 몇 가지 코드입니다 :

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker' 
Vagrant.configure(2) do |config| 
    config.vm.define "docker-host", autostart: false do |host| 
    host.vm.hostname = "docker-host" 
    host.vm.box = "chef/centos-6.6" 
    # The following line terminates all ssh connections. Therefore 
    # Vagrant will be forced to reconnect. 
    # That's a workaround to have the docker command in the PATH 
    host.vm.provision "shell", inline: "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill" 
    host.vm.provision "docker" 
    end 

    host.vm.define 'container', primary: true do |ws| 
    ws.vm.hostname = 'container' 
    ws.vm.provider "docker" do |d| 
     d.image = "library/redis:latest" 
     d.vagrant_machine = "dev-host" 
     d.vagrant_vagrantfile = "./Vagrantfile" 
     d.force_host_vm = true 
    end 
    end 
end 

출력 :

$ vagrant up container 
Bringing machine 'container' up with 'docker' provider... 
==> container: Docker host is required. One will be created if necessary... 
    container: Vagrant will now create or start a local VM to act as the Docker 
    container: host. You'll see the output of the `vagrant up` for this VM below. 
    container: 
    container: Importing base box 'chef/centos-6.6'... 
    container: Matching MAC address for NAT networking... 
    container: Checking if box 'chef/centos-6.6' is up to date... 
    container: Setting the name of the VM: dev-host 
    container: Clearing any previously set network interfaces... 
    container: Preparing network interfaces based on configuration... 
    container: Adapter 1: nat 
    container: Forwarding ports... 
    container: 22 => 2222 (adapter 1) 
    container: Running 'pre-boot' VM customizations... 
    container: Booting VM... 
    container: Waiting for machine to boot. This may take a few minutes... 
    container: SSH address: 127.0.0.1:2222 
    container: SSH username: vagrant 
    container: SSH auth method: private key 
    container: Warning: Connection timeout. Retrying... 
    container: Warning: Connection timeout. Retrying... 
    container: Warning: Remote connection disconnect. Retrying... 
    container: Warning: Remote connection disconnect. Retrying... 
    container: Warning: Remote connection disconnect. Retrying... 
    container: Warning: Remote connection disconnect. Retrying... 
    container: Warning: Remote connection disconnect. Retrying... 
    container: Warning: Remote connection disconnect. Retrying... 
    container: Warning: Remote connection disconnect. Retrying... 
    container: Warning: Remote connection disconnect. Retrying... 
    container: Machine booted and ready! 
    container: Checking for guest additions in VM... 
    container: Setting hostname... 
    container: Mounting shared folders... 
    container: /vagrant => <PATH> 
    container: /tmp/vagrant-cache => <PATH> 
    container: Configuring cache buckets... 
    container: Running provisioner: docker... 
    container: Installing Docker (latest) onto machine... 
    container: Configuring Docker to autostart containers... 
    container: Configuring cache buckets... 
    container: Running provisioner: shell... 
    container: Running: inline script 
    container: Configuring cache buckets... 
==> container: Syncing folders to the host VM... 
    container: Mounting shared folders... 
    container: /var/lib/docker/docker_1417023698_82709 => <PATH> 
==> container: Warning: When using a remote Docker host, forwarded ports will NOT be 
==> container: immediately available on your machine. They will still be forwarded on 
==> container: the remote machine, however, so if you have a way to access the remote 
==> container: machine, then you should be able to access those ports there. This is 
==> container: not an error, it is only an informational message. 
==> container: Creating the container... 
    container: Name: virtual-dev_container_1417023701 
    container: Image: library/redis:latest 
    container: Volume: /var/lib/docker/docker_1417023698_82709:/vagrant 
    container: 
    container: Container created: 2f020d26797f3bd0 
==> container: Starting container... 
==> container: Provisioners will not be run since container doesn't support SSH. 

사용법 :

사용 vagrant up은 레디 스 컨테이너를 시작합니다. 컨테이너의 호스트를 강제로 사용하기 때문에, 방울러는 사용할 수없는 경우 자동으로 시작합니다. vagrant up docker-host --provider=virtualbox으로 직접 호스트를 시작할 수 있습니다. 모든 것이 시작된 후 vagrant ssh docker-host을 사용하여 도커 - 호스트로 ssh 할 수 있습니다. 대부분의 Docker 컨테이너에는 SSH가 없으므로 vagrant ssh container을 사용하여 SSH를 SSH 할 수 없습니다.당신이 컨테이너에보고 할 수있는 일은 한 컨테이너가 실행되는 다음과 같은 "트릭"을 사용한다 :

  • 사용 docker ps이 컨테이너의 ID를 복사 고정 표시기 호스트로

    • SSH를
    • : 당신이 SSH없이 용기에

    추가 참고있는 지금

  • docker exec -it <ID-of-container> /bin/bash를 사용

    ENV['VAGRANT_DEFAULT_PROVIDER'] - 'docker' - 기본 제공자를 설정합니다. Docker의 경우 vagrant up --provider=docker을 입력 할 필요가 없습니다. 기본값은 virtualbox입니다.

    d.vagrant_vagrantfile = "./Vagrantfile" - 도커 호스트의 Vagrant 파일 위치를 설정합니다. 따라서 모든 컨테이너에 대해 고유 한 Vagrantfile을 가질 수 있습니다! 어쨌든,이 예제는 multi-mechine 구조를 사용합니다 [1].

    docker-host 또는 container을 명령에 추가하여 입력 할 수 있습니다. 예를 vagrant up docker-host --provider=virtualbox

    추가 읽기를 들면 :

    Vagrant Multi-Machine

    Vagrant Docker Provisioner

    Vagrant Docker Provider

  • +0

    아니요, 제공 업체와 제공 업체가 섞이지는 않습니다. VMware에서 VM을 실행하려고하지만 Docker 컨테이너에 Redis가 있습니다. 그래서 Docker 공급자를 사용하고 있습니다. 다음 단계는 해당 VM 내에 Docker 컨테이너를 더 추가하는 것입니다. –

    +1

    오케이, 미안 해요. 셸 프로비저를 시도 했습니까? 'host.vm.provision "shell", inline : "ps aux ..."내 예제에서 언급 했습니까? 호스트에서 SSH 연결을 강제 종료하여 방랑자가 다시 연결되도록하여 도커 명령이 도커를 시작하는 데 필요한 경로에 있음 – Yser

    +0

    VERSION VM 내부에서 Docker 컨테이너를 프로비저닝 할 때 권장되는 방법을 사용하는 대신 셸 공급자를 사용하는 것을 권장합니다. –

    관련 문제