2 mysql images downloaded when run docker-compose

Hi! I’m new in Docker, I want to set my environment to learn on my own.
I have a problem when I run my Dockerfile and docker-compose.yml to build MySQL

My problem:2 mysql images downloaded when i run command docker-compose up --build
There are 2 images MySQL in tag “8.0” and “none” after docker-compose completed

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               8.0                 f3f9ffb4e94e        14 seconds ago      547MB
mysql               <none>              9228ee8bac7a        9 days ago          547MB
centos              latest              470671670cac        2 months ago        237MB
nginxdemos/hello    latest              aedf47d433f1        2 years ago         16.8MB

I guess there is some problem in my Dockerfile or docker-compose.yml, but I have no idea why.
I attached my Dockerfile and docker-compose.yml

1.docker-compose.yml

version: '3.3'
services:
  # DB config
  db:
    image: mysql:8.0
    build: ./mysql   
    container_name: mysql
    volumes:
      - ./mysql/db:/docker-entrypoint-initdb.d  
    environment:
      - MYSQL_DATABASE=webapp
      - MYSQL_ROOT_USER=root
      - MYSQL_ROOT_PASSWORD=password
      - TZ=Japan
    ports:
      - "3306:3306"

2.Dockerfile

FROM mysql:8.0 

COPY ./my.cnf /etc/mysql/conf.d/my.cnf

RUN mkdir -p /var/log/mysql
RUN chown mysql.mysql /var/log/mysql

Thank you all so much about reading my question.
Im so sorry about my English.

The docker reference 2 provides one piece of the puzzle:

If you specify image as well as build , then Compose names the built image with the webapp and optional tag specified in image :

build: ./dir
image: webapp:tag

This results in an image named webapp and tagged tag , built from ./dir .

The other piece is that once a new image uses the same tag, the previous image looses the tag. Since your image bases on the other image, it is still required.

If you do not plan to use Docker Swarm deployments, the docker-compose.yml 2 reference is still valid. The additions in 3.x address Swarm related enhancements and changes.

1 Like