skip to Main Content

Is it possible to connect to external container in entrypoint and upload DB dump to it?

I always get web_1 exited with code 0 on this line execution: mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < magento-sample-data-1.9.1.0/magento_sample_data_for_1.9.1.0.sql in install-sampledata from Dockerfile

However, I can do docker exec -it <> bash after containers creation, execute install-sampledata there and it works

I have such docker-compose

version: '2.1'

services:
  db:
    image: mysql:5.6.23
    volumes:
      - db-data:/var/lib/mysql/data
    env_file:
      - env
  web:
    build: .
    ports:
      - "8089:80"
    links:
      - db
    env_file:
      - env
    tty: true
volumes:
  db-data:  

Dockerfile

FROM alexcheng/magento

ENTRYPOINT install-sampledata

and install-sampledata file

#!/usr/bin/env bash

cd /tmp
cp /opt/magento-sample-data-1.9.1.0.tgz .
tar xvf magento-sample-data-1.9.1.0.tgz
cp -R magento-sample-data-1.9.1.0/media/* /var/www/htdocs/media/
cp -R magento-sample-data-1.9.1.0/skin/* /var/www/htdocs/skin/
chown -R www-data:www-data /var/www/htdocs/media

mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < magento-sample-data-1.9.1.0/magento_sample_data_for_1.9.1.0.sql

3

Answers


  1. The problem is: your ENTRYPOINT is install-sampledata: a script which will run one mysql command and… exit!
    At this point the container will stop.

    If possible, it is best to call that script, and then call mysql as in the mysql Dockerfile, in order to leave a foreground process running.

    Or you can have a look at multi-stage build, in order to build an image with your pre-requisite files already baked in.


    Login or Signup to reply.
  2. You have an entry point in mysql containers that allows you to have the container use your mysql dump upon startup. Make a volume to here /docker-entrypoint-initdb.d and you’re container will populate your database.

    Login or Signup to reply.
  3. Add

    sh -c /bin/bash

    at last to your install-sampledata script. It will start a new process bash with a new pid. So your container will not die.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search