Docker-在Docker中的容器之间共享卷

时间:2019-01-21 08:06:12

标签: docker docker-compose

我有一个使用docker-compose创建的,具有pythonphp / apache的码头工人。我的.yaml文件如下所示:

services:

  web:
    build: ./php
    container_name: php_web
    volumes:
      - ./php/:/var/www/html/
    ports:
      - "8100:80"
    stdin_open: true
    tty: true

  python:
    build: ./python
    volumes:
      - ./product:/user/src/app
    ports:
      - "5000:5000"

我希望能够通过python访问Web容器文件系统,反之亦然,以便它们可以共享文件。

是否有使用docker compose做到这一点的简单方法?我不需要保留这些文件,可以在启动/退出时将其删除。

1 个答案:

答案 0 :(得分:3)

在docker中创建卷:

library(tidyverse)
library(lubridate)
library(nycflights13) # Dataset with flight details

# Custom function to transform the date and time information from several columns
# into one "date-time" column. You may be able to get away simply with make_datetime

make_datetime_100 <- function(year, month, day, time) {
  make_datetime(year, month, day, time %/% 100, time %% 100)
}

# Apply that function to relevant columns in the dataset
flights_dt <- flights %>% 
  filter(!is.na(dep_time), !is.na(arr_time)) %>% 
  mutate(
    dep_time = make_datetime_100(year, month, day, dep_time),
    arr_time = make_datetime_100(year, month, day, arr_time),
    sched_dep_time = make_datetime_100(year, month, day, sched_dep_time),
    sched_arr_time = make_datetime_100(year, month, day, sched_arr_time)
  ) %>% 
  select(origin, dest, ends_with("delay"), ends_with("time"))


# Plot the dataset
flights_dt %>% 
  ggplot(aes(dep_time)) + 
  geom_freqpoly(binwidth = 86400) # 86400 seconds = 1 day

然后,在docker-compose文件的顶层声明,如下所示:

docker volume create php-volume
相关问题