Search code examples
mysqldockercontainers

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


Solution

  • 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