How to make MySQL container run in the background when configured in docker-compose

I’ve created the docker-compose.yml file below to create a container based on Ruby image and a container based on MySQL image. When I execute docker-compose up, the MySQL container seems to be created correctly, however it is not run in the background. How can I configure it to do so using the docker-compose.yml file?

version: '2'

services:
  web:
    build: 
      context: .
      dockerfile: .docker/rails.dockerfile
    volumes: 
      - .:/var/www
    ports: 
      - "3000:3000"
    depends_on:
      - 'mysql'
    networks:
      - ddoc-network


  mysql:
    image: mysql
    environment: 
      MYSQL_ROOT_PASSWORD: 'SOMETHING'
    networks:
      - ddoc-network


networks:
  ddoc-network:
    driver: bridge

rails.dockerfile

  • docker build failing with Could not resolve 'archive.ubuntu.com'
  • nginx doesn't forward to django app in docker-compose in ubuntu but it all works in docker-machine in Mac
  • Docker not restarting and building
  • How to run a command in a container using Docker Compose?
  • How to search for an docker image in multiple private registries
  • Running the WSO2 Application Manager docker image with custom configuration
  • FROM ruby:2.3.1
    
    MAINTAINER Juliano Nunes
    
    RUN apt-get update -qq && apt-get install -y build-essential mysql-client libmysqlclient-dev nodejs
    RUN mkdir /var/www
    WORKDIR /var/www
    
    ADD Gemfile /var/www/Gemfile
    ADD Gemfile.lock /var/www/Gemfile.lock
    RUN bundle install
    ADD . /var/www
    
    CMD ['bundle', 'exec', 'rails', 'server', '-b', '0.0.0.0']
    

    CMD

  • Docker: user change in terminal prompt
  • Docker + rails 4 :, weird error during : RUN bundle exec rake assets:precompile
  • How to manage docker image dependencies (maintainance)
  • Docker Compose Link (Alias)
  • How can I connect to a server using python sockets inside a Docker container?
  • Spark standalone cluster on docker in network “bridge”
  • One Solution collect form web for “How to make MySQL container run in the background when configured in docker-compose”

    You can always use docker-compose up -d to run your containers in detached mode.

    Check docker-compose up --help for more info.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.