vtambourine
vtambourine

Reputation: 2149

How to deploy docker-composed application with docker-machine?

How to deploy docker-compose app with simple Rails application using docker-machine? And does it make sense?

I have read multiple articles on that topic, including official Docker docs on using Compose in production and Remote Deployment Guide by Rackspace, but none of it actually works for me.

I have a pretty simple Rails app described by the following docker-compose file:

version: '3'

services:

  app:
    build:
      context: .
      dockerfile: containers/production/Dockerfile
    image: projectname:app
    command: containers/production/bootstrap.sh
    ports:  
      - 3000:3000
    volumes:
      - .:/app
      - gems:/gems
    depends_on:
      - db
    environment:
      - DOCKERIZED=1

  db:
    image: postgres:9.6
    ports:
      - '5432:5432'
    volumes:
      - data:/var/lib/postgresql/data

volumes:
  data:
  gems:

Next I'm trying to deploy it to remote host using docker-machine:

eval "$(docker-machine env production)"
docker-compose build
docker-compose up -d

First two steps works perfectly well. Docker host attached to local Compose, app image built, db container started on production. But launching app failed:

Creating projectname_app_1 ...
Creating projectname_app_1 ... error

ERROR: for projectname_app_1  Cannot start service app: oci runtime error: container_linux.go:262: starting container process caused "exec: \"containers/production/bootstrap.sh\": stat containers/production/bootstrap.sh: no such file or directory"

Looks like I'm missing some important concepts about Machine. How I supposed to write production Compose files to make them work on remote containers host?

Upvotes: 0

Views: 288

Answers (1)

eLRuLL
eLRuLL

Reputation: 18799

from what I see in the error message, looks like your problem is that containers/production/bootstrap.sh doesn't exist inside the docker instance. the command executes a script inside the docker container, and not in the host machine.

Copy the script into the workdir of the container, and execute it with something like ./bootstrap.sh, or maybe something like this could help too:

app:
build:
  context: .
  dockerfile: containers/production/Dockerfile
image: projectname:app
command: /bootstrap.sh
ports:  
  - 3000:3000
volumes:
  - .:/app
  - gems:/gems
  - ./containers/production/bootstrap.sh:/bootstrap.sh
depends_on:
  - db
environment:
  - DOCKERIZED=1

Check that I am matching a file on host with their respective path inside the container (/bootstrap.sh) and executing that in command

Upvotes: 1

Related Questions