Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
e4dc5d31
Commit
e4dc5d31
authored
Sep 05, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/docker: support volumes
parent
2e4882f0
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
18 deletions
+31
-18
CHANGELOG.md
CHANGELOG.md
+1
-0
builder/docker/config.go
builder/docker/config.go
+12
-2
builder/docker/driver.go
builder/docker/driver.go
+0
-1
builder/docker/driver_docker.go
builder/docker/driver_docker.go
+8
-12
builder/docker/step_run.go
builder/docker/step_run.go
+6
-3
website/source/docs/builders/docker.html.markdown
website/source/docs/builders/docker.html.markdown
+4
-0
No files found.
CHANGELOG.md
View file @
e4dc5d31
...
...
@@ -16,6 +16,7 @@ FEATURES:
binaries named
`packer-TYPE-NAME`
.
*
builder/docker: Images can now be committed instead of exported. [GH-1198]
*
builder/docker: Can now specify login credentials to pull images.
*
builder/docker: Support mounting additional volumes. [GH-1430]
*
builder/virtualbox-ovf: New
`import_flags`
setting can be used to add
new command line flags to
`VBoxManage import`
to allow things such
as EULAs to be accepted. [GH-1383]
...
...
builder/docker/config.go
View file @
e4dc5d31
...
...
@@ -14,6 +14,7 @@ type Config struct {
Image
string
Pull
bool
RunCommand
[]
string
`mapstructure:"run_command"`
Volumes
map
[
string
]
string
Login
bool
LoginEmail
string
`mapstructure:"login_email"`
...
...
@@ -41,9 +42,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
// Defaults
if
len
(
c
.
RunCommand
)
==
0
{
c
.
RunCommand
=
[]
string
{
"run"
,
"-d"
,
"-i"
,
"-t"
,
"-v"
,
"{{.Volumes}}"
,
"{{.Image}}"
,
"/bin/bash"
,
}
...
...
@@ -82,6 +81,17 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
}
}
for
k
,
v
:=
range
c
.
Volumes
{
var
err
error
v
,
err
=
c
.
tpl
.
Process
(
v
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing volumes[%s]: %s"
,
k
,
err
))
}
c
.
Volumes
[
k
]
=
v
}
if
c
.
Image
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"image must be specified"
))
...
...
builder/docker/driver.go
View file @
e4dc5d31
...
...
@@ -60,5 +60,4 @@ type ContainerConfig struct {
// This is the template that is used for the RunCommand in the ContainerConfig.
type
startContainerTemplate
struct
{
Image
string
Volumes
string
}
builder/docker/driver_docker.go
View file @
e4dc5d31
...
...
@@ -185,23 +185,19 @@ func (d *DockerDriver) StartContainer(config *ContainerConfig) (string, error) {
// Build up the template data
var
tplData
startContainerTemplate
tplData
.
Image
=
config
.
Image
if
len
(
config
.
Volumes
)
>
0
{
volumes
:=
make
([]
string
,
0
,
len
(
config
.
Volumes
))
for
host
,
guest
:=
range
config
.
Volumes
{
volumes
=
append
(
volumes
,
fmt
.
Sprintf
(
"%s:%s"
,
host
,
guest
))
}
tplData
.
Volumes
=
strings
.
Join
(
volumes
,
","
)
}
// Args that we're going to pass to Docker
args
:=
config
.
RunCommand
for
i
,
v
:=
range
args
{
var
err
error
args
[
i
],
err
=
d
.
Tpl
.
Process
(
v
,
&
tplData
)
args
:=
[]
string
{
"run"
}
for
host
,
guest
:=
range
config
.
Volumes
{
args
=
append
(
args
,
"-v"
,
fmt
.
Sprintf
(
"%s:%s"
,
host
,
guest
))
}
for
_
,
v
:=
range
config
.
RunCommand
{
v
,
err
:=
d
.
Tpl
.
Process
(
v
,
&
tplData
)
if
err
!=
nil
{
return
""
,
err
}
args
=
append
(
args
,
v
)
}
d
.
Ui
.
Message
(
fmt
.
Sprintf
(
"Run command: docker %s"
,
strings
.
Join
(
args
,
" "
)))
...
...
builder/docker/step_run.go
View file @
e4dc5d31
...
...
@@ -19,11 +19,14 @@ func (s *StepRun) Run(state multistep.StateBag) multistep.StepAction {
runConfig
:=
ContainerConfig
{
Image
:
config
.
Image
,
RunCommand
:
config
.
RunCommand
,
Volumes
:
map
[
string
]
string
{
tempDir
:
"/packer-files"
,
},
Volumes
:
make
(
map
[
string
]
string
),
}
for
host
,
container
:=
range
config
.
Volumes
{
runConfig
.
Volumes
[
host
]
=
container
}
runConfig
.
Volumes
[
tempDir
]
=
"/packer-files"
ui
.
Say
(
"Starting docker container..."
)
containerId
,
err
:=
driver
.
StartContainer
(
&
runConfig
)
if
err
!=
nil
{
...
...
website/source/docs/builders/docker.html.markdown
View file @
e4dc5d31
...
...
@@ -95,6 +95,10 @@ described.
`["run", "-d", "-i", "-t", "-v", "{{.Volumes}}", "{{.Image}}", "/bin/bash"]`
.
As you can see, you have a couple template variables to customize, as well.
*
`volumes`
(map of strings to strings) - A mapping of additional volumes
to mount into this container. The key of the object is the host path,
the value is the container path.
## Using the Artifact: Export
Once the tar artifact has been generated, you will likely want to import, tag,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment