Skip to content

Use the /etc/hosts entry for connecting to mysql and use the env only to detect the presence of the link #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2015
Merged

Use the /etc/hosts entry for connecting to mysql and use the env only to detect the presence of the link #42

merged 1 commit into from
Jan 22, 2015

Conversation

tianon
Copy link
Member

@tianon tianon commented Jan 16, 2015

Fixes #41

@oliveagle would you be willing to test and make sure this solves your particular issue?

@oliveagle
Copy link

I'm not sure if I'm doing it correct

  1. I'm on infosiftr/env-only-for-link-presense-detection branch

    $ git status
    # On branch infosiftr/env-only-for-link-presense-detection
    nothing to commit (working directory clean)
    
    $ git remote -v
    infosiftr       https://github.com/infosiftr/wordpress.git (fetch)
    infosiftr       https://github.com/infosiftr/wordpress.git (push)
    origin  https://github.com/docker-library/wordpress.git (fetch)
    origin  https://github.com/docker-library/wordpress.git (push)
    
    $ git log -p
    commit 9aae24350b9c4ede3d5db9cdac1ba88c3202fe98
    Author: Tianon Gravi <[email protected]>
    Date:   Fri Jan 16 10:30:54 2015 -0700
    
    Use the /etc/hosts entry for connecting to mysql and use the env only to detect the presence of the link
    
    diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
    index f6797ee..e2c3f1b 100755
    --- a/docker-entrypoint.sh
    +++ b/docker-entrypoint.sh
    @@ -64,7 +64,7 @@ set_config() {
        sed -ri "s/((['\"])$key\2\s*,\s*)(['\"]).*\3/\1$sed_escaped_value/" wp-config.php
    }
    
    -WORDPRESS_DB_HOST="${MYSQL_PORT_3306_TCP#tcp://}"
    +WORDPRESS_DB_HOST='mysql'
  2. make sure linked wordpress-mysql:mysql running on 172.17.0.2

    $ docker run -ti --rm --link wordpress-mysql:mysql busybox ping -c 2 "mysql" && date
    PING mysql (172.17.0.2): 56 data bytes
    64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.955 ms
    64 bytes from 172.17.0.2: seq=1 ttl=64 time=0.058 ms
    
    --- mysql ping statistics ---
    2 packets transmitted, 2 packets received, 0% packet loss
    round-trip min/avg/max = 0.058/0.506/0.955 ms
    Mon Jan 19 03:02:28 UTC 2015
  3. docker build -t "wordpress-ole-test" .

