简体   繁体   English

docker-compose建立和建立

[英]docker-compose build and up

I am not an advance user so please bear with me. 我不是高级用户,请耐心等待。

I am building a docker image using docker-compose -f mydocker-compose-file.yml ... on my machine. 我正在使用docker-compose -f mydocker-compose-file.yml ...在我的机器上docker-compose -f mydocker-compose-file.yml ...

The image then been pushed to a remote docker registry. 然后将映像推送到远程Docker注册表。

Then from a remote server I pull down this image. 然后从远程服务器上拉下此图像。

To run this image; 运行该映像; I have to copy mydocker-compose-file.yml from my machine to remote server and then run docker-compose -f mydocker-compose-file.yml up -d . 我必须将mydocker-compose-file.yml从我的机器复制到远程服务器,然后运行docker-compose -f mydocker-compose-file.yml up -d

I find this very inefficient as why I need the same YAML file to run the docker image (should I?). 我发现这效率很低,因为为什么我需要相同的YAML文件来运行docker映像(我应该吗?)。

Is there a way to just spin up the container without this file from remote machine? 有没有一种方法可以在没有远程计算机上的文件的情况下直接启动容器?

Everything you can do with Docker Compose, you can do with plain docker commands. 您可以使用Docker Compose进行的所有操作,也可以使用普通docker命令进行的操作。

Depending on how exactly you're interacting with the remote server, your tooling might have native ways to do this. 根据您与远程服务器交互的精确程度,您的工具可能具有执行此操作的本机方法。 One specific example I'm familiar with is the Ansible docker_container module . 我熟悉的一个特定示例是Ansible docker_container模块 If you're already using a tool like Ansible, Chef, or Salt, you can probably use a tool like this to do the same thing your docker-compose.yml file does. 如果您已经在使用Ansible,Chef或Salt之类的工具,则可以使用类似这样的工具来完成docker-compose.yml文件的相同工作。

But otherwise there's more or less a direct translation between a docker-compose.yml file 但是否则,在docker-compose.yml文件之间或多或少会有直接翻译

version: '3'
services:
  foo:
    image: me/foo:20190510.01
    ports: ['8080:8080']

and a command line 和命令行

docker run -d --name foo -p 8080:8080 me/foo:20190510.01

My experience has been that the docker run commands quickly become unwieldy and you want to record them in a file; 我的经验是, docker run命令很快变得笨拙,您想将它们记录在文件中。 and once they're in a file, you start to wish they were in a more structured format, even if you need an auxiliary tool to run them; 一旦将它们保存在文件中,您就开始希望它们采用结构化的格式,即使您需要使用辅助工具来运行它们也是如此; which brings you back to copying around the docker-compose.yml file. 这使您回到围绕docker-compose.yml文件进行复制。 I think that's pretty routine. 我认为这很常规。 ( Something needs to tell the server what to run.) 有什么需要告诉要运行什么服务器。)

As of compose 1.24 along with the 18.09 release of docker (you'll need at least that client version on the remote host), you can run docker commands to a remote host over SSH. compose 1.24到docker的18.09版本(您至少需要远程主机上的该客户端版本)起,您可以通过SSH对远程主机运行docker命令。

# all docker commands in this shell will not talk to the remote host
export DOCKER_HOST=ssh://user@host
# you can verify that with docker info to see which engine you're talking to
docker info
# and now run your docker-compose up command locally to start/stop containers
docker-compose up -d

With previous versions, you could configure TLS certificates to allow specific clients to connect to the docker API over a network connection. 在以前的版本中,您可以配置TLS证书,以允许特定客户端通过网络连接连接到Docker API。 See these docs for more details . 有关更多详细信息,请参见这些文档

Note, if you have host volumes, the variables and paths will be expanded to your laptop directories, but the host mounts will happen on the remote server where those directories may not exist. 请注意,如果您有主机卷,则变量和路径将扩展到您的笔记本电脑目录,但是主机安装将在那些目录可能不存在的远程服务器上进行。 This is a good situation to switch to named volumes. 这是切换到命名卷的好情况。

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

相关问题 docker-compose up --build 与 docker-compose build && docker-compose up 有区别吗 - Is there a difference in docker-compose up --build vs. docker-compose build && docker-compose up docker-compose up && docker-compose build:PostgreSQL错误 - docker-compose up && docker-compose build : error with PostgreSQL docker-compose up没有建立 - docker-compose up doesn't build docker-compose up vs docker-compose up --build vs docker-compose build --no-cache - docker-compose up vs docker-compose up --build vs docker-compose build --no-cache docker-compose -up -d和docker-compose up -build有什么区别? - What's the difference between docker-compose -up -d and docker-compose up -build? Dockerfile没有在docker-compose up -d上按预期方式建立 - Dockerfile does not build up as expected on `docker-compose up -d` 在docker-compose构建之后,docker-compose up运行旧的未更新的容器 - After docker-compose build the docker-compose up run old not updated containers 在docker-compose build或docker-compose上创建文件/文件夹 - Create files / folders on docker-compose build or docker-compose up Docker-compose up 退出,代码为 1,但 docker-compose 构建成功 - Docker-compose up exited with code 1 but successful docker-compose build 为什么 docker-compose 会在 `docker-compose up` 上构建一个新镜像? - Why does docker-compose build a new image on `docker-compose up`?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM