Skip to content
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

listen tcp 0.0.0.0:3306: bind: address already in use #9

Closed
resurtm opened this issue Jan 15, 2017 · 5 comments
Closed

listen tcp 0.0.0.0:3306: bind: address already in use #9

resurtm opened this issue Jan 15, 2017 · 5 comments

Comments

@resurtm
Copy link

resurtm commented Jan 15, 2017

Hello @mikehaertl!

First of all thank you for this project. 😀

I'm not very experienced with Docker, but here's my issue. I have just followed the README. Here's what I had so far:

resurtm@resurtm-desktop:~/dev/codemix-yii2-dockerized$ docker-compose up
Building web
Step 1 : FROM codemix/yii2-base:2.0.10-php7-apache
2.0.10-php7-apache: Pulling from codemix/yii2-base
5c90d4a2d1a8: Pull complete
357b76a49838: Pull complete
0e87614c69f0: Pull complete
a3a94d3df9be: Pull complete
ac140e12d947: Pull complete
e08ee42cd95f: Pull complete
d4cac1e00ff6: Pull complete
f2749ebafcf6: Pull complete
4cc332f0929e: Pull complete
28ecb8eeb945: Pull complete
275c20a098e4: Pull complete
95b402a00746: Pull complete
3187df5ceb6f: Pull complete
4e7cbd0fc089: Pull complete
721a0611fa8c: Pull complete
c39fb0ca7b5c: Pull complete
d7a01a5bd209: Pull complete
77c46c28ae0a: Pull complete
Digest: sha256:7631a53e2b982c13a33d969ed03d57a278e78ca5f46db253ac4a3e36f813cc8f
Status: Downloaded newer image for codemix/yii2-base:2.0.10-php7-apache
 ---> 1b15b5ede9d6
Step 2 : COPY composer.json /var/www/html/
 ---> 41d3e2a8467d
Removing intermediate container 57c9a3619fa3
Step 3 : COPY composer.lock /var/www/html/
 ---> c7d768cd02e2
Removing intermediate container 905288cadc38
Step 4 : RUN composer self-update --no-progress &&     composer install --no-progress
 ---> Running in 26356f6c3668
Updating to version 1.3.1 (stable channel).
Use composer self-update --rollback to return to version 1.2.1
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
 ---> e6c2f184ca05
Removing intermediate container 26356f6c3668
Step 5 : COPY . /var/www/html
 ---> faf3b488d32d
Removing intermediate container b926f9059be1
Step 6 : RUN mkdir runtime web/assets     && chown www-data:www-data runtime web/assets
 ---> Running in 92ccb2f231fe
 ---> a86dc556d438
Removing intermediate container 92ccb2f231fe
Step 7 : VOLUME /var/www
 ---> Running in 6145314405a7
 ---> bc744cc1866e
Removing intermediate container 6145314405a7
Successfully built bc744cc1866e
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Starting codemixyii2dockerized_db_1

ERROR: for db  Cannot start service db: driver failed programming external connectivity on endpoint codemixyii2dockerized_db_1 (4dcbbccbc9775a225bb865f13515e9f310503ae08a9a2949293f330bb3024049): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use
ERROR: Encountered errors while bringing up the project.

And here's the additional details (if that would help you):

resurtm@resurtm-desktop:~/dev/codemix-yii2-dockerized$ sudo systemctl status mysql.service 
[sudo] password for resurtm: 
● mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql; generated; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-01-16 00:26:43 +06; 1h 16min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9641 ExecStop=/etc/init.d/mysql stop (code=exited, status=1/FAILURE)
    Tasks: 29 (limit: 4915)
   Memory: 118.5M
      CPU: 4.322s
   CGroup: /system.slice/mysql.service
           ├─1115 /bin/bash /usr/bin/mysqld_safe
           ├─1263 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/x86_64-linux-gnu/mariadb18/plugin --user=mysql --sk
           └─1264 logger -t mysqld -p daemon error

Jan 15 23:44:09 resurtm-desktop mysqld[1264]: Version: '10.1.20-MariaDB-3'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  Debian unstable
Jan 15 23:44:09 resurtm-desktop mysql[1066]: Starting MariaDB database server: mysqld.
Jan 15 23:44:09 resurtm-desktop systemd[1]: Started LSB: Start and stop the mysql database server daemon.
Jan 15 23:44:10 resurtm-desktop mysql[1066]: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Jan 16 00:26:43 resurtm-desktop systemd[1]: Stopping LSB: Start and stop the mysql database server daemon...
Jan 16 00:26:43 resurtm-desktop mysql[9641]: Stopping MariaDB database server: mysqld failed!
Jan 16 00:26:43 resurtm-desktop systemd[1]: mysql.service: Control process exited, code=exited status=1
Jan 16 00:26:43 resurtm-desktop systemd[1]: Stopped LSB: Start and stop the mysql database server daemon.
Jan 16 00:26:43 resurtm-desktop systemd[1]: mysql.service: Unit entered failed state.
Jan 16 00:26:43 resurtm-desktop systemd[1]: mysql.service: Failed with result 'exit-code'.

