I am trying to make a quick connection setup using the fallowing setup
Copy & Paste to recreate the issue
docker rm -f mariadb && docker run --detach --name mariadb --env MARIADB_USER=user --env MARIADB_PASSWORD=secret --env MARIADB_ROOT_PASSWORD=secret -p 3306:3306 mariadb:latest
docker rm -f phpmyadd && docker run --name phpmyadd -d -e PMA_HOST=host -e PMA_PORT=3306 -p 8080:80 phpmyadmin
docker exec -it mariadb bash
I can login in to mariadb container and access mariadb with
mysql -uroot -psecret
I can also access phpmyadmin container at http://localhost:8080
However when i try to login to mariadb through phpmyadmin i get the fallowing:
It shows that the port is exposed but I can not access it with telnet..
Any idea what is missing here?
For 2 containers to be able to talk to each other, you would have to setup a docker-compose instead. Something like this should work
version: '3.8'
volumes:
mariadb:
driver: local
services:
mariadb:
image: mariadb:10.6
restart: always
environment:
MYSQL_ROOT_PASSWORD: YOUR_ROOT_PASSWORD_HERE
MYSQL_USER: YOUR_MYSQL_USER_HERE
MYSQL_PASSWORD: YOUR_USER_PW_HERE
ports:
- "40000:3306"
volumes:
- mariadb:/var/lib/mysql
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- "40001:80"
environment:
- PMA_HOST=mariadb
- PMA_PORT=3306
And you would start everything using docker-compose up
Related
due to hardware problem, I had to replace my small home server with a new one.
Several self-hosted services with Docker were running on the server for which I tried to backup the volumes following the instructions on the official Docker website and those present in this YouTube video and in this cheat-sheet. Now, following the same documentation, I am trying to restore the backups but without success. The first one I'm trying for is a stack for Nginx Proxy Manager built with Docker compose with this docker-compose.yaml file:
version: "3.6"
services:
app:
image: jc21/nginx-proxy-manager:latest
restart: always
ports:
- "80:80"
- "443:443"
- "81:81"
environment:
DB_MYSQL_HOST: "db"
DB_MYSQL_PORT: 3306
DB_MYSQL_NAME: "db_name"
DB_MYSQL_USER: "db_user"
DB_MYSQL_PASSWORD: "db_password"
volumes:
- data:/data
- ./letsencrypt:/etc/letsencrypt
depends_on:
- db
db:
image: jc21/mariadb-aria:latest
restart: always
environment:
MYSQL_DATABASE: "db_name"
MYSQL_ROOT_PASSWORD: "root_password"
MYSQL_USER: "db_user"
MYSQL_PASSWORD: "db_password"
volumes:
- db:/var/lib/mysql
volumes:
db:
data:
After starting the stack with docker compose up -d command I'm trying to restore db and data volumes with:
docker run --rm --volumes-from nginx-proxy-manager-db-1 -v $(pwd):/backup ubuntu bash -c "cd / && tar xvf /backup/nginx-proxy-manager_db_20220717-082200.tar --strip 1"
docker run --rm --volumes-from nginx-proxy-manager-app-1 -v $(pwd):/backup ubuntu bash -c "cd / && tar xvf /backup/nginx-proxy-manager_data_20220717-082200.tar --strip 1"
What's wrong?
I'm reading the docker-ce dock for installation. It's simple two lines :
docker volume create portainer_data &&
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
Is there a way to do all this stuff with docker-compose file ? So the portainer container will be groupped with all the others when executing docker-comppose down ?
This french tutorial got something working :
portainer:
container_name: portainer
image: portainer/portainer-ce:latest #latest might not be the best option
restart: unless-stopped
command: -H unix:///var/run/docker.sock
ports:
- 9000:9000
volumes:
- /var/run/docker.sock:/var/run/docker.sock:fr
- /etc/localtime:/etc/localtime:fr
- /etc/timezone:/etc/timezone:fr #not sure about those 3 volumes
- dataportainer:/data
volumes:
dataportainer:
This question already has answers here:
[Docker]: Connecting PHPMyAdmin to MySQL doesnt work
(6 answers)
Closed 3 years ago.
I want to spawn MySQL & PHPMyAdmin docker containers. Mysql container can be accessed via 3306 port & PHPMyAdmin can be accessed through 8280 port.
My question is, how a PHP application can be configured to access the MySQL docker container on 3306 port
and the PHPMyAdmin can be configured for MySQL.
Thanks.
Start MySQL server
docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -d mysql
Start phpAdmin with link to mysql container
docker run --name myadmin -d --link mysql:db -p 8080:80 phpmyadmin/phpmyadmin
PHPAdmin application will be serving on localhost:80. MySQL credentials will be root/password.
We can now use docker-compose for this solution which is more portable.
You can use the offical image for MySQL and PHPMyAdmin.
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: example
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8081:80
To access it from php container, just add your php container in the docker-compose, so the connection string should be like
host:db
user: root
pass: example
You can use Adminer a database management tool.
You need the below configuration in docker-compose.yml for Mysql and adminer.
mysqldb:
container_name: mysqldb
image: mysql
restart: always
environment:
- MYSQL_USER= 'xyz'
- MYSQL_PASSWORD='pwd0123456789'
- MYSQL_DB= 'testdb'
networks:
- main
adminer:
container_name: adminer
image: adminer
restart: always
ports:
- 4041:8080
networks:
- main-network
depends_on:
- mysqldb
Here is the compose file that I am using. It consist one postgres db container and one redis container. On top of them I have a gunicorn-django-python web server(docker image:python-3.5). There is one nginx proxy server which is linked to web container.
version: '2'
services:
nginx:
build: ./nginx/
ports:
- 80:80
volumes:
- /usr/src/app/static
links:
- web
web:
build: ./web
ports:
- 8000:8000
volumes:
- /usr/src/app/static
env_file: .env
environment:
DEBUG: 'true'
SECRET_KEY: 5(15ds+i2+%ik6z&!yer+ga9m=e%jcqiz_5wszg)r-z!2--b2d
DB_NAME: postgres
DB_USER: postgres
DB_PASS: postgres
DB_SERVICE: postgres
DB_PORT: 5432
command: /usr/local/bin/gunicorn messanger.wsgi:application -w 2 -b :8000
links:
- redis
- postgres
postgres:
image: postgres
ports:
- 5432
volumes:
- pgdata:/var/lib/postgresql/data/
redis:
image: redis
ports:
- 6379
volumes:
- redisdata:/data
I am facing issue while starting docker containers via
convox start -f docker-compose.yml
Problem is , ideally first postgres/redis servers to be started, then the web server and then nginx server in the end according to their linking order. But actually web server is getting started first due to which it fails without db/cache. See error logs below:
web │ running: docker run -i --rm --name python-app-web -e DB_NAME=postgres -e DB_USER=postgres -e DB_PASS=postgres -e DB_SERVICE=postgres -e DB_PORT=5432 -e DEBUG=true -e SECRET_KEY=5(15ds+i2+%ik6z&!yer+ga9m=e%jcqiz_5wszg)r-z!2--b2d --add-host redis: -e REDIS_SCHEME=tcp -e REDIS_HOST= -e REDIS_PORT=
-e REDIS_PATH= -e REDIS_USERNAME= -e REDIS_PASSWORD= -e REDIS_URL=tcp://:%0A --add-host postgres: -e POSTGRES_SCHEME=tcp -e POSTGRES_HOST= -e POSTGRES_PORT=
-e POSTGRES_PATH= -e POSTGRES_USERNAME= -e POSTGRES_PASSWORD= -e POSTGRES_URL=tcp://:%0A -p 0:8000 -v /Users/gaurav/.convox/volumes/python-app/web/usr/src/app/static:/usr/src/app/static python-app/web sh -c /usr/local/bin/gunicorn messanger.wsgi:application -w 2 -b :8000
web │ invalid argument "redis:" for --add-host: invalid IP address in add-host: ""
web │ See 'docker run --help'.
postgres │ running: docker run -i --rm --name python-app-postgres -p 5432 -v pgdata:/var/lib/postgresql/data/ python-app/postgres
redis │ running: docker run -i --rm --name python-app-redis -p 6379 -v redisdata:/data python-app/redis
But it works fine when I completely removes the nginx server, in that case web server is being kicked off after postgres/redis.
I am not able to understand the actual error.
Complete code can be found here at github.
[Note] Found very strange thing I never expected this. Problem was with the name of the container. If I rename the 'ngnix' container to anything like server/webserver/xyz/myngnix/ngnixxxx etc it all worked as expected and in order. But not working with the name ngnix! strange isn't it.
Just add depends_on directive to docker-compose.yml
version: '2'
services:
depends_on:
- web
nginx:
build: ./nginx/
ports:
- 80:80
volumes:
- /usr/src/app/static
web:
build: ./web
depends_on:
- postrges
- redis
ports:
- 8000:8000
volumes:
- /usr/src/app/static
env_file: .env
environment:
DEBUG: 'true'
SECRET_KEY: 5(15ds+i2+%ik6z&!yer+ga9m=e%jcqiz_5wszg)r-z!2--b2d
DB_NAME: postgres
DB_USER: postgres
DB_PASS: postgres
DB_SERVICE: postgres
DB_PORT: 5432
command: /usr/local/bin/gunicorn messanger.wsgi:application -w 2 -b :8000
postgres:
image: postgres
ports:
- 5432
volumes:
- pgdata:/var/lib/postgresql/data/
redis:
image: redis
ports:
- 6379
volumes:
- redisdata:/data
Order of running containers will be ok. But it doesnt mean that when web app will try to connect to redis, this container will be available. If you want reach this fetures you need something like whait for it or docker-compose health check
I have a simple docker-compose.yml (wp image is based on ibmjstart/wp-bluemix-container, db image is mariadb)
db:
image: registry.eu-gb.bluemix.net/foo/db
environment:
MYSQL_ROOT_PASSWORD: examplepass
ports:
- 3306:3306
volumes:
- /var/lib/mysql
wp:
image: registry.eu-gb.bluemix.net/foo/wp
links:
- db:mysql
ports:
- 80:80
after executing docker compose up -d I get
error: missing WORDPRESS_DB_HOST and MYSQL_PORT_3306_TCP environment variables
Did you forget to --link some_mysql_container:mysql or set an external db
with -e WORDPRESS_DB_HOST=hostname:port?
As you can see, the db container is linked.
When I do the same without docker-compose, using
$ cf ic run -v mysql-vol:/var/lib/mysql --name wpdb -d registry.eu-gb.bluemix.net/foo/db
$ cf ic run -e MYSQL_ROOT_PASSWORD=my-secret-pw -v web-files:/var/www/html/ --link wpdb:mysql -d registry.eu-gb.bluemix.net/foo/wp
Everything works well.
I do export docker variables after cf ic login
More info:
root#vps:~/test/compose# docker-compose --version
docker-compose version 1.7.0, build 0d7bf73
root#vps:~/test/compose# docker --version
Docker version 1.10.3, build 20f81dd
root#vps:~/test/compose# cf --version
cf version 6.15.0+fa1bfe2-2016-01-13
root#vps:~/test/compose# cf ic --version
Docker version 1.10.3, build 20f81dd
UPDATE: As I understand, this problem is caused by the naming:
This docker-compose.yml throws an error
db:
image: registry.eu-gb.bluemix.net/foo/db
environment:
MYSQL_ROOT_PASSWORD: examplepass
container_name:
wpdb
ports:
- 3306:3306
volumes:
- /var/lib/mysql
wp:
image: registry.eu-gb.bluemix.net/foo/wp
links:
- wpdb:mysql
ports:
- 80:80
ERROR: Service "wp" has a link to service "wpdb" which does not exist.
However, if you name the service and container the same, the syntax is ok.
db:
image: registry.eu-gb.bluemix.net/foo/db
environment:
MYSQL_ROOT_PASSWORD: examplepass
container_name:
db
ports:
- 3306:3306
volumes:
- /var/lib/mysql
wp:
image: registry.eu-gb.bluemix.net/foo/wp
links:
- db:mysql
ports:
- 80:80
Although the syntax is OK and the container is linked, the wordpress container logs this
Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 10
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Is this a bug in Bluemix? Looks like a /etc/hosts/ related problem
Sorry for a long post :)
#bartimar Yes, the problem is related to the /etc/hosts file. It needs to have an entry for the db container, but it is not creating it.
I can recreate your problem in the prod-lon02-vizio1 environment, but it works fine in the prod-lon02-kraken1 environment.
My recommendation if for you to manually migrate to the prod-lon02-kraken1 environment to use docker-compose.yml with IBM containers. All environments will be automatically migrated on May 25th anyway.
To migrate simply run the following command:
$ cf ic reprovision
Please note that your images are migrated to new environment, but all your running containers are deleted and you will have to recreate them in the new environment. So use this option with caution.
For more details check the link below:
https://developer.ibm.com/bluemix/2016/03/24/new-deployment-architecture-for-containers/?linkId=22660520