docker build -t "wordpress-ole-test" .
Sending build context to Docker daemon 185.9 kB
Sending build context to Docker daemon 
Step 0 : FROM php:5.6-apache
---> 13a3bdec5726
Step 1 : RUN apt-get update && apt-get install -y rsync && rm -r /var/lib/apt/lists/*
---> Using cache
---> 97ede32414b3
Step 2 : RUN a2enmod rewrite
---> Using cache
---> 60e23f9e3cd2
Step 3 : RUN apt-get update && apt-get install -y libpng12-dev && rm -rf /var/lib/apt/lists/*   && docker-php-ext-install gd    && apt-get purge --auto-remove -y libpng12-dev
---> Using cache
---> 5ea0076d5bb7
Step 4 : RUN docker-php-ext-install mysqli
---> Using cache
---> 69387ad66963
Step 5 : VOLUME /var/www/html
---> Using cache
---> 6e0782896a9b
Step 6 : ENV WORDPRESS_VERSION 4.1.0
---> Using cache
---> 7557b68183af
Step 7 : ENV WORDPRESS_UPSTREAM_VERSION 4.1
---> Using cache
---> b6a84ec2533c
Step 8 : ENV WORDPRESS_SHA1 f0437c96ae3d8acaba3579566f1346f4cd06468e
---> Using cache
---> 12a56efd6c84
Step 9 : RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz  && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -      && tar -xzf wordpress.tar.gz -C /usr/src/       && rm wordpress.tar.gz
---> Using cache
---> f88715c4ed8c
Step 10 : COPY docker-entrypoint.sh /entrypoint.sh
---> Using cache
---> 2fb3b8589856
Step 11 : ENTRYPOINT /entrypoint.sh
---> Using cache
---> c28d460f5e36
Step 12 : CMD apache2-foreground
---> Using cache
---> ef13f96b5a33
Successfully built ef13f96b5a33
  1. run docker:

    $ docker run --link wordpress-mysql:mysql -ti --rm -e WORDPRESS_DB_PASSWORD='$MYSQL_ROOT_PASSWORD'  wordpress-ole-test /bin/bash
    
    WordPress not found in /var/www/html - copying now...
    WARNING: /var/www/html is not empty - press Ctrl+C now if this is an error!
    + ls -A
    index.html
    + sleep 10
    Complete! WordPress has been successfully copied to /var/www/html
    
    Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'root'@'172.17.0.34' (using password: YES) in - on line 5
    MySQL Connection Error: (1045) Access denied for user 'root'@'172.17.0.34' (using password: YES)
    
    
    $ docker run --link wordpress-mysql:mysql -ti --rm -e WORDPRESS_DB_PASSWORD='$MYSQL_ROOT_PASSWORD' wordpress-ole-test /bin/bash
    
    WordPress not found in /var/www/html - copying now...
    WARNING: /var/www/html is not empty - press Ctrl+C now if this is an error!
    + ls -A
    index.html
    + sleep 10
    Complete! WordPress has been successfully copied to /var/www/html
    
    Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'root'@'172.17.0.35' (using password: YES) in - on line 5
    MySQL Connection Error: (1045) Access denied for user 'root'@'172.17.0.35' (using password: YES)
    
    
    // with  -e WORDPRESS_DB_HOST='172.17.0.2' 
    $ docker run --link wordpress-mysql:mysql -ti --rm -e WORDPRESS_DB_PASSWORD='$MYSQL_ROOT_PASSWORD' -e WORDPRESS_DB_HOST='172.17.0.2' wordpress-ole-test /bin/bash
    WordPress not found in /var/www/html - copying now...
    WARNING: /var/www/html is not empty - press Ctrl+C now if this is an error!
    + ls -A
    index.html
    + sleep 10
    Complete! WordPress has been successfully copied to /var/www/html
    
    Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'root'@'172.17.0.38' (using password: YES) in - on line 5
    MySQL Connection Error: (1045) Access denied for user 'root'@'172.17.0.38' (using password: YES)

@yosifkit
Copy link
Member

@oliveagle, I just noticed in your docker run you have -e WORDPRESS_DB_PASSWORD='$MYSQL_ROOT_PASSWORD'. This will not work as you expect, this will set the password to the literal string "$MYSQL_ROOT_PASSWORD" and would not be evaluated in any way. This could be the cause of your denied, though I am not sure on the "ip changes" that you are seeing.

This is the way that I run it (wordpress gets the root password from the ENV vars in the link):

$ docker run -d --name some-mysql -e MYSQL_ROOT_PASSWORD=qwerqwer mysql
$ docker run -d --name wordpress-instance --link some-mysql:mysql -p 8080:80  wordpress

@oliveagle
Copy link

I did set MYSQL_ROOT_PASSWORD while start mysql,

$ docker-enter wordpress-mysql env
HOSTNAME=6bdd37b885fa
MYSQL_VERSION=5.6.22
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
SHLVL=0
HOME=/root
MYSQL_MAJOR=5.6
MYSQL_ROOT_PASSWORD=xxxxxxxxx

start workdpress without -e WORDPRESS_DB_PASSWORD, I got this:

# build from branch infosiftr:env-only-for-link-presense-detection
$ ID=$(docker run -d --link wordpress-mysql:mysql -p 8080:80  wordpress-ole-test)     
$ docker logs $ID
error: missing required WORDPRESS_DB_PASSWORD environment variable
  Did you forget to -e WORDPRESS_DB_PASSWORD=... ?

  (Also of interest might be WORDPRESS_DB_USER and WORDPRESS_DB_NAME.)
# original 
$ ID=$(docker run -d --link wordpress-mysql:mysql -p 8080:80  wordpress)         
$ docker logs $ID
error: missing required WORDPRESS_DB_PASSWORD environment variable
  Did you forget to -e WORDPRESS_DB_PASSWORD=... ?

  (Also of interest might be WORDPRESS_DB_USER and WORDPRESS_DB_NAME.)

@tianon
Copy link
Member Author

tianon commented Jan 20, 2015

What's your docker version? The output of docker info might be helpful too.

@oliveagle
Copy link

$ docker version
Client version: 1.3.2
Client API version: 1.15
Go version (client): go1.3.3
Git commit (client): 39fa2fa/1.3.2
OS/Arch (client): linux/amd64
Server version: 1.3.2
Server API version: 1.15
Go version (server): go1.3.3
Git commit (server): 39fa2fa/1.3.2

@tianon
Copy link
Member Author

tianon commented Jan 22, 2015

$ docker build -t wordpress:env .
Sending build context to Docker daemon 208.4 kB
Sending build context to Docker daemon 
Step 0 : FROM php:5.6-apache
 ---> 13a3bdec5726
...
Successfully built c48e6058c6bd
$ docker run --name some-mysql -d -e MYSQL_ROOT_PASSWORD=lolwut mysql
ac5ee3e57aaef3b15819e204109bc70c1e70668139251c4d9650a9ad88ec4352
$ docker run --name some-wordpress -d --link some-mysql:mysql wordpress:env
18db749afef2b9f2058b80616170dfa1d87f0235f5cf5d38d2c37ee43c0f7465
$ docker logs some-wordpress
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.66. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.66. Set the 'ServerName' directive globally to suppress this message
[Thu Jan 22 21:55:14.043763 2015] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.4 configured -- resuming normal operations
[Thu Jan 22 21:55:14.043804 2015] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
$ docker restart some-mysql
some-mysql
$ curl -sSL "$(docker inspect -f '{{.NetworkSettings.IPAddress}}' some-wordpress)"
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>WordPress &rsaquo; Installation</title>
....

@yosifkit
Copy link
Member

LGTM

yosifkit added a commit that referenced this pull request Jan 22, 2015
…ction

Use the /etc/hosts entry for connecting to mysql and use the env only to detect the presence of the link
@yosifkit yosifkit merged commit 1ded80a into docker-library:master Jan 22, 2015
@yosifkit yosifkit deleted the env-only-for-link-presense-detection branch January 22, 2015 22:32
tianon added a commit to infosiftr/stackbrew that referenced this pull request Jan 26, 2015
- `golang`: update to use `buildpack-deps:*-scm` (docker-library/golang#38)
- `mongo`: replace 2.8 with 3.0.0-rc6 (docker-library/mongo#19)
- `php`: 5.4.37, 5.5.21, 5.6.5
- `tomcat`: 8.0.18
- `wordpress`: use `/etc/hosts` instead of env (docker-library/wordpress#42) and add simple mysql-retry logic to entrypoint (docker-library/wordpress#48)
@zuoyue
Copy link

zuoyue commented Mar 9, 2015

Sorry I didn't read the whole thread. But after I just read it, I still couldn't understand what was oliveagle's original problem and why this change solved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mysql IP increasing automatically?
6 participants