简体   繁体   English

如何使用docker image运行docker-compose?

[英]How to run docker-compose with docker image?

I've moved my docker-compose container from the development machine to a server using docker save image-name > image-name.tar and cat image-name.tar | docker load 我已经使用docker save image-name > image-name.tarcat image-name.tar | docker load -compose容器从开发机移到了服务器上cat image-name.tar | docker load cat image-name.tar | docker load . cat image-name.tar | docker load I can see that my image is loaded by running docker images . 我可以看到通过运行docker images加载了我的映像。 But when I want to start my server with docker-compose up , it says that there isn't any docker-compose.yml. 但是,当我想使用docker-compose up启动服务器docker-compose up ,它说没有任何docker-compose.yml。 And there isn't really any .yml file. 而且实际上没有任何.yml文件。 So how to do with this? 那么该怎么办呢?

UPDATE When I've copied all my project files to the server (including docker-compose.yml), everything started to work. 更新将所有项目文件复制到服务器(包括docker-compose.yml)后,所有内容开始工作。 But is it normal approach and why I needed to save-load image first? 但这是正常方法吗,为什么我需要先保存图像?

What you achieve with docker save image-name > image-name.tar and cat image-name.tar | docker load 使用docker save image-name > image-name.tar可以达到的目的是docker save image-name > image-name.tarcat image-name.tar | docker load cat image-name.tar | docker load is that you put a Docker image into an archive and extract the image on another machine after that. cat image-name.tar | docker load就是您将Docker 映像放入存档中,然后将映像提取到另一台计算机上。 You could check whether this worked correctly with docker run --rm image-name . 您可以检查是否与docker run --rm image-name一起正常工作。

An image is just like a blueprint you can use for running containers. 图像就像可以用于运行容器的蓝图。 This has nothing to do with your docker-compose.yml , which is just a configuration file that has to live somewhere on your machine. 这与docker-compose.yml ,后者只是一个配置文件,必须docker-compose.yml在计算机上的某个位置。 You would have to copy this file manually to the remote machine you wish to run your image on, eg using scp docker-compose.yml remote_machine:/home/your_user/docker-compose.yml . 您必须手动将此文件复制到要在其上运行映像的远程计算机,例如,使用scp docker-compose.yml remote_machine:/home/your_user/docker-compose.yml You could then run docker-compose up from /home/your_user . 然后,您可以从/home/your_user运行docker-compose up

EDIT: Additional info concerning the updated question: 编辑:有关更新的问题的其他信息:

UPDATE When I've copied all my project files to the server (including docker-compose.yml), everything started to work. 更新将所有项目文件复制到服务器(包括docker-compose.yml)后,所有内容开始工作。 But is it normal approach and why I needed to save-load image first? 但这是正常方法吗,为什么我需要先保存图像?

Personally, I have never used this approach of transferring a Docker image (but it's cool, didn't know it). 就我个人而言,我从未使用过这种传输Docker映像的方法(但是它很酷,不知道)。 What you typically would do is pushing your image to a Docker registry (either the official DockerHub one, or a self-hosted registry) and then pulling it from there. 通常,您要做的是将映像推送到Docker注册表(正式的DockerHub注册表或自托管注册表),然后从那里将其拉出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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