so I'm new to docker and now I'm trying to connect my php, and adminer service to mysql service. Here is my docker-compose file.
version: '3.1'
services:
php:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./html:/var/www/html
ports:
- 80:80
db:
image: mysql:5.7
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
ports:
- 3360:3306
adminer:
image: adminer
restart: always
ports:
- 8080:8080
After I ran the docker-compose up -d command, I opened adminer (localhost:8080) and fill the server field with 'db', username with 'test', password with 'test', database with 'test'. Then I clicked login but I got Connection timed out message, I can't login to the mysql service. The mysql service logs showed that the 'mysqld: ready for connections' already. Any ideas where I did it wrong? thank you :)
Related
I've created docker-compose.yml file with the following content. My docker service runs ok, docker run hello-world works just fine and after running command
docker-compose build && docker-compose up -d
I see no errors but in the browser I'm getting an error Unable to connect when I go to localhost:8000
version: '3'
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "8000:80"
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
mysql:
image: mysql:8.0
container_name: mysql
restart: unless-stopped
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root
SERVICE_NAME: mysql
When I run command
docker-compose exec php ls
I can see the list of files and folders
I setup my docker mysql and phpadmin via
version: '3.2'
services:
mysqllocal:
image: mysql:8.0
container_name: container_mysqllocal
restart: always
ports:
- '6603:3306'
environment:
MYSQL_ROOT_PASSWORD: pass1234
MYSQL_ROOT_HOST: '%'
phpmyadmin:
depends_on:
- mysqllocal
image: phpmyadmin/phpmyadmin
container_name: container_phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: mysqllocal
UPLOAD_LIMIT: 3000000000
docker inspect container_mysqllocal and got '172.30.0.2'. However when I tried to connect mysql via SequelPro. It gives Connection Failed error. How do I connect mysql to my SequelPro / mysql workbench app, is there any configuration I've missed?
Below is the screenshot of my SequelPro connection:
have you tried to access mysql from your local machine with the port defined, in your config is 6603
So I am creating an application that is running in a docker container on port 3000 of my local machine. I can open the app at localhost:3000, I can also open it on another device but on the same network by using 192.168.68.100:3000. However, I can't access the app by visiting my_public_ip:3000. I added port forwarding on my router for port 3000. I am running the app using docker-compose up and this is my docker-compose file:
version: '3.7'
services:
main:
container_name: main
build:
context: .
target: development
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- 3000:3000
command: npm run start:dev
env_file:
- .env
networks:
- webnet
depends_on:
- db
db:
container_name: db
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: "..."
MYSQL_USER: "..."
MYSQL_PASSWORD: "..."
MYSQL_ROOT_PASSWORD: "..."
adminer:
container_name: adminer
image: adminer
restart: always
ports:
- 8080:8080
networks:
webnet:
Any suggestions what am I missing?
I executed docker-compose up and my services worked as well but unfortunately when i hit the url " http://localhost:3000 " it gives me an error I'll paste the docker-compose.yml here.
version: "3.7"
services:
db:
image: postgres
container_name: psql
environment:
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres:/var/lib/postgresql/data
- ./postgresql/conf:/etc/postgresql/
restart: always
ports:
- '5432:5432'
api:
build: .
container_name: api
restart: always
command: yarn start
depends_on:
- db
ports:
- "3000:3000"
volumes:
- .:/usr/app
volumes:
postgres:
When I get into the container and execute curl localhost:3000 it works fine.
My problem was solved after I changed the host in my node api to '0.0.0.0' it was 'localhost' so I think the application was running only inside the container and after that change it was visible from all the created network.
I have a generic DB which is running inside another network. I would like to be able to connect to the DB from my API. To do so I have tried to use external_links. However, when I connect to the DB from my API: mysql -h db_1 -u user -p I get this error: ERROR 2005 (HY000): Unknown MySQL server host 'db_1' (0)
Here, is the docker-compose.yml for my app:
version: "3"
services:
api:
image: s2s/api:latest
command: start
ports:
- 8081:8081
external_links:
- db_1
Other, docker-compose.yml file containing my db:
version: "3"
services:
db:
image: mysql:5.7
environment:
MYSQL_DATABASE: name
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
ports:
- 3306:3306
You should not split container's definitions while using Docker Compose. Please use the following one:
version: "3"
services:
api:
image: s2s/api:latest
command: start
ports:
- 8081:8081
db:
image: mysql:5.7
environment:
MYSQL_DATABASE: name
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
ports:
- 3306:3306
In case you specifically need to split them for some reason, please use networks, as external_links are not recommended.