I'm trying to add mysql to a docker compose file, but every time it gives me the error some_name exited with code 0. I tried diffent configurations and even took the following config from the docker docs:
# Use root/example as user/password credentials
version: '3.1'
services:
db:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
In this case adminer works but mysql doesn't.
My config:
mysqldb:
image: mysql
container_name: ${MYSQL_HOST}
env_file:
- ".env"
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
ports:
- "8989:3306"
Both my config and that from the docker docs keep giving me the same error. Although any other services are working fine. Any ideas?
How unfortunate. After hours I deleted my mysql image and after that everything worked fine.
Related
Trying to connect Springboot app dicom_viewer: Imagename: sample with Mysql: Imagename: pb_mysql running in docker container. Error: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure.
Application.properties file:
#MySQL database connection strings
spring.datasource.url=jdbc:mysql://pb_mysql:3306/test?autoReconnect=true&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=pb
spring.datasource.password=pb#123
#JPA property settings
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.show_sql=true
Docker-compose file:
version: '2'
services:
pb_mysql:
container_name: pb_mysql
restart: always
image: mysql/mysql-server:latest
environment:
MYSQL_ROOT_PASSWORD: 'root123' # TODO: Change this
volumes:
- sql-datavolume:/var/lib/mysql
patient_browser:
container_name: patient_browser
restart: always
image: patient_browser
ports:
- 8080:8080
volumes:
- ./dicom_images:/usr/src/app/dicom_images
springboot-image:
container_name: dicom_viewer
restart: always
image: sample
ports:
- 8081:8080
volumes:
sql-datavolume:
networks:
f4:
driver: bridge
Dockerfile:
FROM openjdk:8-jdk-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY ./target/springboot-image-0.0.1-SNAPSHOT.jar /usr/src/app
COPY . /usr/src/app
EXPOSE 8080
ENTRYPOINT ["java","-jar","springboot-image-0.0.1-SNAPSHOT.jar"]
Database: test, table: pm_of_india
Docker images, docker ps -a
docker-compose up
Error: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
There are two things to notice,
depends_on
You kept pb_mysql ahead of others in the yaml configuration file. This does not ensure the mysql-server to be up and running ahead of others.
You want to use depends_on, so the depended pb_mysql will be initiated first.
ports
You are using bridged network, so you need to map 3306 to 3306 for mysql-server.
version: '2'
services:
patient_browser:
container_name: patient_browser
restart: always
image: patient_browser
ports:
- 8080:8080
volumes:
- ./dicom_images:/usr/src/app/dicom_images
- 8081:8080
depends_on:
- pb_mysql
springboot-image:
container_name: dicom_viewer
restart: always
image: sample
ports:
- 8081:8080
depends_on: # Let mysql-server start first
- pb_mysql
pb_mysql:
container_name: pb_mysql
ports:
- "3306:3306" # Port mapping.
restart: always
image: mysql/mysql-server:latest
environment:
MYSQL_ROOT_PASSWORD: 'root123' # TODO: Change this
volumes:
- sql-datavolume:/var/lib/mysql
volumes:
sql-datavolume:
networks:
f4:
driver: bridge
I would avoid using restart: always unless I absolutely need it.
The rest looks good to me. Let me know if it is resolved.
You are not referencing your network.
Try adding it to your services i.e.:
services:
pb_mysql:
networks:
- f4
...
My Docker Wordpress Container some how cannot connect to my database container. I tried to pass the credentials through the environment key.
I'm using external volumes that stores the Data from my previous Wordpress build as well as the data from the Database.
docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
container_name: db
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress_oxygen
volumes:
- wordpress_db-data:/var/lib/mysql
networks:
- conturas-network
wordpress:
depends_on:
- db
image: wordpress:5.6.0-fpm-alpine
container_name: wordpress
restart: unless-stopped
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=wordpress_oxygen
volumes:
- wordpress_data:/var/www/html
networks:
- conturas-network
webserver:
depends_on:
- wordpress
image: nginx:1.19.6-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress_data:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- conturas-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress_data:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email username#xyz.io --agree-tos --no-eff-email --force-renewal -d xyz.io -d www.xyz.io
volumes:
certbot-etc:
wordpress_data:
external: true
wordpress_db-data:
external: true
networks:
conturas-network:
driver: bridge
Error Logs from the db-container
...
2020-12-27T15:53:26.593191Z 2 [Note] Access denied for user 'wordpress_oxygen'#'172.30.0.3' (using password: YES)
Thanks for helping!
The very last line of the logs give the important hint on the underlying issue:
[Note] Access denied for user 'wordpress_oxygen'#'172.30.0.3' (using password: YES)
It means that the database credentials used to connect to the database are incorrect - i.e. the username/password combination.
But since this is logged by the database it means WordPress is actually able to connect to the database - i.e. your docker networks are setup correctly.
You should verify now that the values of configured credentials (WORDPRESS_DB_USER, WORDPRESS_DB_PASSWORD etc.) are actually correct - which is the same as MYSQL_USER and MYSQL_PASSWORD used at the time of initializing the database - that is, the environment variables MYSQL_USER, MYSQL_PASSWORD etc. are only used when the database volume is empty and needs to be initialized, see Environment Variables in the image description:
Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.
You may also try to re-initialize the database by deleting the volume and starting a fresh instance of the service.
Also note that environment and env_file two different ways of specifying environment variables for the service, but mixing those two is bad practice since it can lead to unexpected behavior.
If you want to import values from your .env file to use for variable substitution you don't need to "import" it with env_file since it is loaded automatically for docker-compose! I.e. your current configuration does not do what you probably think it does.
What I did to fix the issue
I removed the the environment keys from the whole compose file.
Why did I do this?
I realized with the help of #acran answers, that the volume that I passed into the docker-compose file, was already a ready to use copy of my Initial Wordpress build/installation the same goes for the MySQL Database. (This means all credentials was already stored inside of each volume) Because of that I was not able to pass environment-variables to the composition, to be more precise, you can pass environment-variables to a build but they would simple have no effect on the finished container build.
You can only set environment-variables at the initial build.
Result
version: '3.3'
services:
db:
image: mysql:5.7
container_name: db
restart: unless-stopped
volumes:
- wordpress_db-data:/var/lib/mysql
networks:
- my-network
wordpress:
depends_on:
- db
image: wordpress:5.6.0-fpm-alpine
container_name: wordpress
restart: unless-stopped
volumes:
- wordpress_data:/var/www/html
networks:
- my-network
webserver:
depends_on:
- wordpress
image: nginx:1.19.6-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- wordpress_data:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- my-network
certbot:
depends_on:
- webserver
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress_data:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html --email my.name#xyz.io --agree-tos --no-eff-email --expand --noninteractive -d xyz.io -d www.xyz.io -d dev.xyz.io
volumes:
certbot-etc:
wordpress_data:
external: true
wordpress_db-data:
external: true
networks:
my-network:
driver: bridge
I'm trying to create a docker-compose.yml file that will bring up JIRA and MySQL. Here's my file:
version: '3'
services:
jira:
depends_on:
- mysql
container_name: jira
restart: always
networks:
- jiranet
build:
context: .
dockerfile: Dockerfile.jira
environment:
- ATL_DB_TYPE=mysql
- ATL_DB_DRIVER=com.mysql.cj.jdbc.Driver
- ATL_JDBC_URL=jdbc:mysql://mysql:3306/jiradb
- ATL_JDBC_USER=jira
- ATL_JDBC_PASSWORD=jellyfish
ports:
- 8080:8080
volumes:
- jira-data:/var/atlassian-data/jira
mysql:
container_name: mysql
restart: always
image: mysql:5.7
networks:
- jiranet
environment:
- MYSQL_ROOT_PASSWORD=ChangeMe!
- MYSQL_DATABASE=jiradb
- MYSQL_USER=jira
- MYSQL_PASSWORD=jellyfish
command: [mysqld, --character-set-server=utf8, --collation-server=utf8_bin, --default-storage-engine=INNODB, --max_allowed_packet=256M, --innodb_log_file_size=2GB, --transaction-isolation=READ-COMMITTED, --binlog_format=row]
volumes:
- mysql-data:/var/lib/mysql
networks:
jiranet: {}
volumes:
jira-data:
mysql-data:
Unfortunately, I'm getting JIRA startup errors when it tried to initialize the database, of the form:
CREATE command denied to user 'jira'#'172.22.0.3' for table 'jiraaction'
I'm guessing it's because the mysql container is creating user jira, but only allowing it to connect from localhost. But, the JIRA container is being seen as coming from an an external IP.
Any ideas on how I can get the jiradb database in mysql to be accessible by the JIRA container by user jira?
I figured out the problem -- I was missing an environment variable in the jira container:
ATL_DB_SCHEMA_NAME=jiradb
After that, things worked fine!
I'm new on Docker and trying now to create my first docker-compose file.
The apache works so far but i'm struggeling a bit with mysql.
Here is my docker-compose.yaml
version: '3'
services:
web:
build: .
ports:
- "8083:80"
volumes:
- ./public_html/:/usr/local/apache2/htdocs/
networks:
- appnet
db:
image: mysql
volumes:
- db-data:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
networks:
- appnet
adminer:
image: adminer
restart: always
ports:
- 8080:8080
volumes:
db-data:
networks:
appnet:
The error is:
[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
I alread tried to remove the volume totally or added a /data at the end. But it gives me all the time the same error. Also Google didn't give me any good hints.
Does someone has an idea?
I figured out now. I'm running Docker on a Windows Machine, so i had to reset the credentials ond Docker App and type in again. Now it works. Hope that will help others as well. It seems on Docker for Windows, when something not work as expected it make sense to reset the credentials.
According to the docker compose yaml,
version: '3'
services:
db:
image: mariadb:latest
container_name: mariadb
restart: always
volumes:
- ./mysql/initdb/:/docker-entrypoint-initdb.d
- ./mysql/data/:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root-pwd
- MYSQL_DATABASE=appdb
- MYSQL_USER=appuser
- MYSQL_PASSWORD=user-pwd
php:
image: php:fpm-alpine
container_name: php
restart: always
volumes:
- ./www/:/var/www/html
expose:
- "9000"
nginx:
image: nginx:alpine
container_name: nginx
restart: always
volumes:
- ./nginx/conf/nginx.conf:/etc/nginx/conf/nginx.conf:ro
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./www:/var/www/html
ports:
- "80:80"
pma:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
restart: always
ports:
- "8080:80"
it produces an error:
#2002 - php_network_getaddresses: getaddrinfo failed: Try again — The server is not responding (or the local server's socket is not correctly configured).
when logging in to phpMyadmin (http://127.0.0.1:8080).
I have tried to fix this problem, but nothing works.
Could you please find a solution?
Any recommendations/comments are welcomed here.
I had a similar problem try this in the links directive - container-name:db as below
links:
- mariadb:db
you should links your phpmyadmin to database services in order to use the db service
pma:
image: phpmyadmin/phpmyadmin
links:
- db
container_name: phpmyadmin
restart: always
ports:
- "8080:80"
environment:
- PMA_HOST: maria_db
here is more about docker compose services links
If you set the following environment variable in docker compose:
pma:
environment:
- PMA_ARBITRARY=1
then you will be given the opportunity to enter the host server manually on the login screen. Enter the name of the database service there. In your case the name of the service is db