Skip to content

Commit 6b5c495

Browse files
committed
1 parent 37738e4 commit 6b5c495

2 files changed

Lines changed: 60 additions & 3 deletions

File tree

lib/services.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ module.exports = async function (docker, projectName, recipe, output) {
2828
if (service.volumes) {
2929
opts['Volumes'] = {};
3030
for (var volume of service.volumes) {
31-
var v = volume.split(':');
32-
opts['Volumes'][v[1]] = {};
31+
if (typeof volume === 'string' || volume instanceof String) {
32+
var v = volume.split(':');
33+
opts['Volumes'][v[1]] = {};
34+
} else {
35+
if (volume.target) {
36+
opts['Volumes'][volume.target] = {};
37+
}
38+
}
3339
}
3440
}
3541

@@ -54,7 +60,29 @@ var buildHostConfig = function (service) {
5460
};
5561

5662
if (service.volumes) {
57-
output['Binds'] = service.volumes;
63+
output['Binds'] = [];
64+
65+
for (var volume of service.volumes) {
66+
if (typeof volume === 'string' || volume instanceof String) {
67+
output['Binds'].push(volume);
68+
} else {
69+
var volumestr = '';
70+
if (volume.source && volume.target) {
71+
volumestr += volume.source + ':' + volume.target + ':';
72+
}
73+
if (volume.read_only) {
74+
volumestr += 'ro,';
75+
}
76+
if (volume.volume && volume.volume.nocopy) {
77+
volumestr += 'nocopy,';
78+
}
79+
if (volume.bind && volume.bind.propagation) {
80+
volumestr += volume.bind.propagation + ',';
81+
}
82+
volumestr = volumestr.slice(0, -1);
83+
output['Binds'].push(volumestr);
84+
}
85+
}
5886
}
5987

6088
if (service.ports && service.ports.length > 0) {

test/assets/wordpress_long.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: "3.9"
2+
3+
services:
4+
db:
5+
image: mysql:5.7
6+
volumes:
7+
- source: db_data
8+
target: /var/lib/mysql
9+
restart: always
10+
environment:
11+
MYSQL_ROOT_PASSWORD: somewordpress
12+
MYSQL_DATABASE: wordpress
13+
MYSQL_USER: wordpress
14+
MYSQL_PASSWORD: wordpress
15+
16+
wordpress:
17+
depends_on:
18+
- db
19+
image: wordpress:latest
20+
ports:
21+
- "8000:80"
22+
restart: always
23+
environment:
24+
WORDPRESS_DB_HOST: db:3306
25+
WORDPRESS_DB_USER: wordpress
26+
WORDPRESS_DB_PASSWORD: wordpress
27+
WORDPRESS_DB_NAME: wordpress
28+
volumes:
29+
db_data: {}

0 commit comments

Comments
 (0)