What's the docker hostname for the second container?

docker
2.0

#1

I’m spinning up 2 containers, but it’s not entirely clear to me how i can get the ‘hostname’ to connect from my php application container with the percona container I’ve got going on. Those containers already have environment variables set, but I don’t understand where the networking bit between the 2 containers is happening. ‘mysql’ just does not seem to work as a host for me. And in the buils output I don’t see my docker run executing.

version: 2
jobs:
build:
docker:
  # specify the version you desire here
    - image: meezaan/php-apache-7.1
  
  # Specify service dependencies here if necessary
  # CircleCI maintains a library of pre-built images
  # documented at https://circleci.com/docs/2.0/circleci-images/
    - image: meezaan/perconadb5.7
run: | 
        docker run -d -h mysql --name mysql meezaan/perconadb5.7
working_directory: /app

steps:
  - run: cd /
  - run: rm -rf /app
  - run: cd ../ && git clone https://github.com/meezaan/microservice-template.git app
  - run: composer install -n --prefer-dist
  - run: vendor/bin/doctrine orm:schema-tool:create

  # run and build tests!
  - run: vendor/bin/phpunit tests/
  - run: vendor/bin/phpcs --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=PSR2 src/
  - run: vendor/bin/phpmd src/ html cleancode,codesize,controversial,design,unusedcode --reportfile build/logs/pmd.html
  - run: vendor/bin/phpcpd --log-pmd build/logs/pmd-cpd.xml src/
  - run: vendor/bin/phploc src/ > build/logs/phploc.html
  - run: vendor/bin/phpdox

Thank you for your help!


#2

As I understand it, all Docker containers work on a merged networking stack, so bringing up MySQL in the second container should make it available in localhost.

I don’t have any experience running multiple containers in this way (since I use Docker Compose and do it all myself). However, I am not sure you can use docker run here. All run sections are run in the context of the first image, but the Docker commands will be issued on your behalf on the Circle build server (which AFAIK we don’t have direct access to). What is the console output for that docker run? I would expect it not to be installed in the PHP/Apache image.

You need a way of supplying parameters to the second image, so it is started with the parameters you want. Checking the docs, I think you need a command key.


#3

Thank you for the response.

The container starts up with what I need as I had everything setup in the Dockerfile before I build and committed it to docker hub.

The docker run actually didn’t execute - at all. I’ve removed it, but there’s still no joy.

localhost doesn’t seem to work on port 3306, anyway. I’ll see if something else is an issue and look through the command key. Thanks for pointing that out, it seems to be talking about the right stuff.


#4

Please give us all of the outputs of your build steps, including any errors in particular. Does the Doctrine schema command work? That will fail if MySQL is not reachable.

You may not need to send any commands to it, if it starts up MySQL by default (I assume it does).


#5

So i ssh’d after the build.

127.0.0.1 works, but localhost does not. Perhaps the docs need updating?


#6

Interesting. There’s been some reports of DNS resolution changing recently, maybe that’s related?


#7

Thanks halfer. It is very likely that the DNS resolution thread is identical to this problem - I’ll check the etc/hosts on the image I built - I don’t use localhost locally when I’m using docker-compose, so I looked at the host file for, well, months.

Here is the first successful build anyway - https://circleci.com/gh/meezaan/microservice-template/32

Thanks for your help!


#8