Home > database >  Why is docker compose trying to pull an image instead of creating a new one?
Why is docker compose trying to pull an image instead of creating a new one?

Time:10-14

I reinstalled docker on my Ubuntu server and now I am trying to rebuild and run a docker container using docker-compose but it seems like there is an error in pulling. How can I work around this, and why does this happen?

docker-compose:

version: "3.7"

networks:
  default:
    external: true
    name: network

services:
  mysql:
    ports:
      - "13306:3306"
    container_name: mysql
    #environment:
    #  - MYSQL_ROOT_PASSWORD=dbPass
    image: mysql

Dockerfile:

FROM mysql:8

ENV MYSQL_DATABASE db
ENV MYSQL_ROOT_PASSWORD=dbPass

COPY ./scripts/ /docker-entrypoint-initdb.d/

Input command: docker-compose up --build

Error message:

Pulling mydb (mysql:)...
ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.

Continue with the new image? [yN]n
ERROR: pull access denied for mysql:, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

CodePudding user response:

It seems that when you removed the image you created with the volume, you forgot to also remove the volume. I think there is 2 solutions for this:

  1. Delete your volume using docker volume rm specific-volume-name (see here)
  2. Recreate the build using new volume by adding -V option (see here)

CodePudding user response:

I had forgotten to add the build property in the compose file. Which causes docker to try to fetch the image based on what is defined.

version: "3.7"

networks:
  default:
    external: true
    name: network

services:
  mysql:
    ports:
      - "13306:3306"
    container_name: mysql
    image: mysql
    build: .

  • Related