Docker:写入链接容器的磁盘 [英] Docker: Write to disk of linked container

查看:106
本文介绍了Docker:写入链接容器的磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行简单Web应用程序的Docker容器。 Docker Compose使用以下docker-compose.yml文件将该容器链接到其他两个容器:

I have a Docker container that runs a simple web application. That container is linked to two other containers by Docker Compose with the following docker-compose.yml file:

version: '2'

services:
  mongo_service:
    image: mongo
    command: mongod
    ports:
      - '27017:27017'

  tomcat_service:
    image: 'bitnami/tomcat:latest'
    ports:
      - '8080:8080'

  web:
    # gain access to linked containers
    links:
      - mongo_service
      - tomcat_service
    # explicitly declare service dependencies
    depends_on:
      - mongo_service
      - tomcat_service
    # set environment variables
    environment:
      PYTHONUNBUFFERED: 'true'
    # use the image from the Dockerfile in the cwd
    build: .
    ports:
      - '8000:8000'

web 容器启动,我想在 tomcat_service上的 / bitnami / tomcat / data / 中写一些内容容器。我尝试只从 web 容器中写入该磁盘位置,但遇到一个例外:

Once the web container starts, I want to write some content to /bitnami/tomcat/data/ on the tomcat_service container. I tried just writing to that disk location from within the web container but am getting an exception:


没有这样的文件或目录:'/ bitnami / tomcat / data /'

No such file or directory: '/bitnami/tomcat/data/'

有人知道我能做什么能够从 web 容器写入 tomcat_service 容器?我将非常感谢其他人在这个问题上可以提供的任何建议!

Does anyone know what I can do to be able to write to the tomcat_service container from the web container? I'd be very grateful for any advice others can offer on this question!

推荐答案

如果需要,您必须使用docker卷一种服务写入其他服务。如果Web写入someFolderName,则tomcat_service中将存在相同的文件。

you have to use docker volumes if you want one service to write to other service. If web writes to someFolderName the same file will exist in the tomcat_service.

version: '2'

services:

  tomcat_service:
    image: 'bitnami/tomcat:latest'
    volumes:
      - my_shared_data:/bitnami/tomcat/data/

  web:
    volumes:
      - my_shared_data:/someFolderName

volumes:
  my_shared_data:

体积中的数据仍然存在,甚至在下次重新创建Docker容器时这些数据仍然可用。在docker容器中写入某些数据时,应始终使用docker卷。

Data in volumes persist and they will be available even next time you re-create docker containers. You should always use docker volumes when writing some data in docker containers.

这篇关于Docker:写入链接容器的磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