Docker: Error while creating a container with volume - mysql

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

Related

Can't create a MYSQL docker container with volume

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.

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 container run" requires at least 1 argument

I'm trying to create a container using a volume that I have already created, but my console shows the error
docker container run" requires at least 1 argument
This is the command I'm trying to run:
docker container run --name db -v volume-dados-do-banco:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Mypass
I have also tried this one, wih more arguments, but the same error persists:
docker container run -d --name db -p 3306:3306 -e 'ACCEPT_EULA=Y' -e MYSQL_ROOT_PASSWORD=Mypass -v volume-dados-do-banco:/var/lib/mysql
Any thoughts on the reason why this is happening?
Problem is not with docker, you just didn't specify which image to run. Your command should include Docker image as per documentation.
docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...]
Example would be:
docker run -d --name db -v volume-dados-do-banco:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Mypass mysql:latest
i just had the same problem with psql my password simply contained & and i needed to escape it with / before &
try the below command.. it seems a syntax error on your command..
docker container run -d --name db -v volume-dados-do-banco:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Mypass
i have the same problem when i use this:
docker run -d -p 3306:3306 -v /Volumes/wd4black/mysql -e MYSQL_ROOT_PASSWORD=root mysql
but when i try below, the problem is disappear:
docker run --name my-s -d -p 3306:3306 -v /Volumes/wd4black/mysql -e MYSQL_ROOT_PASSWORD=root mysql
so i think the --name is key, but the doc didn/t write it.
I just restarted docker and ran:
docker run --name torgmysqldb --volumes-from volume-dados-banco-mysql -e MYSQL_ROOT_PASSWORD=Mypass -p 3307:3306 mysql
I found out a known issue about this:
https://github.com/docker/for-win/issues/2722
After you have extracted the image from the Docker repository, you can move on to deploying the new Container with the following code snippet:
sudo docker run --name=[container_name] -d [image_tag_name]

Using mysql image from docker

I am trying to use the available mysql tags from this doc.
I am using the following command to download the image
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
But when I run this image with
sudo docker run mysql:tag
it gives the following error
error: database is uninitialized and MYSQL_ROOT_PASSWORD not set
Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?
Any idea on where else to set this password?