resurtm@resurtm-desktop:~/dev/codemix-yii2-dockerized$ screenfetch
         _,met$$$$$gg.           resurtm@resurtm-desktop
      ,g$$$$$$$$$$$$$$$P.        OS: Debian testing stretch
    ,g$$P""       """Y$$.".      Kernel: x86_64 Linux 4.8.0-2-amd64
   ,$$P'              `$$$.      Uptime: 1h 58m
  ',$$P       ,ggs.     `$$b:    Packages: 1932
  `d$$'     ,$P"'   .    $$$     Shell: bash 4.4.5
   $$P      d$'     ,    $$P     Resolution: 1920x1200
   $$:      $$.   -    ,d$$'     DE: XFCE
   $$\;      Y$b._   _,d$P'      WM: Xfwm4
   Y$$.    `.`"Y$$$$P"'          WM Theme: Default
   `$$b      "-.__               GTK Theme: Adwaita [GTK2]
    `Y$$                         Icon Theme: Tango
     `Y$$.                       Font: Sans 10
       `$$b.                     CPU: Intel Core i5 CPU 760 @ 2.801GHz
         `Y$$b.                  GPU: GeForce GT 640/PCIe/SSE2
            `"Y$b._              RAM: 4618MiB / 16041MiB
                `""""           
                                
resurtm@resurtm-desktop:~/dev/codemix-yii2-dockerized$ uname -a
Linux resurtm-desktop 4.8.0-2-amd64 #1 SMP Debian 4.8.15-2 (2017-01-04) x86_64 GNU/Linux

resurtm@resurtm-desktop:~/dev/codemix-yii2-dockerized$ cat /etc/debian_version 
stretch/sid

resurtm@resurtm-desktop:~/dev/codemix-yii2-dockerized$ dpkg -l | grep docker
ii  docker-engine                         1.12.6-0~debian-stretch                          amd64        Docker: the open-source application container engine

resurtm@resurtm-desktop:~/dev/codemix-yii2-dockerized$ docker-compose --version
docker-compose version 1.9.0, build 2585387

Cheers,
@resurtm

@schmunk42
Copy link

@resurtm From what I've understood you've already a MySQL Server running on your Debian system.

In docker-compose.yml the MySQL server in the Docker container also gets mapped to 3306 on the host, that's the reason why you get an error.

I'd suggest to change that to 13306:3306 and update the application config - please double check that you don't mix up your host MySQL and the one in the Docker container.

As a sidenote: expose is for inter-container communication, ports for host mapping.

@resurtm
Copy link
Author

resurtm commented Jan 16, 2017

Hi @schmunk42!

From what I've understood you've already a MySQL Server running on your Debian system.

Yes, that's true, but as you can see in my OP I've stopped it at systemd level.

I'd suggest to change that to 13306:3306 and update the application config - please double check that you don't mix up your host MySQL and the one in the Docker container.

Thanks! Will try this way.

@resurtm
Copy link
Author

resurtm commented Jan 16, 2017

Also wouldn't it be logical to change default MySQL port exposed from the Docker container to something else (as you suggested me 13306)? I think all the people using this project would definitely have MySQL already installed on their host systems.

@resurtm
Copy link
Author

resurtm commented Jan 16, 2017

Thanks @schmunk42 for pointing it out! ;-) Works for now.

@resurtm resurtm closed this as completed Jan 16, 2017
@schmunk42
Copy link

@resurtm Glad it worked!

There are several ways to do this and it depends on personal preference.

As an example, if you're running a standalone server you do not have already, mapping the same port is usually the first example.
For dockerized web-applications is almost some other port than 80 ;) - on many systems you need to be root to bind to ports lower than 1024 anyway. Maybe there's some kind of system restriction in your case?

For local development we were using "random" port mapping for a long time also in development, therefore we created make targets to overcome the fiddling in ps, which port you need to open. Bonus: additional open-targets in test environment.
For local development we're now using a port mapping like 24080:80 (a fixed port somewhere in the 20000ers different per project) - it's just easier.

But for testing, especially running multiple stacks in parallel you have to remove the fixed ports at all. Otherwise there'd be conflict when running on the same host.

Regards.

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

No branches or pull requests

2 participants