docker-compose run does not run the entrypoint scripts of dependent services

拜拜、爱过 提交于 2020-04-17 22:16:07

问题


I am trying to run a one time command on my application container using the command

docker-compose run --entrypoint="/usr/src/app/migrate.sh" app

app is the name of my service and the said entrypoint contains the one-time command that I'm trying to run. Here's my docker-compose.yml file

version: '3'
services:
  app:
    build: .
    # mount the current directory (on the host) to /usr/src/app on the container, any changes in either would be reflected in both the host and the container
    volumes:
      - .:/usr/src/app
    # expose application on localhost:36081
    ports:
      - "36081:36081"
    # application restarts if stops for any reason - required for the container to restart when the application fails to start due to the database containers not being ready
    restart: always
    depends_on:
      - db1
      - db2
    # the environment variables are used in docker/config/env_config.rb to connect to different database containers
    environment:
      MYSQL_DB1_HOST: db1
      MYSQL_DB1_PORT: 3306
      MYSQL_DB2_HOST: db2
      MYSQL_DB2_PORT: 3306
  db1:
    image: mysql/mysql-server:5.7
    environment: 
      MYSQL_DATABASE: test1
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    # mount volume of the schema script to /docker-entrypoint-initdb.d to execute the script on startup  
    volumes:
      - ./docker/seed/db1:/docker-entrypoint-initdb.d
      - db1-volume:/var/lib/mysql
    restart: always
    # to connect locally from SequelPro
    ports:
      - "1200:3306"
  db2:
    image: mysql/mysql-server:5.7
    environment: 
      MYSQL_DATABASE: test2
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    # mount volume of the schema script to /docker-entrypoint-initdb.d to execute the script on startup  
    volumes:
      - ./docker/seed/db2:/docker-entrypoint-initdb.d
      - db2-volume:/var/lib/mysql
    restart: always
    # to connect locally from SequelPro
    ports:
      - "1201:3306"

Everything works as expected when I start docker-compose up, but when I invoke docker-compose run, the dependent services db1 and db2 containers are up, but they are not initialised with the entrypoint script(as a result the mySQL database is not created). The volume is attached though.
How can I ensure that the entrypoint script of the dependent containers is invoked as well?

来源:https://stackoverflow.com/questions/60445625/docker-compose-run-does-not-run-the-entrypoint-scripts-of-dependent-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!