简体   繁体   中英

How to “docker-compose up” for images from Docker Hub

Is it possible to pull and start all containers defined in docker-compose.yml? I'm trying to execute docker-compose up -d my/image , where my/image is a repo on DockerHub, but it says "Can't find docker-compose.yml". I also tried first to pull the image using docker pull my/image with the same result

UPD: The image https://hub.docker.com/r/gplcart/core/ , source - https://github.com/gplcart/docker-core

SOLVED: It seems docker-compose does not work that way I want. I need to create a directory manually, place docker-compose.yml there, then run docker-compose up .

https://docs.docker.com/compose/wordpress/#define-the-project

I expected that running docker-compose up -d repo/image is enough to download and run all defined containers

Make sure docker and docker-compose binaries coming from the same package manager. Eg

$ which -a docker docker-compose
/snap/bin/docker
/snap/bin/docker-compose

In other words, if you've installed Docker from a Snap , docker-compose binary should be already included ( ls /snap/docker/current/bin/ ). When using Apt repository, docker-compose can be installed separately, so don't interchange binaries between Snap with Apt , as well don't mix docker with docker.io package on Apt.

Try logging in to Docker Hub so that Docker Compose knows you want to pull images from there.

From the command line ...

docker login

You will be prompted for a username and password. Once authenticated, compose should pull your images from Docker Hub when running docker-compose up .

Also, you need to run docker-compose up from the same directory where your docker-compose.yml file is. Looking at your docker-compose.yml file on Github, it looks like you are missing a few lines. You need to specify the version, and gplcart , db and phpmyadmin should be under services .

version: '3'
services:
  gplcart:
    build: .
    links:
      - db
    ports:
      - 8080:80
  db:
    image: mariadb:10.2
    environment:
      MYSQL_DATABASE: test
      MYSQL_ROOT_PASSWORD: test
    ports:
      - 3306:3306
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:4.7
    links:
      - db
    ports:
      - 8181:80

To pull an image use docker-compose pull <service_name> , where service_name is one of the services listed in your docker-compose.yml file

The docker pull my/image fails, but should fail with a different error than you noted (you posted a compose error)

In your example, my/name is not a valid service name because you can't use a / in the service name. Compose would give you a different error.

It's unclear to me what my/name represents (assuming you replaced it with something locally).

If you post your docker-compose.yml it would help determine what the correct docker and docker-compose commands should be.

The error Can't find docker-compose.yml indicates that you are not currently in the directory with your docker-compose.yml file, or that you have named the file something different. If you have named the file something different, including a different case or extension, you can either rename the file, or run docker-compose -f your_filename.yml up to pass a different file for docker-compose to parse. If you are not in the directory, make sure to cd into that directory before running docker-compose commands.

docker-compose acts based on your local docker-compose.yml file. Pulling a third-party image with docker-compose is usually useful when, instead of executing separate docker commands (in order to pull an image or deploy your app, etc etc), you want to define your architecture in a more structured way like:

My docker-compose.yml file:

version: '3'

services:

    containerA:
        image: gplcart/core

    containerB:
        build: .
        # go on defining the rest ...

and deploying with:

docker-compose build && docker-compose up -d

Here is the simplest working example of docker-compose.yml file:

version: '3'
services:
  hello-world:
    image: hello-world

Which should produce the following results:

$ docker-compose up
Creating network "docker_default" with the default driver
Creating docker_hello-world_1 ... done
Attaching to docker_hello-world_1
hello-world_1  |
hello-world_1  | Hello from Docker!
hello-world_1  | This message shows that your installation appears to be working correctly.
hello-world_1  |
hello-world_1  | To generate this message, Docker took the following steps:
hello-world_1  |  1. The Docker client contacted the Docker daemon.
hello-world_1  |  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
hello-world_1  |     (amd64)
hello-world_1  |  3. The Docker daemon created a new container from that image which runs the
hello-world_1  |     executable that produces the output you are currently reading.
hello-world_1  |  4. The Docker daemon streamed that output to the Docker client, which sent it
hello-world_1  |     to your terminal.
hello-world_1  |
hello-world_1  | To try something more ambitious, you can run an Ubuntu container with:
hello-world_1  |  $ docker run -it ubuntu bash
hello-world_1  |
hello-world_1  | Share images, automate workflows, and more with a free Docker ID:
hello-world_1  |  https://hub.docker.com/
hello-world_1  |
hello-world_1  | For more examples and ideas, visit:
hello-world_1  |  https://docs.docker.com/get-started/
hello-world_1  |
docker_hello-world_1 exited with code 0

In case of problems, use the following commands which can help to track down the problem:

  • docker-compose config - Validate configuration file.
  • docker-compose logs - Check the latest logs.
  • docker info - Check system-wide information.
  • sudo strace -fe network docker-compose up - Debug the network issues.
  • journalctl -u docker.service - Check the logs of Docker service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM