[英]How to run a Docker Compose image pulled from GitHub Packages
I have pushed a Docker image on GitHub Packages and now I would like to pull it and use it.我已经在 GitHub Packages 上推送了一个 Docker 镜像,现在我想拉它并使用它。 To run the image locally, I used to go to the related folder and run it with the command docker-compose up
.为了在本地运行映像,我曾经转到相关文件夹并使用命令docker-compose up
运行它。 However now, by pulling from GitHub Packages, I just get the Docker image without any folder and I don't know how I can run it.但是现在,通过从 GitHub 包中提取,我只获得了没有任何文件夹的 Docker 映像,我不知道如何运行它。
By inspecting the image it has all the files related to the original folder but, when I try to run the docker-compose up ghcr.io/giuliomat/bdt-project
command, I get an error saying that there is no docker-compose.yml in the directory.通过检查图像,它包含与原始文件夹相关的所有文件,但是,当我尝试运行docker-compose up ghcr.io/giuliomat/bdt-project
命令时,我收到一条错误消息,指出没有 docker-compose。 yml 在目录中。 If I just use the command docker run ghcr.io/giuliomat/bdt-project
it runs one of the two services specified in the docker-compose.yml file.如果我只使用命令docker run ghcr.io/giuliomat/bdt-project
它docker run ghcr.io/giuliomat/bdt-project
-compose.yml 文件中指定的两个服务之一。 How can I run the Docker Compose image correctly?如何正确运行 Docker Compose 镜像? Thanks in advance!提前致谢!
Update: I try to explain myself better.更新:我试着更好地解释自己。 In the image there is a Dockerfile (that now I've uploaded in the question) which is used to build the web service.在图像中有一个用于构建 Web 服务的 Dockerfile(现在我已在问题中上传)。 I developed the image locally and I have no problem running it with docker-compose up
, but now I wanted to see what it has to be done in order to run it when a user pulls it from my GitHub Packages, and this is my problem.我在本地开发了映像,并且使用docker-compose up
运行它没有问题,但是现在我想看看当用户从我的 GitHub 包中提取它时必须执行哪些操作才能运行它,这是我的问题. The pulled image should have all the elements needed to run but I don't know what command to use in order to tell Docker to run both services specified in the docker-compose.yml file, since when a user pulls from GitHub Packages it only gets the image and no folder where run docker-compose up
.拉取的映像应该包含运行所需的所有元素,但我不知道使用什么命令来告诉 Docker 运行 docker-compose.yml 文件中指定的两个服务,因为当用户从 GitHub 包中提取时,它只获取图像并且没有运行docker-compose up
文件夹。
Dockerfile: Dockerfile:
docker-compose.yml: docker-compose.yml:
content of the pulled docker image:拉取的 docker 镜像的内容:
Update:更新:
Docker image repository does not store yml files, therefore either you provide a README.md
for the user in the image registry (with yml verbosely copy-pasted there) and/or you provide also the link to the version control repository where the rest of the files reside, so the user can clone and use docker-compose up
.泊坞窗图像库不存储阳明文件,所以要么你提供一个README.md
在图像注册表中的用户(与YML冗长复制粘贴有)和/或还提供链接到版本控制储存库,其余文件驻留,因此用户可以克隆和使用docker-compose up
。
docker-compose up [options] [--scale SERVICE=NUM...] [SERVICE...]
means "find [service...] (if specified, otherwise run all) in
docker-compose.yml` in the current working directory and run it. docker-compose up [options] [--scale SERVICE=NUM...] [SERVICE...]
意思是“ (if specified, otherwise run all) in
docker-compose.yml` 中找到 [service...] (if specified, otherwise run all) in
当前工作目录并运行它。
So if you move out of the folder with docker-compose.yml
it won't pick the compose file and therefore won't work.因此,如果您使用docker-compose.yml
文件夹,它将不会选择撰写文件,因此将无法工作。
Also for the image using you need to specify image
property of a service instead of build
because build
works with the Dockerfile
locally and attempts to build an image instead of pulling it from GitHub Docker image registry:同样对于使用的图像,您需要指定服务的image
属性而不是build
因为build
在本地使用Dockerfile
并尝试构建图像而不是从 GitHub Docker 镜像注册表中提取它:
web:
image: "ghcr.io/giuliomat/bdt-project:latest"
It'd be the same way you have it for redis
service.这与您为redis
服务提供的方式相同。
Also make sure you can pull the image locally first (otherwise docker login
would be necessary prior to compose commands) by:还要确保您可以首先在本地拉取图像(否则在撰写命令之前需要docker login
):
docker pull ghcr.io/giuliomat/bdt-project
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.