35

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

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

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

I checked ip of my virtual machine

$ docker-machine ip 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

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.

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 :-)

Thanks.

User
  • 1,978
  • 5
  • 26
  • 47

1 Answers1

80

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.

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.

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 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.

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.

AlexChaffee
  • 8,092
  • 2
  • 49
  • 55
  • 1
    I usually wokr on linux, so I dropped docker-machine and it looks better now :-) – User Jul 28 '16 at 09:28
  • My comment seems to be late but anyway: may I set docker-machine env properties right in the Windows Env Variables to not type them every time I open a shell? Are there any implications of that? – Dedyshka Mar 16 '17 at 08:39
  • You can't hardcode them because they may change. (Virtual network interface addresses, that sort of thing.) On Linux I wrote a login script that did that `eval` above to set them into the shell environment, but I don't know how to make that magic work in Windows. – AlexChaffee Apr 24 '17 at 02:08
  • I feel much easier to use `docker-machine use default` instead of `eval $(...)`. – steppo May 31 '17 at 10:39
  • 2
    If a docker machine is for OSX/Windows, why is there a linux version? https://docs.docker.com/machine/install-machine/#installing-machine-directly – Alston Jul 31 '17 at 08:51
  • 1
    @Alston because (a) why not? you can run VMs on Linux so why not run Docker on those VMs with Docker-Machine? (b) It's got remote provisioning and management features now, so you can use Linux as a client to manage remote docker-machine instances (or clusters or swarms or whatever). – AlexChaffee Sep 15 '17 at 16:54
  • @steppo `docker-machine use` may not have been available when I wrote that answer, and at any rate only works inside `bash` as a contributed extension, not part of the supported docker-machine CLI: https://github.com/docker/machine/blob/master/contrib/completion/bash/docker-machine-wrapper.bash – AlexChaffee Sep 15 '17 at 16:58
  • @AlexChaffee very concise answer. Can you also please mention what docker swarm is? :P – Prakhar Agrawal Sep 29 '17 at 07:20
  • @PrakharAgrawal sorry, even I don't understand docker swarm! :-) (yet) – AlexChaffee Oct 09 '17 at 13:01
  • @PrakharAgrawal Docker Swarm is multi-host container orchestration platform. Something like K8s. – Vino Sep 10 '19 at 23:13