Docker Compose does not allow to use local images

后端 未结 9 1907
-上瘾入骨i
-上瘾入骨i 2020-12-24 00:33

The following command fails, trying to pull image from the Docker Hub:

$ docker-compose up -d
Pulling web-server (web-server:staging)...
ERROR: repository we         


        
9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 00:56

    March-09-2020 EDIT:

    (docker version 18.09.9-ce build 039a7df, dockercompose version 1.24.0, build 0aa59064)

    I found that to just create a docker container, you can just docker-compose 'up -d' after tagging the container with a fake local registry server tag (localhost:5000/{image}).

    $ docker tag {imagename}:{imagetag} localhost:5000/{imagename}:{imagetag}
    

    You don't need to run the local registry server, but need to change the image url in dockercompose yaml file with the fake local registry server url:

    version: '3'
    services:
    web-server:
      image: localhost:5000/{your-image-name} #change from {imagename}:{imagetag} to localhost:5000/{imagename}:{imagetag}
      ports:
        - "80:80"
    

    from {imagename}:{imagetag} to localhost:5000/{imagename}:{imagetag}

    and just up -d

    $ docker-compose -f {yamlfile}.yaml up -d 
    

    This creates the container if you already have the image (localhost:5000/{imagename}) in your local machine.


    Adding to @Tom Saleeba's response,

    I still got errors after tagging the container with "/" (for ex: victor-dombrovsky/docker-image:latest) It kept looking for the image from remote docker.io server.

    registry_address/docker-image
    

    It seems the url before "/" is the registry address and after "/" is the image name. and without "/" provided, docker-compose by default looks for the image from the remote docker.io.

    It guess it's a known bug with docker-compose

    I finally got it working by running the local registry, pushing the image to the local registry with the registry tag, and pulling the image from the local registry.

    $ docker run -d -p 5000:5000 --restart=always --name registry registry:2
    $ docker tag your-image-name:latest localhost:5000/your-image-name
    $ docker push localhost:5000/your-image-name
    

    and then change the image url in the dockerfile:

    version: '3'
    services:
      chat-server:
        image: chat-server:staging
        ports:
          - "8110:8110"
      web-server:
        image: localhost:5000/{your-image-name} #####change here
        ports:
          - "80:80"
          - "443:443"
          - "8009:8009"
          - "8443:8443"
    

    Similarly for the chat-server image.

提交回复
热议问题