Closed steverobbins closed 2 years ago
Try
RUN /bin/bash -c -l "cd $WORKDIR && mysql -h localhost -e 'CREATE DATABASE IF NOT EXISTS magento_travis;'"
Change localhost by the machine name or ip if the database is not on the same machine.
Due to the way build works with docker, using service during the build execution is not possible actually (see https://github.com/jolicode/JoliCi/blob/master/docs/command/run.md#starting-services)
Also the host of mysql in JoliCi is not localhost
but mysql
(service is launch in a separated container)
I will try to put a simple workaround with code and exemple in documentation on how to change your .travis.yml file to use service in both TravisCi and JoliCi.
@joelwurtz you're right !
It's not possible to link a container during build time so there's no way to use a service from another container. Unless it's already running, but then you need to hardcode it's name or ip which is not good either.
The container is restarted between each RUN
command and the service is not started automatically. You have to start it yourself.
The solution is to run the mysql
command only on first run, not during biuld time.
RUN /bin/bash -c -l "cd $WORKDIR && mysql -h localhost -e 'CREATE DATABASE IF NOT EXISTS magento_travis;'"
@joelwurtz Slightly off topic, is there a way I can boot up a container and run this command without having to kill and re-rerun jolici?
@steverobbins you can always ssh into the container though that is not the recommended way : If you run SSHD in your Docker containers, you're doing it wrong!
Or consider making a container dedicated to running mysql client.
I have a Dockerfile
ending with these lines :
COPY run.sh /run.sh
RUN chmod 0755 /run.sh
ENTRYPOINT ["/run.sh"]
CMD [""]
And the run.sh
file have the following content :
#!/bin/sh
if [ "$1" = "behat" ]; then
shift
DISPLAY=:1
xvfb-run java -jar /home/euratalent/selenium-server-standalone.jar > /dev/null 2>&1 &
/reset-env.sh
su - euratalent -c "cd /var/www/euratalent.com/www/ && bin/behat $*"
elif [ "$1" = "console" ]; then
shift
su - euratalent -c "cd /var/www/euratalent.com/www/ && php app/console $*"
elif [ "$1" = "doctrine" ]; then
shift
su - euratalent -c "cd /var/www/euratalent.com/www/ && bin/doctrine $*"
elif [ "$1" = "reset-env" ]; then
shift
/reset-env.sh $*
elif [ "$1" = "psql" ]; then
shift
psql $*
else
echo "usage:"
echo "$0 behat [arguemnts]"
echo "$0 console [arguemnts]"
echo "$0 doctrine [arguemnts]"
echo "$0 psql [arguemnts]"
fi
This allows me to run commands outside of the container as if I was inside.
Hello,
Thanks for opening this issue.
Unfortunately, we don't support this repository anymore. I'm sorry, but I'll close this issue.
I hope you understand.
When trying to run on this project I get
How can this be resolved?