Can't create a MYSQL docker container with volume - mysql

I'm trying to create a MYSQL docker container with volume using the following command:
docker run -d -v $(pwd)/api/db/data:/var/lib/mysql --rm --name mysql-container mysql-image
But i recieve the error:
Unable to find image 'de:latest' locally docker: Error response from
daemon: pull access denied for de, repository does not exist or may
require 'docker login': denied: requested access to the resource is
denied. See 'docker run --help'.
I'm alredy logged in my docker account and when i try creating the container without the volume, using this command:
docker run -d --rm --name mysql-container mysql-image
no errors occurs.

Related

docker: Error response from daemon: network mysql_net not found

I'm running this command in Docker docker run --restart always --network mysql_net --ip 192.169.0.2 --name mariadb -e MARIADB_ROOT_PASSWORD=example -v mariadb:/var/lib/mysql -d mariadb
But I'm getting this error : docker: Error response from daemon: network mysql_net not found.
I've been looking for info for a while now but due to I'm starting in Docker and i didn't find any info I can't find a solution.
It is because the network mysql_net does not exists yet. You can create e.g. bridge network as follows:
docker network create -d bridge mysql_net
But I recommend you starting it with docker-compose. See in official docker hub page of e.g. mariadb for docker-compose example.

How can I to connect to a Docker running mysql?

The instructions here: https://hub.docker.com/_/mysql indicate to run
$ docker run -it --network some-network --rm mysql mysql -hsome-mysql-container -uexample-user -p
But i have no idea what some-network is? So i run this instead and get and 'unknown MySQL host' error even though some-mysql-container is definitely the name of my container.
$ docker run -it--rm mysql mysql -hsome-mysql-container -uexample-user -p
What am I doing wrong here?
'some-network' refers to a docker-network. You need to create it first. I named it 'mysql-network' to make its purpose a bit more clear:
docker network create mysql-network
Then, start database container:
docker run --network mysql-network --name mysql-db -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
Then, start a the client container to connect to the first one:
docker run -it --network mysql-network --rm mysql mysql -hmysql-db -uroot -p
By adding both containers to the same network, they are able to communicate with each other.

using docker images for mySQL and redmine, how do I resolve "Unknown MySQL server host"?

I am using the docker images supplied at https://hub.docker.com/_/redmine
I have chosen to use MySQL as my database backend. So I have 2 docker containers: MySQL and Redmine, as downloaded from dockerhub.
Following the instructions on the docker/redmine link above, I ran through the commands and found that the redmine docker would not start. Inspecting the docker logs, I see:
rake aborted!
Mysql2::Error::ConnectionError: Unknown MySQL server host redmine (-5)
I thought the 2 dockers were having difficulty talking to each other, so I setup a new docker network for both containers to use:
docker network create --driver bridge redmine-net
Adapting the instructions, on the docker/redmine link above, I run
docker run -d name our-mysql --network redmine-net -e MYSQL_USER=redmine -e MYSQL_PASSWORD=todays-password -e MYSQL_DATABASE=redmine -e MYSQL_RANDOM_ROOT_PASSWORD=1 -p 3306:3306 mysql:5.7
docker run -d name our-redmine --network redmine-net -e REDMINE_DB_MYSQL=redmine -e REDMINE_DB_USERNAME=redmine -e REDMINE_DB_PASSWORD=todays-password redmine:latest
However, the redmine contain still falls over instantly, with the same error.
EDIT Using the *.yml file as provided in the dockerhub redmine instructions works pretty faultlessly.
So the question is: what is the docker-compose method doing that docker run isn't handling?
Thank you.
The REDMINE_DB_MYSQL arg of the redmine container do reference to the mysql container, so, if you define the database service like our-mysql, then set REDMINE_DB_MYSQL=our-mysql

Docker: Error while creating a container with volume

I'm trying to create a simple mysql container, but I'm getting an error.
I created a Dockerfile:
FROM mysql
ENV MYSQL_ROOT_PASSWORD <password>
I built the image:
docker build -t mysql-image -f api/db/Dockerfile .
But when I tried to create a container with a host volume, an error appears:
docker run -d -v $(pwd)/api/db/data:/var/lib/mysql --rm --name mysql-container mysql-image
docker: Error response from daemon: pull access denied for de, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
If I run the same command, but without the volume parameters, then the container is created without any errors:
docker run -d --rm --name mysql-container mysql-image
I appreciate any help
Do you have whitespace in your current path? If so, it may be confusing the $(pwd) as two or more separate parameters. Try wrapping the whole parameter to -v in double quotes.
docker run -d -v "$(pwd)/api/db/data:/var/lib/mysql" --rm --name mysql-container mysql-image

Not able to connect to Localhost Mysql from docker container

I have installed docker on Windows machine using docker tool box.
I also have mysql installed on my windows machine and the server is running on port 3306 (localhost - 127.0.0.1 - outside the docker machine)
I am running a sprint boot application inside a docker container with name as 'micra-workq-svc' inside the docker network called 'micra-network'
I want application running inside the docker to connect to this local host.
I spent hours searching on google and none of the links help me to resolve this issue.
I tried running mysql image with this command:
docker run --name micra-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=<pass> -e MYSQL_DATABASE=<db name> -e MYSQL_USER=<roo user> -e MYSQL_PASSWORD=<root password >--net=micra-network mysql:latest
I am using following command to run my container:
docker run -e "SPRING_PROFILES_ACTIVE=dev" --network micra-network --env "eureka.client.enabled=true" --env "eureka.host=micra-eureka-server" --env "eureka.instance.preferIpAddress: true" --env "eureka.client.serviceUrl.defaultZone=http://micra-eureka-server:8761/eureka" --env DATABASE_HOST=127.0.0.1 --env DATABASE_PORT=3306 --env DATABASE_NAME=<db name> --env DATABASE_USER=<db user> --env DATABASE_PASSWORD=<db password> --expose 8083 -p 8083:8083 --name micra-workq-svc --link micra-mysql -t <my docker service image>
This is how application.properties look like in spring boot:
spring:
datasource:
password: ${DATABASE_PASSWORD}
url: jdbc:mysql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
username: ${DATABASE_USER}
When I run my service I get following error:
Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
My docker machine ip is 192.168.99.100.
Just clean your containers and images as administrator execute this command docker prune - a , put DATABASE_HOST=micra-mysql and run again.